| | |
| | | package com.yeshi.fanli.service.manger.goods;
|
| | |
|
| | | import java.util.HashMap;
|
| | | import java.util.HashSet;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | | import java.util.Set;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import org.springframework.stereotype.Component;
|
| | | import org.yeshi.utils.StringUtil;
|
| | |
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
|
| | | import com.yeshi.fanli.entity.taobao.TaoKeAppInfo;
|
| | | import com.yeshi.fanli.service.inter.taobao.TaoBaoBuyRelationMapService;
|
| | | import com.yeshi.fanli.service.inter.user.tb.UserExtraTaoBaoInfoService;
|
| | | 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.taobao.TaoBaoUtil;
|
| | | import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
|
| | |
|
| | | /**
|
| | | * 转链组件
|
| | | * |
| | | * @author Administrator
|
| | | *
|
| | | */
|
| | | @Component
|
| | | public class ConvertLinkManager {
|
| | |
|
| | | @Resource
|
| | | private UserExtraTaoBaoInfoService userExtraTaoBaoInfoService;
|
| | |
|
| | | @Resource
|
| | | private TaoBaoBuyRelationMapService taoBaoBuyRelationMapService;
|
| | |
|
| | | @Resource
|
| | | private RedisManager redisManager;
|
| | |
|
| | | /**
|
| | | * |
| | | * @Title: convertJDLinkFromText @Description:转链文本中的京东短链 @param text @param
|
| | | * uid @param share @return @throws Exception String 返回类型 @throws
|
| | | */
|
| | |
|
| | | public String convertJDLinkFromText(String text, Long uid, boolean share) throws Exception {
|
| | |
|
| | | StringBuilder builder = new StringBuilder(text);
|
| | | String newText = builder.toString();
|
| | | // 京东转链
|
| | | // 提取京东所有的链接
|
| | | List<String> jdShortLink = JDUtil.getJDShortLinksFromText(text);
|
| | | Set<String> linkSet = new HashSet<>();
|
| | | Map<String, String> linkMap = new HashMap<>();
|
| | | if (jdShortLink != null && jdShortLink.size() > 0) {
|
| | | linkSet.addAll(jdShortLink);
|
| | | for (String shortLink : linkSet) {
|
| | | String link = null;
|
| | | if (share)
|
| | | link = JDApiUtil.convertLinkWithSubUnionId(shortLink, null, JDApiUtil.POSITION_SHARE + "",
|
| | | uid + "");
|
| | | else
|
| | | link = JDApiUtil.convertLinkWithSubUnionId(shortLink, null, JDApiUtil.POSITION_FANLI + "",
|
| | | uid + "");
|
| | | if (!StringUtil.isNullOrEmpty(link)) {
|
| | | linkMap.put(shortLink, link);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | 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
|
| | | */
|
| | | private String convertTBLinkFromText(String text, Long uid, boolean share) throws Exception {
|
| | |
|
| | | StringBuilder builder = new StringBuilder(text);
|
| | | String newText = builder.toString();
|
| | | List<String> tokenList = TaoBaoUtil.getTokenListFromTextWithKuoHao(newText);
|
| | | if (tokenList != null && tokenList.size() > 0) {
|
| | |
|
| | | String relationId = null;
|
| | | if (share) {
|
| | | relationId = userExtraTaoBaoInfoService.getRelationIdByUid(uid);
|
| | | if (StringUtil.isNullOrEmpty(relationId))
|
| | | throw new Exception("淘宝未授权");
|
| | | }
|
| | | Set<String> tokenSet = new HashSet<>();
|
| | | tokenSet.addAll(tokenList);
|
| | | Map<String, String> tokenMap = new HashMap<>();
|
| | | for (String token : tokenSet) {
|
| | | Long auctionId = TaoKeApiUtil.tokenConvertAuctionId(token);
|
| | | if (auctionId == null)
|
| | | throw new Exception("从淘口令获取商品失败");
|
| | | TaoBaoGoodsBrief simpleGoods = TaoKeApiUtil.getSimpleGoodsInfo(auctionId);
|
| | | if (simpleGoods == null)
|
| | | throw new Exception("商品信息获取失败");
|
| | | String link = null;
|
| | | if (share) {
|
| | | TaoBaoGoodsBrief goods = TaoKeApiUtil.specialConvertCoupon(auctionId,
|
| | | new TaoKeAppInfo(TaoBaoConstant.TAOBAO_AUTH_APPKEY, TaoBaoConstant.TAOBAO_AUTH_APPSECRET,
|
| | | TaoBaoConstant.TAOBAO_RELATION_PID_DEFAULT));
|
| | | if (goods == null)
|
| | | throw new Exception("商品转链失败");
|
| | |
|
| | | link = goods.getCouponLink();
|
| | | if (StringUtil.isNullOrEmpty(link)) {
|
| | | link = goods.getAuctionUrl();
|
| | | }
|
| | | if (StringUtil.isNullOrEmpty(link))
|
| | | throw new Exception("商品转链失败");
|
| | | link += "&relationId=" + relationId;
|
| | | } else {
|
| | | if (simpleGoods.getMaterialLibType() != null && simpleGoods.getMaterialLibType() == 1) {
|
| | | TaoBaoGoodsBrief goods = TaoKeApiUtil.specialConvertCoupon(auctionId,
|
| | | new TaoKeAppInfo(TaoBaoConstant.TAOBAO_AUTH_APPKEY,
|
| | | TaoBaoConstant.TAOBAO_AUTH_APPSECRET,
|
| | | TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT));
|
| | | if (goods == null)
|
| | | throw new Exception("商品转链失败");
|
| | |
|
| | | link = goods.getCouponLink();
|
| | | if (StringUtil.isNullOrEmpty(link)) {
|
| | | link = goods.getAuctionUrl();
|
| | | }
|
| | | } else {
|
| | | String sRelationId = taoBaoBuyRelationMapService.getRelationId(uid);
|
| | |
|
| | | TaoBaoGoodsBrief goods = TaoKeApiUtil.specialConvertCoupon(auctionId,
|
| | | new TaoKeAppInfo(TaoBaoConstant.TAOBAO_AUTH_APPKEY,
|
| | | TaoBaoConstant.TAOBAO_AUTH_APPSECRET,
|
| | | TaoBaoConstant.TAOBAO_RELATION_AS_SPECIAL_PID));
|
| | | if (goods == null)
|
| | | throw new Exception("商品转链失败");
|
| | |
|
| | | link = goods.getCouponLink();
|
| | | if (StringUtil.isNullOrEmpty(link)) {
|
| | | link = goods.getAuctionUrl();
|
| | | }
|
| | | if (StringUtil.isNullOrEmpty(link))
|
| | | throw new Exception("商品转链失败");
|
| | | link += "&relationId=" + sRelationId;
|
| | | }
|
| | | }
|
| | |
|
| | | if (StringUtil.isNullOrEmpty(link)) {
|
| | | throw new Exception("商品转链失败");
|
| | | }
|
| | |
|
| | | String newToken = TaoKeApiUtil.getTKToken(simpleGoods.getPictUrl(), simpleGoods.getTitle(), link);
|
| | | if (StringUtil.isNullOrEmpty(newToken)) {
|
| | | throw new Exception("口令转链失败");
|
| | | }
|
| | | tokenMap.put(token, TaoBaoUtil.filterTaoToken(newToken));
|
| | | }
|
| | |
|
| | | for (String token : tokenSet) {
|
| | | if (tokenMap.get(token) == null)
|
| | | throw new Exception("淘宝部分转链失败");
|
| | | newText = newText.replace(token, tokenMap.get(token));
|
| | | }
|
| | | }
|
| | | return newText;
|
| | | }
|
| | |
|
| | | /**
|
| | | * |
| | | * @Title: convertLinkFromText @Description: 从文本转链 @param text @return
|
| | | * String 返回类型 @throws
|
| | | */
|
| | | public String convertLinkFromText(String text, Long uid, boolean share) throws Exception {
|
| | | String newText = convertJDLinkFromText(text, uid, share);
|
| | | newText = convertTBLinkFromText(newText, uid, share);
|
| | | 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;
|
| | | }
|
| | |
|
| | | }
|
| | | package com.yeshi.fanli.service.manger.goods; |
| | | |
| | | import java.util.*; |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import com.yeshi.fanli.dto.pdd.PDDGoodsDetail; |
| | | import com.yeshi.fanli.entity.SystemEnum; |
| | | import com.yeshi.fanli.entity.SystemFunction; |
| | | import com.yeshi.fanli.entity.SystemPIDInfo; |
| | | import com.yeshi.fanli.service.inter.pdd.PDDAuthService; |
| | | import com.yeshi.fanli.service.inter.user.UserFunctionsLimitService; |
| | | import com.yeshi.fanli.service.manger.PIDManager; |
| | | import com.yeshi.fanli.util.Constant; |
| | | import com.yeshi.fanli.vo.pdd.PDDConvertLinkResultVO; |
| | | import org.springframework.stereotype.Component; |
| | | import org.yeshi.utils.StringUtil; |
| | | |
| | | import com.yeshi.fanli.dto.taobao.api.TaoKeOfficialActivityConvertResultDTO; |
| | | import com.yeshi.goods.facade.entity.taobao.TaoBaoGoodsBrief; |
| | | import com.yeshi.common.entity.taobao.TaoKeAppInfo; |
| | | import com.yeshi.fanli.exception.goods.ConvertLinkException; |
| | | 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.goods.facade.utils.taobao.HaoDanKuApiUtil; |
| | | import com.yeshi.fanli.util.taobao.TaoBaoUtil; |
| | | import com.yeshi.fanli.util.taobao.TaoKeApiUtil; |
| | | import org.yeshi.utils.UrlUtils; |
| | | |
| | | /** |
| | | * 转链组件 |
| | | * |
| | | * @author Administrator |
| | | */ |
| | | @Component |
| | | public class ConvertLinkManager { |
| | | |
| | | @Resource |
| | | private UserExtraTaoBaoInfoService userExtraTaoBaoInfoService; |
| | | |
| | | @Resource |
| | | private TaoBaoBuyRelationMapService taoBaoBuyRelationMapService; |
| | | |
| | | @Resource |
| | | private RedisManager redisManager; |
| | | |
| | | @Resource |
| | | private TaoBaoTokenAuctionIdMapManager taoBaoTokenAuctionIdMapManager; |
| | | |
| | | @Resource |
| | | private PDDAuthService pddAuthService; |
| | | |
| | | @Resource |
| | | private PIDManager pidManager; |
| | | |
| | | /** |
| | | * @Title: convertJDLinkFromText @Description:转链文本中的京东短链 @param text @param |
| | | * uid @param share @return @throws Exception String 返回类型 @throws |
| | | */ |
| | | |
| | | public String convertJDLinkFromText(SystemEnum system, String text, Long uid, boolean share, boolean simpleTKToken) throws Exception { |
| | | |
| | | StringBuilder builder = new StringBuilder(text); |
| | | String newText = builder.toString(); |
| | | // 京东转链 |
| | | // 提取京东所有的链接 |
| | | List<String> jdShortLink = JDUtil.getJDShortLinksFromText(text); |
| | | Set<String> linkSet = new HashSet<>(); |
| | | Map<String, String> linkMap = new HashMap<>(); |
| | | if (jdShortLink != null && jdShortLink.size() > 0) { |
| | | linkSet.addAll(jdShortLink); |
| | | for (String shortLink : linkSet) { |
| | | String link = null; |
| | | if (share) |
| | | link = JDApiUtil.convertLinkWithSubUnionId(shortLink, null, null, pidManager.getPidCache(system, Constant.SOURCE_TYPE_JD, SystemPIDInfo.PidType.share), |
| | | uid + ""); |
| | | else |
| | | link = JDApiUtil.convertLinkWithSubUnionId(shortLink, null, null, pidManager.getPidCache(system, Constant.SOURCE_TYPE_JD, SystemPIDInfo.PidType.fanli), |
| | | uid + ""); |
| | | if (!StringUtil.isNullOrEmpty(link)) { |
| | | linkMap.put(shortLink, link); |
| | | } |
| | | } |
| | | } |
| | | |
| | | for (String link : linkSet) { |
| | | if (linkMap.get(link) == null) |
| | | throw new Exception("京东转链失败"); |
| | | newText = newText.replace(link, linkMap.get(link)); |
| | | } |
| | | |
| | | return newText; |
| | | } |
| | | |
| | | public String convertPDDLinkFromText(SystemEnum system, 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)) { |
| | | PDDGoodsDetail goodsDetail = PinDuoDuoApiUtil.getGoodsDetail(goodsId); |
| | | if (goodsDetail == null) |
| | | throw new Exception("拼多多转链失败"); |
| | | PDDConvertLinkResultVO pddUrl = PinDuoDuoApiUtil.convert(goodsDetail.getGoodsSign(), |
| | | share ? pidManager.getPidCache(system, Constant.SOURCE_TYPE_PDD, SystemPIDInfo.PidType.share) : pidManager.getPidCache(system, Constant.SOURCE_TYPE_PDD, SystemPIDInfo.PidType.fanli), pddAuthService.getFanliCustomParams(uid), false); |
| | | if (pddUrl != null) { |
| | | linkMap.put(shortLink, pddUrl.getShort_url()); |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | 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 |
| | | * uid @param share @return @throws Exception String 返回类型 @throws |
| | | */ |
| | | /** |
| | | * @param text |
| | | * @param uid |
| | | * @param share |
| | | * @param simpleToken -是否采用简版淘口令 |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | private String convertTBLinkFromText(SystemEnum system, String text, Long uid, boolean share, boolean simpleToken) throws Exception { |
| | | |
| | | |
| | | String specialPid = pidManager.getPid(system, Constant.SOURCE_TYPE_TAOBAO, SystemPIDInfo.PidType.fanli); |
| | | String relationPid = pidManager.getPid(system, Constant.SOURCE_TYPE_TAOBAO, SystemPIDInfo.PidType.share); |
| | | String specialRelationPid = pidManager.getPid(system, Constant.SOURCE_TYPE_TAOBAO, SystemPIDInfo.PidType.fanliChannel); |
| | | |
| | | StringBuilder builder = new StringBuilder(text); |
| | | String newText = builder.toString(); |
| | | |
| | | // 解析淘口令 |
| | | List<String> tokenList = TaoBaoUtil.getTokenListFromTextWithKuoHao(newText); |
| | | if (tokenList != null && tokenList.size() > 0) { |
| | | |
| | | String relationId = null; |
| | | if (share) { |
| | | relationId = userExtraTaoBaoInfoService.getRelationIdByUid(uid); |
| | | if (StringUtil.isNullOrEmpty(relationId)) |
| | | throw new Exception("淘宝未授权"); |
| | | } |
| | | |
| | | Set<String> tokenSet = new HashSet<>(); |
| | | tokenSet.addAll(tokenList); |
| | | Map<String, String> tokenMap = new HashMap<>(); |
| | | for (String token : tokenSet) { |
| | | String auctionId = taoBaoTokenAuctionIdMapManager.getAuctionIdByToken(token); |
| | | if (auctionId == null) |
| | | throw new Exception("从淘口令获取商品失败"); |
| | | TaoBaoGoodsBrief simpleGoods = TaoKeApiUtil.getSimpleGoodsInfo(auctionId); |
| | | if (simpleGoods == null) |
| | | throw new Exception("商品信息获取失败"); |
| | | String link = null; |
| | | if (share) { |
| | | //暂时调用好单库API |
| | | link = HaoDanKuApiUtil.getInstance().convertLink(auctionId, relationPid, null, null, relationId); |
| | | // TaoBaoGoodsBrief goods = TaoKeApiUtil.specialConvertCoupon(auctionId, |
| | | // new TaoKeAppInfo(TaoBaoConstant.TAOBAO_AUTH_APPKEY, TaoBaoConstant.TAOBAO_AUTH_APPSECRET, |
| | | // TaoBaoConstant.TAOBAO_RELATION_PID_DEFAULT)); |
| | | // if (goods == null) |
| | | // throw new Exception("商品转链失败"); |
| | | // |
| | | // link = goods.getCouponLink(); |
| | | // if (StringUtil.isNullOrEmpty(link)) { |
| | | // link = goods.getAuctionUrl(); |
| | | // } |
| | | if (StringUtil.isNullOrEmpty(link)) |
| | | throw new Exception("商品转链失败"); |
| | | link += "&relationId=" + relationId; |
| | | } else { |
| | | String specialId = userExtraTaoBaoInfoService.getSpecialIdByUid(uid); |
| | | |
| | | |
| | | if (simpleGoods.getMaterialLibType() != null && simpleGoods.getMaterialLibType() == 1) { |
| | | TaoBaoGoodsBrief goods = TaoKeApiUtil.specialConvertCouponV2(auctionId, |
| | | new TaoKeAppInfo(TaoBaoConstant.TAOBAO_AUTH_APPKEY, |
| | | TaoBaoConstant.TAOBAO_AUTH_APPSECRET, |
| | | specialPid), specialId, null); |
| | | if (goods == null) |
| | | throw new Exception("商品转链失败"); |
| | | |
| | | link = goods.getCouponLink(); |
| | | if (StringUtil.isNullOrEmpty(link)) { |
| | | link = goods.getAuctionUrl(); |
| | | } |
| | | } else { |
| | | String sRelationId = taoBaoBuyRelationMapService.getRelationId(uid); |
| | | |
| | | TaoBaoGoodsBrief goods = TaoKeApiUtil.specialConvertCouponV2(auctionId, |
| | | new TaoKeAppInfo(TaoBaoConstant.TAOBAO_AUTH_APPKEY, |
| | | TaoBaoConstant.TAOBAO_AUTH_APPSECRET, |
| | | specialRelationPid), specialId, null); |
| | | if (goods == null) |
| | | throw new Exception("商品转链失败"); |
| | | |
| | | link = goods.getCouponLink(); |
| | | if (StringUtil.isNullOrEmpty(link)) { |
| | | link = goods.getAuctionUrl(); |
| | | } |
| | | if (StringUtil.isNullOrEmpty(link)) |
| | | throw new Exception("商品转链失败"); |
| | | link += "&relationId=" + sRelationId; |
| | | } |
| | | } |
| | | |
| | | if (StringUtil.isNullOrEmpty(link)) { |
| | | throw new Exception("商品转链失败"); |
| | | } |
| | | |
| | | String newToken = TaoKeApiUtil.getTKToken(simpleGoods.getPictUrl(), simpleGoods.getTitle(), link, simpleToken); |
| | | if (StringUtil.isNullOrEmpty(newToken)) { |
| | | throw new Exception("口令转链失败"); |
| | | } |
| | | tokenMap.put(token, TaoBaoUtil.filterTaoToken(newToken)); |
| | | } |
| | | |
| | | for (String token : tokenSet) { |
| | | if (tokenMap.get(token) == null) |
| | | throw new Exception("淘宝部分转链失败"); |
| | | 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 = relationPid.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, simpleToken); |
| | | newText = newText.replace(st, TaoBaoUtil.filterTaoToken(token)); |
| | | } |
| | | } |
| | | } |
| | | |
| | | return newText; |
| | | } |
| | | |
| | | /** |
| | | * @Title: convertLinkFromText @Description: 从文本转链 @param text @return |
| | | * String 返回类型 @throws |
| | | */ |
| | | public String convertLinkFromText(SystemEnum system, String text, Long uid, boolean share, boolean simpleToken) |
| | | throws ConvertLinkException, Exception { |
| | | String newText = convertJDLinkFromText(system, text, uid, share, simpleToken); |
| | | newText = convertPDDLinkFromText(system, newText, uid, share); |
| | | newText = convertTBLinkFromText(system, newText, uid, share, simpleToken); |
| | | |
| | | List<String> urls = UrlUtils.parseUrlsFromText(text); |
| | | if (urls != null) |
| | | for (String url : urls) { |
| | | if (url.contains("{relationId}")) { |
| | | String relationId = userExtraTaoBaoInfoService.getRelationIdByUid(uid); |
| | | if (StringUtil.isNullOrEmpty(relationId)) { |
| | | throw new Exception("淘宝未授权"); |
| | | } |
| | | newText = newText.replace(url, url.replace("{relationId}", relationId)); |
| | | } |
| | | } |
| | | if (text.equalsIgnoreCase(newText)) |
| | | throw new ConvertLinkException(ConvertLinkException.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, boolean simpleToken) { |
| | | String token = TaoKeApiUtil.getTKToken(picturl, title, link, simpleToken); |
| | | if (!StringUtil.isNullOrEmpty(token)) { |
| | | // 缓存30分钟 |
| | | redisManager.cacheCommonString( |
| | | RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoUserTKToken, uid + "-" + StringUtil.Md5(token)), "1", |
| | | 60 * 30); |
| | | } |
| | | return token; |
| | | } |
| | | |
| | | @Resource |
| | | private UserFunctionsLimitService userFunctionsLimitService; |
| | | |
| | | |
| | | //淘宝官方活动转链 |
| | | public TaoKeOfficialActivityConvertResultDTO taobaoOfficialActivityConvert(Long uid, String pid, String promotionSceneId, String relationId, boolean share) throws ConvertLinkException { |
| | | // 用户ID不为空时要验证相关的能力 |
| | | if (uid != null) { |
| | | //自购 |
| | | if (!share) { |
| | | if (userFunctionsLimitService.isLimit(uid, SystemFunction.fanli, new Date())) { |
| | | throw new ConvertLinkException(ConvertLinkException.CODE_FUNCTION_LIMIT, "该功能被限制"); |
| | | } |
| | | } else { |
| | | //分享 |
| | | if (userFunctionsLimitService.isLimit(uid, SystemFunction.share, new Date())) { |
| | | throw new ConvertLinkException(ConvertLinkException.CODE_FUNCTION_LIMIT, "该功能被限制"); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | TaoKeOfficialActivityConvertResultDTO dto = TaoKeApiUtil.officialActivityConvert( |
| | | pid.split("_")[3], promotionSceneId, relationId); |
| | | return dto; |
| | | } |
| | | |
| | | |
| | | public static void main(String[] args){ |
| | | |
| | | String newText = "【天猫】双11-预售玩法会场!做任务,赢最高16元红包!\n" + |
| | | "復製本条{淘宝活动:20150318020016625},进入【Ta0宝】立即抢购!"; |
| | | // 解析淘宝官方活动ID |
| | | List<String> list = new ConvertLinkManager(). getTaoBaoOfficialActivityId(newText); |
| | | if (list.size() > 0) { |
| | | String relationId = null; |
| | | for (String st : list) { |
| | | String activityid = st.replace("{淘宝活动:", "").replace("}", ""); |
| | | if (!StringUtil.isNullOrEmpty(activityid)) { |
| | | String adzoneId = "mm_124933865_56750082_89555600043".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, true); |
| | | newText = newText.replace(st, TaoBaoUtil.filterTaoToken(token)); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | } |