| | |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import com.yeshi.fanli.entity.taobao.SearchFilter; |
| | | import com.yeshi.fanli.entity.taobao.TaoBaoSearchResult; |
| | | import com.yeshi.fanli.util.*; |
| | | import com.yeshi.fanli.util.goods.douyin.CSJCPSApiUtil; |
| | | import com.yeshi.fanli.util.goods.douyin.DYUtil; |
| | | import com.yeshi.fanli.util.goods.douyin.vo.DYGoodsDetail; |
| | | import com.yeshi.fanli.util.taobao.TaoKeApiUtil; |
| | | import com.yeshi.goods.facade.utils.taobao.DaTaoKeApiUtil; |
| | | import org.jsoup.Jsoup; |
| | | import org.springframework.stereotype.Component; |
| | | import org.yeshi.utils.HttpUtil; |
| | | import org.yeshi.utils.NumberUtil; |
| | |
| | | import com.yeshi.fanli.service.inter.user.TokenRecordService; |
| | | import com.yeshi.fanli.service.manger.goods.jd.JDGoodsLinkParseManager; |
| | | import com.yeshi.fanli.service.manger.goods.tb.TaoBaoTokenAuctionIdMapManager; |
| | | import com.yeshi.fanli.util.Constant; |
| | | import com.yeshi.fanli.util.DouYinUtil; |
| | | import com.yeshi.fanli.util.RedisManager; |
| | | import com.yeshi.fanli.util.StringUtil; |
| | | import com.yeshi.fanli.util.TokenUtil; |
| | | import com.yeshi.fanli.util.Utils; |
| | | import com.yeshi.fanli.util.VersionUtil; |
| | | import com.yeshi.fanli.util.factory.CommonGoodsFactory; |
| | | import com.yeshi.fanli.util.jd.JDApiUtil; |
| | | import com.yeshi.fanli.util.jd.JDUtil; |
| | |
| | | typeSet.add(ClipboardContentType.text); |
| | | } |
| | | |
| | | |
| | | return typeSet; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 特价解析粘贴板 |
| | | * 无平台,根据格式判断平台 |
| | | * |
| | | * @param text |
| | | */ |
| | | public Integer tejiaParseSourceType(String text) { |
| | | if (text == null) |
| | | return null; |
| | | text = text.trim(); |
| | | //判断是否有链接 |
| | | List<String> linkList = HttpUtil.getUrlListFromText(text); |
| | | if (linkList != null && linkList.size() > 0) { |
| | | String link = linkList.get(0); |
| | | if (TaoBaoUtil.isTaoBaoLink(link)) { |
| | | return Constant.SOURCE_TYPE_TAOBAO; |
| | | } else if (JDUtil.isJDLink(link)) { |
| | | return Constant.SOURCE_TYPE_JD; |
| | | } else if (PinDuoDuoUtil.isPDDLink(link)) { |
| | | return Constant.SOURCE_TYPE_PDD; |
| | | } else if (VipShopUtil.isVIPShopLink(link)) { |
| | | return Constant.SOURCE_TYPE_VIP; |
| | | } else if (SuningUtil.isSuningLink(link)) { |
| | | return Constant.SOURCE_TYPE_SUNING; |
| | | } |
| | | //链接非电商平台链接 |
| | | return null; |
| | | } |
| | | |
| | | //判断是否疑似口令 |
| | | if (TaoBaoUtil.isHaveNewVersionTaoBaoToken(text)) { |
| | | return Constant.SOURCE_TYPE_TAOBAO; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | |
| | | text = text.trim(); |
| | | |
| | | Set<ClipboardContentType> typeSet = parseContentType(text, platform, version); |
| | | //新版口令 |
| | | String goodsId = null; |
| | | if (text.contains("https://m.tb.cn/")) { |
| | | String tempGoodsId = DaTaoKeApiUtil.parseGoodsIdFromToken(text); |
| | | if (tempGoodsId != null) { |
| | | goodsId = tempGoodsId; |
| | | typeSet.add(ClipboardContentType.taoBaoToken); |
| | | } else { |
| | | try { |
| | | TaoKeApiUtil.TokenConvertResult result = TaoKeApiUtil.tokenConvert(text); |
| | | if (result != null) { |
| | | goodsId = result.getNum_iid(); |
| | | typeSet.add(ClipboardContentType.taoBaoToken); |
| | | } |
| | | } catch (TaoBaoTokenParseException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 系统口令 |
| | | if (typeSet.contains(ClipboardContentType.systemToken)) { |
| | |
| | | return; |
| | | } |
| | | //优先解析淘口令 |
| | | Long goodsId = DaTaoKeApiUtil.parseTaoBaoToken(text); |
| | | if (goodsId != null) { |
| | | CommonGoods commonGoods = getTaoBaoGoods(goodsId); |
| | | if (commonGoods != null) |
| | | resultListener.onResult(commonGoods); |
| | | else |
| | | resultListener.onResult(text); |
| | | |
| | | TaoBaoGoodsBrief taobaoGoods =null; |
| | | try { |
| | | taobaoGoods = TaoKeApiUtil.getSimpleGoodsInfoForOwnBuy(goodsId); |
| | | } catch (TaobaoGoodsDownException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | if (taobaoGoods==null) { |
| | | int startIndex = text.indexOf("「"); |
| | | int endIndex = text.indexOf("」"); |
| | | if (startIndex > 0 && endIndex > 0) { |
| | | resultListener.onResult(text.substring(startIndex+1,endIndex)); |
| | | return; |
| | | } |
| | | } else { |
| | | CommonGoods commonGoods = CommonGoodsFactory.create(taobaoGoods); |
| | | if (commonGoods != null) |
| | | resultListener.onResult(commonGoods); |
| | | else |
| | | resultListener.onResult(text); |
| | | } |
| | | return; |
| | | } |
| | | |
| | |
| | | } catch (UnsupportedEncodingException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | //TODO 解析链接中的title |
| | | // Jsoup.connect(text).get(); |
| | | |
| | | |
| | | resultListener.none(); |
| | | } else { |
| | |
| | | if (simpleGoods.getGoodsType() == Constant.SOURCE_TYPE_TAOBAO) { |
| | | TaoBaoGoodsBrief goods = null; |
| | | try { |
| | | goods = redisManager.getTaoBaoGoodsBrief(Long.parseLong(simpleGoods.getGoodsId())); |
| | | goods = redisManager.getTaoBaoGoodsBrief(simpleGoods.getGoodsId()); |
| | | } catch (NumberFormatException e) { |
| | | e.printStackTrace(); |
| | | } catch (TaobaoGoodsDownException e) { |
| | |
| | | if (goods != null) { |
| | | commonGoods = CommonGoodsFactory.create(goods); |
| | | } else { |
| | | goods = TaoBaoUtil.getTmallGoodsInfo(simpleGoods.getGoodsId()); |
| | | if (goods != null) { |
| | | SearchFilter sf=new SearchFilter(); |
| | | sf.setKey("https://item.taobao.com/item.htm?id="+simpleGoods.getGoodsId()); |
| | | TaoBaoSearchResult searchResult = TaoKeApiUtil.searchWuLiaoNew(sf,null,null); |
| | | if(searchResult!=null&&searchResult.getTaoBaoGoodsBriefs()!=null&&searchResult.getTaoBaoGoodsBriefs().size()>0){ |
| | | TaoBaoGoodsBrief tempGoods = searchResult.getTaoBaoGoodsBriefs().get(0); |
| | | commonGoods = new CommonGoods(); |
| | | commonGoods.setTitle(goods.getTitle()); |
| | | commonGoods.setPicture(goods.getPictUrl()); |
| | | } else { |
| | | // TODO 根据淘宝商品ID解析标题与图片 |
| | | commonGoods.setTitle(tempGoods.getTitle()); |
| | | commonGoods.setPicture(tempGoods.getPictUrl()); |
| | | }else { |
| | | goods = TaoBaoUtil.getTmallGoodsInfo(simpleGoods.getGoodsId()); |
| | | if (goods != null) { |
| | | commonGoods = new CommonGoods(); |
| | | commonGoods.setTitle(goods.getTitle()); |
| | | commonGoods.setPicture(goods.getPictUrl()); |
| | | } else { |
| | | // TODO 根据淘宝商品ID解析标题与图片 |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | if (goods != null) { |
| | | commonGoods = CommonGoodsFactory.create(goods); |
| | | } |
| | | } else if (simpleGoods.getGoodsType() == Constant.SOURCE_TYPE_DY) { |
| | | DYGoodsDetail goods = CSJCPSApiUtil.goodsDetail(Long.parseLong(simpleGoods.getGoodsId())); |
| | | if (goods != null) { |
| | | commonGoods = CommonGoodsFactory.create(goods); |
| | | } |
| | | } |
| | | |
| | | return commonGoods; |
| | |
| | | if (!StringUtil.isNullOrEmpty(vipId)) { |
| | | return new SimpleCommonGoods(vipId, Constant.SOURCE_TYPE_VIP); |
| | | } |
| | | String dyProductId = DYUtil.parseProdectIdFromLink(link); |
| | | if (!StringUtil.isNullOrEmpty(dyProductId)) { |
| | | return new SimpleCommonGoods(dyProductId, Constant.SOURCE_TYPE_DY); |
| | | } |
| | | |
| | | // 解析淘宝 |
| | | String auctionId = parseTBAuctionIdFromLink(link); |
| | |
| | | } |
| | | |
| | | // 领券短连接 |
| | | if (StringUtil.isNullOrEmpty(jdId) && link.contains("u.jd.com")) { |
| | | if (StringUtil.isNullOrEmpty(jdId) && (link.contains("u.jd.com")||link.contains("//3.cn/"))) { |
| | | jdId = jdGoodsLinkParseManager.parseGoodsIdByJDShortUrl(link); |
| | | } |
| | | |
| | | return jdId; |
| | | } |
| | | |
| | | |
| | | |
| | | public String parseTBAuctionIdFromLink(String link) { |
| | |
| | | } |
| | | |
| | | private CommonGoods parseTaoBaoToken(String token) throws TaoBaoTokenParseException { |
| | | Long auctionId = taoBaoTokenAuctionIdMapManager.getAuctionIdByToken(token); |
| | | String auctionId = taoBaoTokenAuctionIdMapManager.getAuctionIdByToken(token); |
| | | if (auctionId != null) {// |
| | | return getTaoBaoGoods(auctionId); |
| | | } else { |
| | |
| | | } |
| | | } |
| | | |
| | | private CommonGoods getTaoBaoGoods(Long auctionId) { |
| | | private CommonGoods getTaoBaoGoods(String auctionId) { |
| | | TaoBaoGoodsBrief goods = TaoBaoUtil.isAlimama(auctionId + ""); |
| | | if (goods == null) { |
| | | goods = TaoBaoUtil.getTaoBaoGoodsBriefNotInPub(auctionId); |
| | |
| | | this.goodsType = goodsType; |
| | | } |
| | | } |
| | | |
| | | |
| | | public static void main(String[] args) { |
| | | //String originText, String platform, String version |
| | | |
| | | new ClipboardAnalysisManager(). parseJDSkuIdFromLink("https://3.cn/1-U6tjhC"); |
| | | |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | * |
| | | * @author Administrator |
| | | */ |
| | | |
| | | |