| | |
| | | package com.yeshi.fanli.service.manger.goods;
|
| | |
|
| | | import java.util.ArrayList;
|
| | | import java.util.HashMap;
|
| | | import java.util.HashSet;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | | import java.util.Set;
|
| | | import java.util.regex.Matcher;
|
| | | import java.util.regex.Pattern;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import org.springframework.stereotype.Component;
|
| | | import org.yeshi.utils.StringUtil;
|
| | |
|
| | | import com.yeshi.fanli.dto.pdd.PDDPromotionUrl;
|
| | | import com.yeshi.fanli.dto.taobao.api.TaoKeOfficialActivityConvertResultDTO;
|
| | | 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.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;
|
| | |
|
| | |
| | | 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;
|
| | | }
|
| | |
|
| | | // 获取淘宝官方活动ID内容
|
| | | public List<String> getTaoBaoOfficialActivityId(String text) {
|
| | |
|
| | | // {淘宝活动:13123123}
|
| | | String regex = "(\\{\u6dd8\u5b9d\u6d3b\u52a8\\:){1}+[0-9]{5,20}\\}{1}";
|
| | | Pattern pattern = Pattern.compile(regex);
|
| | | Matcher m = pattern.matcher(text);
|
| | | List<String> urlList = new ArrayList<>();
|
| | | while (m.find()) {
|
| | | urlList.add(m.group());
|
| | | }
|
| | |
|
| | | return urlList;
|
| | |
|
| | | }
|
| | |
|
| | | /**
|
| | | *
|
| | | * @Title: convertTBLinkFromText @Description: 转链文本中的淘口令 @param text @param
|
| | |
| | |
|
| | | StringBuilder builder = new StringBuilder(text);
|
| | | String newText = builder.toString();
|
| | |
|
| | | // 解析淘口令
|
| | | List<String> tokenList = TaoBaoUtil.getTokenListFromTextWithKuoHao(newText);
|
| | | if (tokenList != null && tokenList.size() > 0) {
|
| | |
|
| | |
| | | newText = newText.replace(token, tokenMap.get(token));
|
| | | }
|
| | | }
|
| | |
|
| | | // 解析淘宝官方活动ID
|
| | | List<String> list = getTaoBaoOfficialActivityId(newText);
|
| | | if (list.size() > 0) {
|
| | | String relationId = null;
|
| | | if (share) {
|
| | | relationId = userExtraTaoBaoInfoService.getRelationIdByUid(uid);
|
| | | if (StringUtil.isNullOrEmpty(relationId))
|
| | | throw new Exception("淘宝未授权");
|
| | | }
|
| | | for (String st : list) {
|
| | | String activityid = st.replace("{淘宝活动:", "").replace("}", "");
|
| | | if (!StringUtil.isNullOrEmpty(activityid)) {
|
| | | String adzoneId = TaoBaoConstant.TAOBAO_RELATION_PID_DEFAULT.split("_")[3];
|
| | | TaoKeOfficialActivityConvertResultDTO dto = TaoKeApiUtil.officialActivityConvert(adzoneId,
|
| | | activityid, relationId);
|
| | | String link = dto.getShort_click_url();
|
| | | if (StringUtil.isNullOrEmpty(link)) {
|
| | | link = dto.getClick_url();
|
| | | }
|
| | |
|
| | | String token = TaoKeApiUtil.getTKToken("http://", "淘宝官方活动", link);
|
| | | newText = newText.replace(st, TaoBaoUtil.filterTaoToken(token));
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | return newText;
|
| | | }
|
| | |
|
| | |
| | | public String convertLinkFromText(String text, Long uid, boolean share)
|
| | | throws ConvertLinkExceptionException, Exception {
|
| | | String newText = convertJDLinkFromText(text, uid, share);
|
| | | newText = convertPDDLinkFromText(newText, uid, share);
|
| | | newText = convertTBLinkFromText(newText, uid, share);
|
| | | if (text.equalsIgnoreCase(newText))
|
| | | throw new ConvertLinkExceptionException(ConvertLinkExceptionException.CODE_NONE, "不包含可转链的口令与链接");
|