| | |
| | | import org.springframework.stereotype.Component;
|
| | | import org.yeshi.utils.StringUtil;
|
| | |
|
| | | import com.yeshi.fanli.dto.pdd.PDDPromotionUrl;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
|
| | | import com.yeshi.fanli.entity.taobao.TaoKeAppInfo;
|
| | | import com.yeshi.fanli.exception.goods.ConvertLinkExceptionException;
|
| | | import com.yeshi.fanli.service.inter.taobao.TaoBaoBuyRelationMapService;
|
| | | import com.yeshi.fanli.service.inter.user.tb.UserExtraTaoBaoInfoService;
|
| | | import com.yeshi.fanli.service.manger.goods.tb.TaoBaoTokenAuctionIdMapManager;
|
| | | import com.yeshi.fanli.util.RedisKeyEnum;
|
| | | import com.yeshi.fanli.util.RedisManager;
|
| | | import com.yeshi.fanli.util.TaoBaoConstant;
|
| | | import com.yeshi.fanli.util.jd.JDApiUtil;
|
| | | import com.yeshi.fanli.util.jd.JDUtil;
|
| | | import com.yeshi.fanli.util.pinduoduo.PinDuoDuoApiUtil;
|
| | | import com.yeshi.fanli.util.pinduoduo.PinDuoDuoUtil;
|
| | | import com.yeshi.fanli.util.taobao.TaoBaoUtil;
|
| | | import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
|
| | |
|
| | |
| | | @Resource
|
| | | private TaoBaoBuyRelationMapService taoBaoBuyRelationMapService;
|
| | |
|
| | | @Resource
|
| | | private RedisManager redisManager;
|
| | |
|
| | | @Resource
|
| | | private TaoBaoTokenAuctionIdMapManager taoBaoTokenAuctionIdMapManager;
|
| | |
|
| | | /**
|
| | | *
|
| | | * @Title: convertJDLinkFromText
|
| | | * @Description:转链文本中的京东短链 |
| | | * @param text
|
| | | * @param uid
|
| | | * @param share
|
| | | * @return
|
| | | * @throws Exception |
| | | * String 返回类型
|
| | | * @throws
|
| | | * @Title: convertJDLinkFromText @Description:转链文本中的京东短链 @param text @param
|
| | | * uid @param share @return @throws Exception String 返回类型 @throws
|
| | | */
|
| | |
|
| | | private String convertJDLinkFromText(String text, Long uid, boolean share) throws Exception {
|
| | | public String convertJDLinkFromText(String text, Long uid, boolean share) throws Exception {
|
| | |
|
| | | StringBuilder builder = new StringBuilder(text);
|
| | | String newText = builder.toString();
|
| | |
| | | return newText;
|
| | | }
|
| | |
|
| | | public String convertPDDLinkFromText(String text, Long uid, boolean share) throws Exception {
|
| | |
|
| | | StringBuilder builder = new StringBuilder(text);
|
| | | String newText = builder.toString();
|
| | | // 京东转链
|
| | | // 提取京东所有的链接
|
| | | List<String> pddShortLink = PinDuoDuoUtil.getPDDShortLinksFromText(text);
|
| | | Set<String> linkSet = new HashSet<>();
|
| | | Map<String, String> linkMap = new HashMap<>();
|
| | | if (pddShortLink != null && pddShortLink.size() > 0) {
|
| | | linkSet.addAll(pddShortLink);
|
| | | for (String shortLink : linkSet) {
|
| | | String goodsId = PinDuoDuoUtil.getPDDGoodsId(shortLink);
|
| | | if (!StringUtil.isNullOrEmpty(goodsId)) {
|
| | | PDDPromotionUrl pddUrl = PinDuoDuoApiUtil.convert(Long.parseLong(goodsId),
|
| | | share ? PinDuoDuoApiUtil.PID_SHARE : PinDuoDuoApiUtil.PID_FANLI, uid + "");
|
| | | if (pddUrl != null) {
|
| | | linkMap.put(shortLink, pddUrl.getShortUrl());
|
| | | }
|
| | | }
|
| | |
|
| | | }
|
| | | }
|
| | |
|
| | | for (String link : linkSet) {
|
| | | if (linkMap.get(link) == null)
|
| | | throw new Exception("拼多多转链失败");
|
| | | newText = newText.replace(link, linkMap.get(link));
|
| | | }
|
| | |
|
| | | return newText;
|
| | | }
|
| | |
|
| | | /**
|
| | | *
|
| | | * @Title: convertTBLinkFromText
|
| | | * @Description: 转链文本中的淘口令
|
| | | * @param text
|
| | | * @param uid
|
| | | * @param share
|
| | | * @return
|
| | | * @throws Exception |
| | | * String 返回类型
|
| | | * @throws
|
| | | * @Title: convertTBLinkFromText @Description: 转链文本中的淘口令 @param text @param
|
| | | * uid @param share @return @throws Exception String 返回类型 @throws
|
| | | */
|
| | | private String convertTBLinkFromText(String text, Long uid, boolean share) throws Exception {
|
| | |
|
| | | StringBuilder builder = new StringBuilder(text);
|
| | | String newText = builder.toString();
|
| | | List<String> tokenList = TaoBaoUtil.getTokenListFromText(newText);
|
| | | List<String> tokenList = TaoBaoUtil.getTokenListFromTextWithKuoHao(newText);
|
| | | if (tokenList != null && tokenList.size() > 0) {
|
| | |
|
| | | String relationId = null;
|
| | |
| | | tokenSet.addAll(tokenList);
|
| | | Map<String, String> tokenMap = new HashMap<>();
|
| | | for (String token : tokenSet) {
|
| | | Long auctionId = TaoKeApiUtil.tokenConvertAuctionId(token);
|
| | | Long auctionId = taoBaoTokenAuctionIdMapManager.getAuctionIdByToken(token);
|
| | | if (auctionId == null)
|
| | | throw new Exception("从淘口令获取商品失败");
|
| | | TaoBaoGoodsBrief simpleGoods = TaoKeApiUtil.getSimpleGoodsInfo(auctionId);
|
| | |
| | | if (StringUtil.isNullOrEmpty(newToken)) {
|
| | | throw new Exception("口令转链失败");
|
| | | }
|
| | | tokenMap.put(token, newToken);
|
| | | tokenMap.put(token, TaoBaoUtil.filterTaoToken(newToken));
|
| | | }
|
| | |
|
| | | for (String token : tokenSet) {
|
| | |
| | |
|
| | | /**
|
| | | *
|
| | | * @Title: convertLinkFromText
|
| | | * @Description: 从文本转链
|
| | | * @param text
|
| | | * @return |
| | | * String 返回类型
|
| | | * @throws
|
| | | * @Title: convertLinkFromText @Description: 从文本转链 @param text @return
|
| | | * String 返回类型 @throws
|
| | | */
|
| | | public String convertLinkFromText(String text, Long uid, boolean share) throws Exception {
|
| | | public String convertLinkFromText(String text, Long uid, boolean share)
|
| | | throws ConvertLinkExceptionException, Exception {
|
| | | String newText = convertJDLinkFromText(text, uid, share);
|
| | | newText = convertPDDLinkFromText(text, uid, share);
|
| | | newText = convertTBLinkFromText(newText, uid, share);
|
| | | if (text.equalsIgnoreCase(newText))
|
| | | throw new ConvertLinkExceptionException(ConvertLinkExceptionException.CODE_NONE, "不包含可转链的口令与链接");
|
| | | return newText;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 创建口令 @Title: createTaoBaoToken @Description: @param uid 用户ID @param
|
| | | * picturl @param title @param link @return String 返回类型 @throws
|
| | | */
|
| | | public String createTaoBaoToken(Long uid, String picturl, String title, String link) {
|
| | |
|
| | | String token = TaoKeApiUtil.getTKToken(picturl, title, link);
|
| | | if (!StringUtil.isNullOrEmpty(token)) {
|
| | | // 缓存30分钟
|
| | | redisManager.cacheCommonString(
|
| | | RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoUserTKToken, uid + "-" + StringUtil.Md5(token)), "1",
|
| | | 60 * 30);
|
| | | }
|
| | | return token;
|
| | | }
|
| | |
|
| | | }
|