| | |
| | | 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.*; |
| | | 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.pdd.PDDPromotionUrl; |
| | | 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.ConvertLinkExceptionException; |
| | | 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; |
| | |
| | | @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(String text, Long uid, boolean share, boolean simpleTKToken) throws Exception { |
| | | public String convertJDLinkFromText(SystemEnum system, String text, Long uid, boolean share, boolean simpleTKToken) throws Exception { |
| | | |
| | | StringBuilder builder = new StringBuilder(text); |
| | | String newText = builder.toString(); |
| | |
| | | for (String shortLink : linkSet) { |
| | | String link = null; |
| | | if (share) |
| | | link = JDApiUtil.convertLinkWithSubUnionId(shortLink, null, null, JDApiUtil.POSITION_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, JDApiUtil.POSITION_FANLI + "", |
| | | 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); |
| | |
| | | return newText; |
| | | } |
| | | |
| | | public String convertPDDLinkFromText(String text, Long uid, boolean share) throws Exception { |
| | | public String convertPDDLinkFromText(SystemEnum system, String text, Long uid, boolean share) throws Exception { |
| | | |
| | | StringBuilder builder = new StringBuilder(text); |
| | | String newText = builder.toString(); |
| | |
| | | for (String shortLink : linkSet) { |
| | | String goodsId = PinDuoDuoUtil.getPDDGoodsId(shortLink); |
| | | if (!StringUtil.isNullOrEmpty(goodsId)) { |
| | | PDDGoodsDetail goodsDetail = PinDuoDuoApiUtil.getGoodsDetail(Long.parseLong(goodsId)); |
| | | PDDGoodsDetail goodsDetail = PinDuoDuoApiUtil.getGoodsDetail(goodsId); |
| | | if (goodsDetail == null) |
| | | throw new Exception("拼多多转链失败"); |
| | | PDDConvertLinkResultVO pddUrl = PinDuoDuoApiUtil.convert(goodsDetail.getGoodsSign(), |
| | | share ? PinDuoDuoApiUtil.PID_SHARE : PinDuoDuoApiUtil.PID_FANLI, pddAuthService.getFanliCustomParams(uid), false); |
| | | 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()); |
| | | } |
| | |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | private String convertTBLinkFromText(String text, Long uid, boolean share, boolean simpleToken) 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(); |
| | |
| | | tokenSet.addAll(tokenList); |
| | | Map<String, String> tokenMap = new HashMap<>(); |
| | | for (String token : tokenSet) { |
| | | Long auctionId = taoBaoTokenAuctionIdMapManager.getAuctionIdByToken(token); |
| | | String auctionId = taoBaoTokenAuctionIdMapManager.getAuctionIdByToken(token); |
| | | if (auctionId == null) |
| | | throw new Exception("从淘口令获取商品失败"); |
| | | TaoBaoGoodsBrief simpleGoods = TaoKeApiUtil.getSimpleGoodsInfo(auctionId); |
| | |
| | | String link = null; |
| | | if (share) { |
| | | //暂时调用好单库API |
| | | link = HaoDanKuApiUtil.getInstance().convertLink(auctionId, TaoBaoConstant.TAOBAO_RELATION_PID_DEFAULT, null, null, relationId); |
| | | 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 (simpleGoods.getMaterialLibType() != null && simpleGoods.getMaterialLibType() == 1) { |
| | | TaoBaoGoodsBrief goods = TaoKeApiUtil.specialConvertCoupon(auctionId, |
| | | TaoBaoGoodsBrief goods = TaoKeApiUtil.specialConvertCouponV2(auctionId, |
| | | new TaoKeAppInfo(TaoBaoConstant.TAOBAO_AUTH_APPKEY, |
| | | TaoBaoConstant.TAOBAO_AUTH_APPSECRET, |
| | | TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT), specialId, null); |
| | | specialPid), specialId, null); |
| | | if (goods == null) |
| | | throw new Exception("商品转链失败"); |
| | | |
| | |
| | | } else { |
| | | String sRelationId = taoBaoBuyRelationMapService.getRelationId(uid); |
| | | |
| | | TaoBaoGoodsBrief goods = TaoKeApiUtil.specialConvertCoupon(auctionId, |
| | | TaoBaoGoodsBrief goods = TaoKeApiUtil.specialConvertCouponV2(auctionId, |
| | | new TaoKeAppInfo(TaoBaoConstant.TAOBAO_AUTH_APPKEY, |
| | | TaoBaoConstant.TAOBAO_AUTH_APPSECRET, |
| | | TaoBaoConstant.TAOBAO_RELATION_AS_SPECIAL_PID), specialId, null); |
| | | specialRelationPid), specialId, null); |
| | | if (goods == null) |
| | | 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]; |
| | | String adzoneId = relationPid.split("_")[3]; |
| | | TaoKeOfficialActivityConvertResultDTO dto = TaoKeApiUtil.officialActivityConvert(adzoneId, |
| | | activityid, relationId); |
| | | String link = dto.getShort_click_url(); |
| | |
| | | * @Title: convertLinkFromText @Description: 从文本转链 @param text @return |
| | | * String 返回类型 @throws |
| | | */ |
| | | public String convertLinkFromText(String text, Long uid, boolean share, boolean simpleToken) |
| | | throws ConvertLinkExceptionException, Exception { |
| | | String newText = convertJDLinkFromText(text, uid, share, simpleToken); |
| | | newText = convertPDDLinkFromText(newText, uid, share); |
| | | newText = convertTBLinkFromText(newText, uid, share, simpleToken); |
| | | 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) |
| | |
| | | } |
| | | } |
| | | if (text.equalsIgnoreCase(newText)) |
| | | throw new ConvertLinkExceptionException(ConvertLinkExceptionException.CODE_NONE, "不包含可转链的口令与链接"); |
| | | throw new ConvertLinkException(ConvertLinkException.CODE_NONE, "不包含可转链的口令与链接"); |
| | | return newText; |
| | | } |
| | | |
| | |
| | | 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)); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | } |