| | |
| | | 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.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;
|
| | |
| | | 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 = convertLinkFromText(text, uid, share);
|
| | | newText = convertPDDLinkFromText(newText, uid, share);
|
| | | newText = convertTBLinkFromText(newText, uid, share);
|
| | | if (text.equalsIgnoreCase(newText))
|
| | | throw new ConvertLinkExceptionException(ConvertLinkExceptionException.CODE_NONE, "不包含可转链的口令与链接");
|