From f4a0f2acc63d7785eab108419a4e16f5f688cb95 Mon Sep 17 00:00:00 2001
From: yujian <yujian@163.com>
Date: 星期六, 18 一月 2020 12:06:27 +0800
Subject: [PATCH] 用户注册信息
---
fanli/src/main/java/com/yeshi/fanli/util/taobao/TaoBaoUtil.java | 564 +++++++++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 454 insertions(+), 110 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 acfba6b..edf39f4 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
@@ -3,8 +3,10 @@
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Type;
import java.math.BigDecimal;
+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;
@@ -14,11 +16,17 @@
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
+import javax.script.Invocable;
+import javax.script.ScriptEngine;
+import javax.script.ScriptEngineManager;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.params.HttpMethodParams;
+import org.hibernate.cache.spi.NaturalIdCacheKey;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
@@ -28,6 +36,7 @@
import org.springframework.stereotype.Component;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.NodeList;
+import org.yeshi.utils.BigDecimalUtil;
import org.yeshi.utils.HttpUtil;
import org.yeshi.utils.NumberUtil;
import org.yeshi.utils.entity.ProxyIP;
@@ -51,15 +60,17 @@
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.DaTaoKeDetailV2;
import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException;
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.inter.goods.TaoBaoLinkService;
-import com.yeshi.fanli.service.inter.hongbao.HongBaoManageService;
+import com.yeshi.fanli.service.inter.order.config.HongBaoManageService;
import com.yeshi.fanli.tag.PageEntity;
import com.yeshi.fanli.util.AESUtil;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.MoneyBigDecimalUtil;
import com.yeshi.fanli.util.StringUtil;
+import com.yeshi.fanli.util.TaoBaoConstant;
import com.yeshi.fanli.util.TaoBaoHttpUtil;
import com.yeshi.fanli.util.TimeUtil;
import com.yeshi.fanli.vo.msg.ClientTextStyleVO;
@@ -702,8 +713,13 @@
tg.setReservePrice(tb.getReservePrice());
tg.setUserType(tb.getUserType());
tg.setShopTitle(tb.getShopTitle());
+ tg.setTkRate(tb.getTkRate());
+ tg.setSellerId(tb.getSellerId());
tg.setState(tb.getState()); // 鐘舵�侊細2018-12-03
- if (tb.getCouponAmount().compareTo(BigDecimal.valueOf(0)) == 1) {
+ if (tb.getCouponAmount().compareTo(BigDecimal.valueOf(0)) > 0) {
+
+ tg.setCoupon(true);// 鏈夊埜
+
TaoBaoQuanInfo quanInfo = new TaoBaoQuanInfo();
quanInfo.setCouponAmount(tb.getCouponAmount());
String couponEffectiveEndTime = tb.getCouponEffectiveEndTime();
@@ -714,7 +730,7 @@
quanInfo.setCouponLeftCount(tb.getCouponLeftCount());
quanInfo.setCouponLink(
TaoBaoCouponUtil.getCoupleUrl(tb.getCouponActivityId(), pid, tb.getAuctionId() + ""));
- quanInfo.setCouponPrice(tb.getZkPrice().subtract(tb.getTkCommFee()));
+ quanInfo.setCouponPrice(MoneyBigDecimalUtil.sub(tg.getZkPrice(), tb.getCouponAmount()));
quanInfo.setCouponStartFee(tb.getCouponStartFee());
quanInfo.setCouponTotalCount(tb.getCouponTotalCount());
tg.setTaoBaoQuanInfo(quanInfo);
@@ -757,14 +773,52 @@
tg.setTaoBaoHongBaoInfo(hongBaoInfo);
+ tg.setMoneyType(1);
+ tg.setSalesType(1);
// 娴嬭瘯浣跨敤
- tg.setMoneyType(Math.random() > 0.5 ? 1 : 2);
- tg.setSalesType(Math.random() > 0.5 ? 1 : 2);
- List<ClientTextStyleVO> labels = new ArrayList<>();
- labels.add(new ClientTextStyleVO("鏍囩娴嬭瘯鍐呭", "#FF0000"));
- tg.setLabels(labels);
+ // tg.setSalesType(Math.random() > 0.5 ? tg.getSalesType() : 3);
+ // if(Constant.IS_TEST)
+ // {
+ // List<ClientTextStyleVO> labels = new ArrayList<>();
+ // labels.add(new ClientTextStyleVO("鏍囩鍐呭", "#F14242"));
+ // labels.add(new ClientTextStyleVO("鏍囩鍐呭", "#00FF00"));
+ // tg.setLabels(labels);
+ // }
+ return loadYuShouInfo(tg, tb);
+ }
- return tg;
+ private static TaoBaoGoodsBriefExtra loadYuShouInfo(TaoBaoGoodsBriefExtra extra, TaoBaoGoodsBrief goods) {
+ if (goods != null && extra != null) {
+ if (isYUShou(goods)) {// 棰勫敭鍟嗗搧
+ // extra.setZkPrice(new BigDecimal(goods.getPresaleDeposit()));
+ // 棰勫敭
+ if (extra.getLabels() == null)
+ extra.setLabels(new ArrayList<>());
+ extra.getLabels().add(new ClientTextStyleVO("棰勫敭", "#FF2B4E"));
+ }
+ }
+ return extra;
+ }
+
+ /**
+ * 鏄惁涓洪鍞晢鍝�
+ *
+ * @param goods
+ * @return
+ */
+ public static boolean isYUShou(TaoBaoGoodsBrief goods) {
+ if (!StringUtil.isNullOrEmpty(goods.getPresaleDeposit())
+ && !StringUtil.isNullOrEmpty(goods.getPresaleStartTime())
+ && !StringUtil.isNullOrEmpty(goods.getPresaleEndTime())) {
+ long startTime = Long.parseLong(goods.getPresaleStartTime());
+ long endTime = Long.parseLong(goods.getPresaleEndTime());
+ long now = System.currentTimeMillis();
+ if (now >= startTime && now < endTime) {
+ return true;
+ }
+ }
+
+ return false;
}
/**
@@ -1007,33 +1061,32 @@
}
tg.setTaoBaoHongBaoInfo(hongBaoInfo);
+ tg.setMoneyType(1);
+ tg.setSalesType(1);
// 娴嬭瘯浣跨敤
- tg.setMoneyType(Math.random() > 0.5 ? 1 : 2);
- tg.setSalesType(Math.random() > 0.5 ? 1 : 2);
- List<ClientTextStyleVO> labels = new ArrayList<>();
- labels.add(new ClientTextStyleVO("鏍囩娴嬭瘯鍐呭", "#FF0000"));
- tg.setLabels(labels);
+ // tg.setMoneyType(Math.random() > 0.5 ? 1 : 2);
+ // tg.setSalesType(Math.random() > 0.5 ? 1 : 2);
+ // tg.setSalesType(Math.random() > 0.5 ? tg.getSalesType() : 3);
+ // List<ClientTextStyleVO> labels = new ArrayList<>();
+ // labels.add(new ClientTextStyleVO("鏍囩鍐呭", "#F14242"));
+ // labels.add(new ClientTextStyleVO("鏍囩鍐呭", "#000000"));
+ // tg.setLabels(labels);
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) {
@@ -1315,6 +1368,41 @@
return taoBaoGoodsBrief;
}
+ public static String getGoodsIdByPhoneShareUrl(String burl) {
+ try {
+ Connection connect = Jsoup.connect(burl);
+ Document document = connect.get();
+ org.jsoup.nodes.Element element = document.getElementsByTag("head").get(0).getElementsByTag("Script")
+ .get(1);
+ String html = element.toString();
+ int index = html.indexOf("var url = ");
+ int endIndex = html.lastIndexOf("'");
+ html = html.substring(index, endIndex);
+ int index2 = html.indexOf("'");
+ html = html.substring(index2 + 1);
+ int indexId = html.indexOf("id=");
+ String id = "";
+ if (html.contains("a.m.taobao.com")) {
+ indexId = html.indexOf("com/i");
+ html = html.substring(indexId);
+ html = html.substring(5, html.indexOf("."));
+ id = html;
+ } else {
+ String reg = "[?|&]{1}[i]{1}[d]{1}[=]{1}\\d+[&]?";
+ Pattern p = Pattern.compile(reg);
+ Matcher matcher = p.matcher(html);
+ if (matcher.find()) {
+ id = matcher.group();
+ }
+ id = id.substring(id.indexOf("=") + 1, id.lastIndexOf("&"));
+ }
+ return id;
+ } catch (Exception e) {
+ LogHelper.error("鏃犳硶瑙f瀽鍒版窐瀹濆晢鍝両D:" + burl);
+ return null;
+ }
+ }
+
/**
* 鑾峰彇鍟嗗搧鐨勭敤鎴峰垎鎴愭瘮渚�
*
@@ -1325,10 +1413,11 @@
* @return
*/
public static String getGoodsHongBaoInfo(TaoBaoGoodsBrief goodsBrief, BigDecimal rate) {
- if (goodsBrief != null && goodsBrief.getMaterialLibType() != null && goodsBrief.getMaterialLibType() == 0)
- return "楼0.00";
- else
- return "楼" + getGoodsHongBaoMoney(goodsBrief, rate).toString();
+ // if (goodsBrief != null && goodsBrief.getMaterialLibType() != null &&
+ // goodsBrief.getMaterialLibType() == 0)
+ // return "楼0.00";
+ // else
+ return "楼" + getGoodsHongBaoMoney(goodsBrief, rate).toString();
}
/**
@@ -1339,9 +1428,10 @@
* @return
*/
public static BigDecimal getGoodsHongBaoMoney(TaoBaoGoodsBrief goodsBrief, BigDecimal rate) {
+ BigDecimal money = null;
if (StringUtil.isNullOrEmpty(goodsBrief.getCouponInfo())
|| goodsBrief.getCouponInfo().trim().equalsIgnoreCase("鏃�")) {
- return MoneyBigDecimalUtil.mul(
+ money = MoneyBigDecimalUtil.mul(
MoneyBigDecimalUtil.mul(MoneyBigDecimalUtil.mul(goodsBrief.getZkPrice(), goodsBrief.getTkRate()),
new BigDecimal("0.01")),
MoneyBigDecimalUtil.div(rate, new BigDecimal(100)));
@@ -1353,16 +1443,17 @@
if (startFee.compareTo(goodsBrief.getZkPrice()) <= 0
&& goodsBrief.getZkPrice().compareTo(couponAccount) > 0) {
BigDecimal finalPrice = goodsBrief.getZkPrice().subtract(couponAccount);
- return MoneyBigDecimalUtil.mul(MoneyBigDecimalUtil
+ money = MoneyBigDecimalUtil.mul(MoneyBigDecimalUtil
.mul(MoneyBigDecimalUtil.mul(finalPrice, goodsBrief.getTkRate()), new BigDecimal("0.01")),
MoneyBigDecimalUtil.div(rate, new BigDecimal(100)));
} else {// 涓嶈兘鐢ㄥ埜
- return MoneyBigDecimalUtil.mul(MoneyBigDecimalUtil.mul(
+ money = MoneyBigDecimalUtil.mul(MoneyBigDecimalUtil.mul(
MoneyBigDecimalUtil.mul(goodsBrief.getZkPrice(), goodsBrief.getTkRate()),
new BigDecimal("0.01")), MoneyBigDecimalUtil.div(rate, new BigDecimal(100)));
}
}
+ return BigDecimalUtil.getWithNoZera(money);
}
// }
@@ -1396,30 +1487,7 @@
*/
public static BigDecimal getShareGoodsHongBaoInfo(TaoBaoGoodsBrief goodsBrief, BigDecimal rate) {
-
- // 璁$畻杩斿埄
- // 鏃犲埜
- if (StringUtil.isNullOrEmpty(goodsBrief.getCouponInfo()) || goodsBrief.getCouponInfo().contains("鏃�")) {
- return goodsBrief.getZkPrice().multiply(goodsBrief.getTkRate()).divide(new BigDecimal(10000)).multiply(rate)
- .setScale(2, BigDecimal.ROUND_DOWN);
-
- } else// 鏈夊埜
- {
- List<BigDecimal> list = TaoBaoCouponUtil.getCouponInfo(goodsBrief.getCouponInfo());
- BigDecimal startFee = list.get(0);
- BigDecimal couponAccount = list.get(1);
- if (startFee.compareTo(goodsBrief.getZkPrice()) <= 0
- && goodsBrief.getZkPrice().compareTo(couponAccount) > 0) {
- BigDecimal finalPrice = goodsBrief.getZkPrice().subtract(couponAccount);
- return finalPrice.multiply(goodsBrief.getTkRate()).divide(new BigDecimal(10000)).multiply(rate)
- .setScale(2, BigDecimal.ROUND_DOWN);
-
- } else {// 涓嶈兘鐢ㄥ埜
- return goodsBrief.getZkPrice().multiply(goodsBrief.getTkRate()).divide(new BigDecimal(10000))
- .multiply(rate).setScale(2, BigDecimal.ROUND_DOWN);
- }
-
- }
+ return getGoodsHongBaoMoney(goodsBrief, rate);
}
/**
@@ -1684,6 +1752,38 @@
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(),
+ 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());
+ taoBaoGoods.setCouponTotalCount(detail.getCouponTotalNum());
+ taoBaoGoods.setPictUrl(detail.getMainPic());
+ taoBaoGoods.setPictUrlWhite(detail.getMainPic());
+ if (taoBaoGoods.getPictUrl() != null && !taoBaoGoods.getPictUrl().startsWith("http"))
+ taoBaoGoods.setPictUrl("https:" + taoBaoGoods.getPictUrl());
+
+ if (taoBaoGoods.getPictUrlWhite() != null && !taoBaoGoods.getPictUrlWhite().startsWith("http"))
+ taoBaoGoods.setPictUrlWhite("https:" + taoBaoGoods.getPictUrlWhite());
+
+ taoBaoGoods.setSellerId(detail.getSellerId());
+ taoBaoGoods.setShopTitle(detail.getShopName());
+ taoBaoGoods.setTitle(detail.getDtitle());
+ taoBaoGoods.setUserType(detail.getShopType());
+ taoBaoGoods.setZkPrice(detail.getOriginalPrice());
+ taoBaoGoods.setTkRate(detail.getCommissionRate());
+ taoBaoGoods.setTkCommFee(new BigDecimal("0"));
+ taoBaoGoods.setState(0);
+ return taoBaoGoods;
+ }
+
/**
* 鑾峰彇娣樺疂鑱旂洘鐨勬巿鏉冮摼鎺�
*
@@ -1714,40 +1814,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;
}
@@ -1770,44 +1898,260 @@
e.printStackTrace();
}
String result = HttpUtil.get(url);
- JSONObject resultJson = JSONObject.fromObject(result);
- JSONObject dataJson = resultJson.optJSONObject("data");
- JSONObject sellerJson = dataJson.optJSONObject("seller");
+
TaoBaoShop shop = new TaoBaoShop();
- shop.setGoodRatePercentage(new BigDecimal(sellerJson.optString("goodRatePercentage").replace("%", "")));
- shop.setId(sellerJson.optLong("userId"));
- JSONArray array = sellerJson.optJSONArray("evaluates");
- for (int i = 0; i < array.size(); i++) {
- JSONObject item = array.optJSONObject(i);
- if ("瀹濊礉鎻忚堪".equalsIgnoreCase(item.optString("title").trim())) {
- shop.setScoreGoods(new BigDecimal(item.optString("score").trim()));
- shop.setScoreGoodsD(new BigDecimal(item.optString("level").trim()));
- } else if ("鍗栧鏈嶅姟".equalsIgnoreCase(item.optString("title").trim())) {
- shop.setScoreSeller(new BigDecimal(item.optString("score").trim()));
- shop.setScoreSellerD(new BigDecimal(item.optString("level").trim()));
- } else if ("鐗╂祦鏈嶅姟".equalsIgnoreCase(item.optString("title").trim())) {
- shop.setScoreLogistics(new BigDecimal(item.optString("score").trim()));
- shop.setScoreLogisticsD(new BigDecimal(item.optString("level").trim()));
+ try {
+ JSONObject resultJson = JSONObject.fromObject(result);
+ JSONObject dataJson = resultJson.optJSONObject("data");
+ JSONObject sellerJson = dataJson.optJSONObject("seller");
+
+ shop.setGoodRatePercentage(new BigDecimal(sellerJson.optString("goodRatePercentage").replace("%", "")));
+
+ LogHelper.test("鍗栧淇℃伅:" + result);
+ shop.setId(sellerJson.optLong("userId"));
+ JSONArray array = sellerJson.optJSONArray("evaluates");
+ for (int i = 0; i < array.size(); i++) {
+ JSONObject item = array.optJSONObject(i);
+ if ("瀹濊礉鎻忚堪".equalsIgnoreCase(item.optString("title").trim())) {
+ shop.setScoreGoods(new BigDecimal(item.optString("score").trim()));
+ shop.setScoreGoodsD(new BigDecimal(item.optString("level").trim()));
+ } else if ("鍗栧鏈嶅姟".equalsIgnoreCase(item.optString("title").trim())) {
+ shop.setScoreSeller(new BigDecimal(item.optString("score").trim()));
+ shop.setScoreSellerD(new BigDecimal(item.optString("level").trim()));
+ } else if ("鐗╂祦鏈嶅姟".equalsIgnoreCase(item.optString("title").trim())) {
+ shop.setScoreLogistics(new BigDecimal(item.optString("score").trim()));
+ shop.setScoreLogisticsD(new BigDecimal(item.optString("level").trim()));
+ }
}
- }
- shop.setSellerNick(sellerJson.optString("sellerNick"));
- shop.setShopIcon("https:" + sellerJson.optString("shopIcon"));
- shop.setShopId(sellerJson.optLong("shopId"));
- shop.setShopName(sellerJson.optString("shopName"));
- if ("B".equalsIgnoreCase(sellerJson.optString("sellerType")))
- shop.setUserType(1);
- else
- shop.setUserType(0);
+ shop.setSellerNick(sellerJson.optString("sellerNick"));
+ shop.setShopIcon("https:" + sellerJson.optString("shopIcon"));
+ shop.setShopId(sellerJson.optLong("shopId"));
+ shop.setShopName(sellerJson.optString("shopName"));
+ if ("B".equalsIgnoreCase(sellerJson.optString("sellerType")))
+ shop.setUserType(1);
+ else
+ shop.setUserType(0);
+
+ shop.setShopLink(TaoBaoUtil.getShopLink(shop.getId()));
+ } catch (Exception e) {
+ // if (1 > 0)
+ // return null;
+ try {
+ TaoBaoGoodsBrief goods = TaoKeApiUtil.getSimpleGoodsInfo(auctionId);
+ shop.setId(goods.getSellerId());
+ shop.setShopName(goods.getShopTitle());
+ shop.setUserType(goods.getUserType());
+ } catch (Exception e1) {
+ shop.setId(1L);
+ shop.setShopName("");
+ shop.setUserType(0);
+ }
+
+ shop.setGoodRatePercentage(new BigDecimal(100));
+ shop.setScoreGoods(new BigDecimal("4.9"));
+ shop.setScoreGoodsD(new BigDecimal("0"));
+ shop.setScoreSeller(new BigDecimal("4.9"));
+ shop.setScoreSellerD(new BigDecimal("0"));
+ shop.setScoreLogistics(new BigDecimal("4.9"));
+ shop.setScoreLogisticsD(new BigDecimal("0"));
+ shop.setSellerNick("");
+ shop.setShopIcon("https:");
+ shop.setShopLink(TaoBaoUtil.getShopLink(shop.getId()));
+ }
return shop;
}
- public static void main(String[] args) {
- String s = channelMap.get("3");
- System.out.println(s);
+ /**
+ * 鏍规嵁鍗栧id鑾峰彇搴楅摵閾炬帴
+ *
+ * @param sellerId
+ * @return
+ */
+ public static String getShopLink(Long sellerId) {
+ return "http://store.taobao.com/shop/view_shop.htm?user_number_id=" + sellerId;
+ }
+ /**
+ * 鏄惁鍙互鍔犲叆娣樼ぜ閲戠殑棰勯�夊晢鍝佸簱
+ *
+ * @param v2
+ * @return
+ */
+ public static boolean canAddToTLJBuyGoods(TaoBaoGoodsBrief goods) {
+ BigDecimal tljMoney = getShareGoodsHongBaoInfo(goods, TaoBaoConstant.OWN_BUY_WITHOUT_FANLI_RATE);
+ // 涓嶈兘灏忎簬1鍧�
+ if (tljMoney.compareTo(new BigDecimal(1)) < 0 || tljMoney.compareTo(new BigDecimal(10)) > 0)
+ return false;
+
+ // 鍒稿悗浠蜂笉鑳藉ぇ浜�150
+ if (getAfterUseCouplePrice(goods).compareTo(new BigDecimal(150)) > 0)
+ return false;
+
+ return true;
+ }
+
+ /**
+ * 鏌ヨ澶╃尗鍟嗗搧鍥剧墖銆佹爣棰�
+ *
+ * @param auctionId
+ * @return
+ */
+ public static TaoBaoGoodsBrief getTmallGoodsInfo(String auctionId) {
+ TaoBaoGoodsBrief taoBaoGoodsBrief = null;
+ try {
+ Connection connect = Jsoup.connect(String.format(TM_PHONE_URL, auctionId));
+ Document document = connect.get();
+ Elements elements = document.getElementsByTag("script");
+ if (elements.size() >= 0) {
+ for (int i = 0; i < elements.size(); i++) {
+ String content = elements.get(i).toString();
+ if (content.contains("var _DATA_Mdskip")) {
+ 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);}";
+ } else {
+ content += ";function getData(){ var json={title:_DATA_Mdskip.item.title,pictUrl:_DATA_Mdskip.item.videos[0].videoThumbnailURL}; return JSON.stringify(json);}";
+ }
+
+ ScriptEngineManager manager = new ScriptEngineManager();
+ ScriptEngine engine = manager.getEngineByName("javascript");
+ engine.eval(content);
+
+ if (engine instanceof Invocable) {
+ Invocable in = (Invocable) engine;
+ JSONObject json = JSONObject.fromObject(in.invokeFunction("getData"));
+ Object title = json.get("title");
+ Object pictUrl = json.get("pictUrl");
+ taoBaoGoodsBrief = new TaoBaoGoodsBrief();
+ taoBaoGoodsBrief.setTitle(title.toString());
+ taoBaoGoodsBrief.setPictUrl(pictUrl.toString());
+ }
+
+ break;
+ }
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return taoBaoGoodsBrief;
+ }
+
+ /**
+ * 鎶栭煶杩斿埄local 鑾峰彇鐪熷疄娣樺疂閾炬帴
+ *
+ * @param url
+ * https://s.click.taobao.com/t?e=m%3D2%26s%
+ * 3DT9DFpHQCT7Rw4vFB6t2Z2ueEDrYVVa64XoO8tOebS+dRAdhuF14FMR8
+ * @return
+ */
+ public static String getRealUrl(String url) {
+ if (StringUtil.isNullOrEmpty(url))
+ return null;
+
+ try {
+ HttpClient client = new HttpClient(new MultiThreadedHttpConnectionManager());
+ client.getHttpConnectionManager().getParams().setConnectionTimeout(10000);
+ client.getParams().setParameter(HttpMethodParams.USER_AGENT,
+ "Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)"); // 璁╂湇鍔″櫒璁や负鏄疘E
+ GetMethod get = new GetMethod(url);
+ get.setFollowRedirects(false); // 绂佹鑷姩閲嶅畾鍚�
+ int iGetResultCode = client.executeMethod(get);
+ String location = get.getResponseHeader("location").getValue(); // 鎵撳嵃鍦板潃
+ GetMethod get2 = new GetMethod(URLDecoder.decode(location.split("tu=")[1]));
+ get2.addRequestHeader("Referer", location);
+ get2.setFollowRedirects(false); // 绂佹鑷姩閲嶅畾鍚�
+ int iGetResultCode2 = client.executeMethod(get2);
+ return get2.getResponseHeader("location").getValue(); // 鐪熷疄鍦板潃
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ return null;
+ }
+
+ /**
+ * 娣樺彛浠よ繃婊�
+ *
+ * @param token
+ * @return
+ */
+ public static String filterTaoToken(String token) {
+ if (StringUtil.isNullOrEmpty(token))
+ return token;
+ if (token.contains("锟�") || token.contains("鈧�")) {
+ String newToken = "";
+ for (int i = 0; i < token.length(); i++) {
+ if (token.charAt(i) == '锟�' || token.charAt(i) == '鈧�') {
+ if (!newToken.contains("("))
+ newToken += "(";
+ else
+ newToken += ")";
+ } else
+ newToken += token.charAt(i) + "";
+ }
+ return newToken;
+ }
+ 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;
+ else
+ return false;
+ }
+
+ /**
+ * 浠庢枃鏈腑鎻愬彇娣樺彛浠�
+ * @Title: getTokenListFromText
+ * @Description:
+ * @param str
+ * @return
+ * List<String> 杩斿洖绫诲瀷
+ * @throws
+ */
+ public static List<String> getTokenListFromText(String str) {
+ String[] marks = new String[] { "鈧�", "楼", "锟�", "鈧�", "\\$", "鈧�", "垄", "鈧�" };
+
+ return getTokenListFromText(str, Arrays.asList(marks));
+ }
+
+ 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, st));
+ }
+ 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