From 98b1a0affd69bbe63223c21fdd2c404e8bedfccb Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期三, 20 五月 2020 17:25:08 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/div' into 2.1.2 --- fanli/src/main/java/com/yeshi/fanli/util/taobao/TaoBaoUtil.java | 225 ++++++++++++++++++++++++++++++++++--------------------- 1 files changed, 139 insertions(+), 86 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/util/taobao/TaoBaoUtil.java b/fanli/src/main/java/com/yeshi/fanli/util/taobao/TaoBaoUtil.java index 7c282c9..6c819a4 100644 --- a/fanli/src/main/java/com/yeshi/fanli/util/taobao/TaoBaoUtil.java +++ b/fanli/src/main/java/com/yeshi/fanli/util/taobao/TaoBaoUtil.java @@ -6,6 +6,7 @@ import java.net.URLDecoder; import java.net.URLEncoder; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -43,6 +44,7 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; +import com.yeshi.fanli.entity.bus.user.vip.UserLevelEnum; import com.yeshi.fanli.entity.common.ImageInfo; import com.yeshi.fanli.entity.goods.CommonGoods; import com.yeshi.fanli.entity.taobao.SearchFilter; @@ -58,7 +60,6 @@ import com.yeshi.fanli.entity.taobao.TaoBaoSearchResult; import com.yeshi.fanli.entity.taobao.TaoBaoShop; import com.yeshi.fanli.entity.taobao.TaoBaoUnionConfig; -import com.yeshi.fanli.entity.taobao.dataoke.DaTaoKeDetail; import com.yeshi.fanli.entity.taobao.dataoke.DaTaoKeDetailV2; import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException; import com.yeshi.fanli.log.LogHelper; @@ -789,14 +790,11 @@ private static TaoBaoGoodsBriefExtra loadYuShouInfo(TaoBaoGoodsBriefExtra extra, TaoBaoGoodsBrief goods) { if (goods != null && extra != null) { if (isYUShou(goods)) {// 棰勫敭鍟嗗搧 - extra.setZkPrice(new BigDecimal(goods.getPresaleDeposit())); + // extra.setZkPrice(new BigDecimal(goods.getPresaleDeposit())); // 棰勫敭 if (extra.getLabels() == null) extra.setLabels(new ArrayList<>()); extra.getLabels().add(new ClientTextStyleVO("棰勫敭", "#FF2B4E")); - if (!StringUtil.isNullOrEmpty(goods.getPresaleDiscountFeeText())) {// 鍦ㄦ爣棰樻坊鍔犱紭鎯犱俊鎭� - extra.setTitle(String.format("銆�%s銆�", goods.getPresaleDiscountFeeText()) + extra.getTitle()); - } } } return extra; @@ -1024,7 +1022,7 @@ tg.setTaoBaoQuanInfo(quanInfo); } - BigDecimal proportion = taoBaoUtil.manageService.getFanLiRate(); + BigDecimal proportion = taoBaoUtil.manageService.getFanLiRate(UserLevelEnum.daRen); TaoBaoHongBaoInfo hongBaoInfo = new TaoBaoHongBaoInfo(); String tkMktStatus = tb.getTkMktStatus(); if ("1".equals(tkMktStatus)) { @@ -1077,23 +1075,13 @@ return tg; } - public static TaoBaoGoodsBrief getTaoBaoGoodsBrief(String id) { - Map<String, String> params = new HashMap<String, String>(); - params.put("q", String.format("http://item.taobao.com/item.htm?id=%s", id)); - params.put("_t", System.currentTimeMillis() + ""); - params.put("auctionTag", ""); - params.put("perPageSize", 40 + ""); - params.put("t", System.currentTimeMillis() + ""); - String result = TaoBaoHttpUtil.get(SEARCH_URL, params); - result = result.replace("</span>", "").replace("<span class=H>", ""); - TaoBaoSearchResult presult = parseTaoBao(result); - if (presult != null && presult.getTaoBaoGoodsBriefs().size() > 0) { - // TaoBaoGoodsBrief taoBaoGoodsBrief = - // presult.getTaoBaoGoodsBriefs().get(0); - - return presult.getTaoBaoGoodsBriefs().get(0); - } else - return null; + /** + * 鑾峰彇鏈弬涓庢帹骞跨殑娣樺疂鍟嗗搧璇︽儏 @Title: getTaoBaoGoodsBrief @Description: @param + * id @return TaoBaoGoodsBrief 鍖呭惈锛堟爣棰樹笌鍥剧墖锛� @throws + */ + public static TaoBaoGoodsBrief getTaoBaoGoodsBriefNotInPub(Long id) { + TaoBaoGoodsBrief tb = TaoBaoUtil.getTmallGoodsInfo(id + ""); + return tb; } public static List<String> getSuguestSearch(String key) { @@ -1436,22 +1424,6 @@ */ public static BigDecimal getGoodsHongBaoMoney(TaoBaoGoodsBrief goodsBrief, BigDecimal rate) { BigDecimal money = null; - - // 棰勫敭鍟嗗搧 - if (isYUShou(goodsBrief)) { - if (goodsBrief.getYsylCommissionRate() != null) - money = MoneyBigDecimalUtil.mul( - MoneyBigDecimalUtil.mul(MoneyBigDecimalUtil.mul(new BigDecimal(goodsBrief.getPresaleDeposit()), - goodsBrief.getYsylCommissionRate()), new BigDecimal("0.01")), - MoneyBigDecimalUtil.div(rate, new BigDecimal(100))); - else - money = MoneyBigDecimalUtil.mul(MoneyBigDecimalUtil.mul( - MoneyBigDecimalUtil.mul(goodsBrief.getZkPrice(), goodsBrief.getTkRate()), - new BigDecimal("0.01")), MoneyBigDecimalUtil.div(rate, new BigDecimal(100))); - - return money; - } - if (StringUtil.isNullOrEmpty(goodsBrief.getCouponInfo()) || goodsBrief.getCouponInfo().trim().equalsIgnoreCase("鏃�")) { money = MoneyBigDecimalUtil.mul( @@ -1775,43 +1747,31 @@ return taoBaoGoods; } - public static TaoBaoGoodsBrief convert(DaTaoKeDetail detail) { - TaoBaoGoodsBrief taoBaoGoods = new TaoBaoGoodsBrief(); - taoBaoGoods.setAuctionId(detail.getGoodsId()); - taoBaoGoods.setBiz30day(detail.getSalesNum()); - taoBaoGoods.setCouponAmount(detail.getQuanPrice()); - taoBaoGoods.setCouponInfo(String.format("婊�%s鍏冨噺%s鍏�", detail.getQuanCondition(), - MoneyBigDecimalUtil.getWithNoZera(detail.getQuanPrice()))); - taoBaoGoods.setCouponLeftCount(detail.getQuanSurplus()); - taoBaoGoods.setCouponStartFee(new BigDecimal(detail.getQuanCondition())); - if (detail.getQuanReceive() != null) - taoBaoGoods.setCouponTotalCount(detail.getQuanSurplus() + detail.getQuanReceive()); - taoBaoGoods.setPictUrl(detail.getPic()); - taoBaoGoods.setPictUrlWhite(detail.getPic()); - taoBaoGoods.setSellerId(detail.getSellerId()); - taoBaoGoods.setShopTitle(""); - taoBaoGoods.setTitle(detail.getdTitle()); - taoBaoGoods.setUserType(detail.getIsTmall()); - taoBaoGoods.setZkPrice(detail.getOrgPrice()); - taoBaoGoods.setTkRate(detail.getCommission()); - taoBaoGoods.setTkCommFee(new BigDecimal("0")); - taoBaoGoods.setState(0); - return taoBaoGoods; - } - public static TaoBaoGoodsBrief convert(DaTaoKeDetailV2 detail) { TaoBaoGoodsBrief taoBaoGoods = new TaoBaoGoodsBrief(); taoBaoGoods.setAuctionId(detail.getGoodsId()); taoBaoGoods.setBiz30day(detail.getMonthSales()); + // 鍒哥浉鍏宠浆鎹� taoBaoGoods.setCouponAmount(detail.getCouponPrice()); - taoBaoGoods.setCouponInfo(String.format("婊�%s鍏冨噺%s鍏�", detail.getCouponConditions(), + taoBaoGoods.setCouponInfo(String.format("婊�%s鍏冨噺%s鍏�", detail.getOriginalPrice(), MoneyBigDecimalUtil.getWithNoZera(detail.getCouponPrice()))); if (detail.getCouponTotalNum() != null && detail.getCouponReceiveNum() != null) taoBaoGoods.setCouponLeftCount(detail.getCouponTotalNum() - detail.getCouponReceiveNum()); else taoBaoGoods.setCouponLeftCount(0); taoBaoGoods.setCouponStartFee(detail.getOriginalPrice()); + try { + taoBaoGoods.setCouponStartFee(detail.getOriginalPrice()); + } catch (Exception e) { + } + taoBaoGoods.setCouponTotalCount(detail.getCouponTotalNum()); + taoBaoGoods.setCouponLink(detail.getCouponLink()); + taoBaoGoods.setCouponEffectiveStartTime(TimeUtil.getGernalTime( + TimeUtil.convertToTimeTemp(detail.getCouponStartTime(), "yyyy-MM-dd HH:mm:ss"), "yyyy-MM-dd")); + taoBaoGoods.setCouponEffectiveEndTime(TimeUtil.getGernalTime( + TimeUtil.convertToTimeTemp(detail.getCouponEndTime(), "yyyy-MM-dd HH:mm:ss"), "yyyy-MM-dd")); + taoBaoGoods.setPictUrl(detail.getMainPic()); taoBaoGoods.setPictUrlWhite(detail.getMainPic()); if (taoBaoGoods.getPictUrl() != null && !taoBaoGoods.getPictUrl().startsWith("http")) @@ -1861,40 +1821,68 @@ return url; } + /** + * 鑾峰彇娣樺疂鐨勫晢鍝佽鎯� + * + * @param actionId + * @return + */ public static TaoBaoGoodsBrief getSimpleGoodsBrief(Long actionId) { JSONObject data = new JSONObject(); data.put("itemNumId", actionId + ""); String url = ""; try { - url = String.format("https://acs.m.taobao.com/h5/mtop.taobao.detail.getdetail/6.0/?data=%s", + url = String.format( + "http://acs.m.taobao.com/h5/mtop.taobao.detail.getdetail/6.0/?data=%s&qq-pf-to=pcqq.group", URLEncoder.encode(data.toString(), "UTF-8")); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } - String result = HttpUtil.get(url); + String result = null; + try { + Connection.Response doc = Jsoup.connect(url).ignoreContentType(true).timeout(1000 * 10) + .userAgent( + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Edge/18.18362") + .header("Accept", "text/html, application/xhtml+xml, application/xml; q=0.9, */*; q=0.8") + .header("Accept-Language", "zh-CN").header("Host", "acs.m.taobao.com") + .header("Upgrade-Insecure-Requests", "1") + .header("Cookie", + "_cc_=VFC%2FuZ9ajQ%3D%3D; isg=BLu7TvdFYk89dV4DMXO7XNRGU58lEM8SDjV-ja14l7rRDNvuNeBfYtlOJmznNycK; thw=cn; miid=1490566681358073134; x=e%3D1%26p%3D*%26s%3D0%26c%3D0%26f%3D0%26g%3D0%26t%3D0%26__ll%3D-1%26_ato%3D0; cna=ZW8rFCpNP1gCAWpXAiKqMzqi; tracknick=tb23001560; l=cBxbffilq1UJdAFCBOCanurza77OSdAYYuPzaNbMi_5NE6T1BR7Ok6G1vF96VsWdOW8B4NSiTkp9-etkZ3Znq9SpXUJ1.; tg=0; _w_app_lg=19; WAPFDFDTGFG=%2B4cMKKP%2B8PI%2BtNYpkiAuTPLkiJB1kcwi") + .execute(); + result = doc.body(); + } catch (Exception e1) { + e1.printStackTrace(); + } + JSONObject resultOBJ = JSONObject.fromObject(result); if (resultOBJ.optJSONObject("data") != null) { data = resultOBJ.optJSONObject("data"); - JSONObject item = data.optJSONObject("item"); - JSONObject seller = data.optJSONObject("seller"); - TaoBaoGoodsBrief goods = new TaoBaoGoodsBrief(); - goods.setAuctionId(item.optLong("itemId")); - goods.setTitle(item.optString("title")); - if (item.optJSONArray("images") != null && item.optJSONArray("images").size() > 0) { - String picture = item.optJSONArray("images").optString(0); - goods.setPictUrl(picture.startsWith("http") ? picture : "https:" + picture); + if (data != null) { + JSONObject item = data.optJSONObject("item"); + if (item != null) { + JSONObject seller = data.optJSONObject("seller"); + TaoBaoGoodsBrief goods = new TaoBaoGoodsBrief(); + goods.setTitle(item.optString("title")); + goods.setAuctionId(item.optLong("itemId")); + goods.setTitle(item.optString("title")); + if (item.optJSONArray("images") != null && item.optJSONArray("images").size() > 0) { + String picture = item.optJSONArray("images").optString(0); + goods.setPictUrl(picture.startsWith("http") ? picture : "https:" + picture); + } + if (seller != null) { + goods.setSellerId(seller.optLong("shopId")); + String shopType = seller.optString("shopType"); + if ("B".equalsIgnoreCase(shopType)) { + goods.setUserType(1); + } else + goods.setUserType(0); + goods.setShopTitle(seller.optString("shopName")); + } + return goods; + } } - goods.setSellerId(seller.optLong("shopId")); - String shopType = seller.optString("shopType"); - if ("B".equalsIgnoreCase(shopType)) { - goods.setUserType(1); - } else - goods.setUserType(0); - - goods.setShopTitle(seller.optString("shopName")); - return goods; } return null; } @@ -2027,14 +2015,14 @@ if (elements.size() >= 0) { for (int i = 0; i < elements.size(); i++) { String content = elements.get(i).toString(); - if (content.contains("var _DATA_Mdskip")) { + if (content.contains("var _DATA_Detail")) { content = content.replace("<script>", ""); content = content.replace("</script>", ""); if (content.contains("videoDetail")) { - content += ";function getData(){ var json={title:_DATA_Mdskip.item.title,pictUrl:_DATA_Mdskip.item.videoDetail.videoThumbnailURL}; return JSON.stringify(json);}"; + content += ";function getData(){ var json={title:_DATA_Detail.item.title,pictUrl:_DATA_Detail.item.images[0]}; return JSON.stringify(json);}"; } else { - content += ";function getData(){ var json={title:_DATA_Mdskip.item.title,pictUrl:_DATA_Mdskip.item.videos[0].videoThumbnailURL}; return JSON.stringify(json);}"; + content += ";function getData(){ var json={title:_DATA_Detail.item.title,pictUrl:_DATA_Detail.item.images[0]}; return JSON.stringify(json);}"; } ScriptEngineManager manager = new ScriptEngineManager(); @@ -2049,6 +2037,9 @@ taoBaoGoodsBrief = new TaoBaoGoodsBrief(); taoBaoGoodsBrief.setTitle(title.toString()); taoBaoGoodsBrief.setPictUrl(pictUrl.toString()); + if (!pictUrl.toString().startsWith("http")) { + taoBaoGoodsBrief.setPictUrl(TbImgUtil.getTBSize220Img("http:" + pictUrl.toString())); + } } break; @@ -2118,6 +2109,24 @@ return token; } + /** + * 鎻愬彇鑷湁鏍煎紡鐨勬窐鍙d护 + * + * @param str + * @return + */ + public static String parseSystemTaoToken(String str) { + String pattern = "(\\({1}[A-Za-z0-9]+\\){1})"; + Pattern r = Pattern.compile(pattern); + Matcher m = r.matcher(str); + while (m.find()) { + String group = m.group(0); + if (!StringUtil.isNullOrEmpty(group) && group.length() >= 10) + return group; + } + return null; + } + public static boolean isSpecialGoods(Integer materialLibType) { if (materialLibType != null && materialLibType == 1) return true; @@ -2125,4 +2134,48 @@ return false; } + private final static String[] taoTokenSymbols = new String[] { "鈧�-鈧�", "楼-楼", "锟�-锟�", "鈧�-鈧�", "\\$-\\$", "鈧�-鈧�", "垄-垄", + "鈧�-鈧�" }; + + /** + * 浠庢枃鏈腑鎻愬彇娣樺彛浠� @Title: getTokenListFromText @Description: @param str @return + * List<String> 杩斿洖绫诲瀷 @throws + */ + public static List<String> getTokenListFromText(String str) { + String[] marks = taoTokenSymbols; + + return getTokenListFromText(str, Arrays.asList(marks)); + } + + /** + * 浠庢枃鏈腑鎻愬彇娣樺彛浠�(鎷彿鐨勫彛浠や篃绠�) + * + * @param str + * @return + */ + public static List<String> getTokenListFromTextWithKuoHao(String str) { + String[] marks = taoTokenSymbols; + List<String> list = new ArrayList<>(); + for (String st : marks) + list.add(st); + list.add("\\(-\\)"); + list.add("锛�-锛�"); + return getTokenListFromText(str, list); + } + + public static List<String> getTokenListFromText(String str, List<String> markList) { + List<String> expressList = new ArrayList<>(); + for (String st : markList) { + expressList.add(String.format("(%s{1}[A-Za-z0-9]{11,13}+%s{1})", st.split("-")[0], st.split("-")[1])); + } + String pattern = StringUtil.concat(expressList, "|"); + Pattern r = Pattern.compile(pattern); + Matcher m = r.matcher(str); + List<String> urlList = new ArrayList<>(); + while (m.find()) { + urlList.add(m.group()); + } + return urlList; + } + } -- Gitblit v1.8.0