From e068c9acf06cff7673fadfca686128f6d6d66e20 Mon Sep 17 00:00:00 2001
From: yujian <yujian@123.com>
Date: 星期一, 12 八月 2019 11:12:57 +0800
Subject: [PATCH] Merge branch 'div' of ssh://193.112.35.168:29418/fanli-server into div

---
 fanli/src/main/java/com/yeshi/fanli/util/pinduoduo/PinDuoDuoUtil.java |   72 +++++++++++++++++++++++++----------
 1 files changed, 51 insertions(+), 21 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/util/pinduoduo/PinDuoDuoUtil.java b/fanli/src/main/java/com/yeshi/fanli/util/pinduoduo/PinDuoDuoUtil.java
index 6a44fe1..55807c4 100644
--- a/fanli/src/main/java/com/yeshi/fanli/util/pinduoduo/PinDuoDuoUtil.java
+++ b/fanli/src/main/java/com/yeshi/fanli/util/pinduoduo/PinDuoDuoUtil.java
@@ -1,5 +1,9 @@
 package com.yeshi.fanli.util.pinduoduo;
 
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
 import java.io.UnsupportedEncodingException;
 import java.math.BigDecimal;
 import java.net.URLEncoder;
@@ -9,6 +13,7 @@
 import javax.script.Invocable;
 import javax.script.ScriptEngine;
 import javax.script.ScriptEngineManager;
+import javax.script.ScriptException;
 
 import org.apache.commons.httpclient.HttpClient;
 import org.apache.commons.httpclient.methods.PostMethod;
@@ -24,6 +29,7 @@
 import com.yeshi.fanli.log.LogHelper;
 import com.yeshi.fanli.util.MoneyBigDecimalUtil;
 import com.yeshi.fanli.util.StringUtil;
+import com.yeshi.fanli.util.jd.JDUtil;
 
 import net.sf.json.JSONArray;
 import net.sf.json.JSONObject;
@@ -145,7 +151,7 @@
 		try {
 			client.executeMethod(pm);
 			String result = pm.getResponseBodyAsString();
-			LogHelper.test("鎷煎澶氱寽浣犲枩娆�:"+result);
+			LogHelper.test("鎷煎澶氱寽浣犲枩娆�:" + result);
 			JSONObject json = JSONObject.fromObject(result);
 			JSONArray array = json.optJSONArray("data");
 			if (array != null) {
@@ -348,8 +354,7 @@
 		}
 		return null;
 	}
-	
-	
+
 	/**
 	 * 澶氬杩涘疂鐖彇鏁版嵁-鍝佺墝濂借揣
 	 * 
@@ -359,8 +364,7 @@
 	public static PDDGoodsResult getTodaySaleGoods() {
 		JSONObject params = new JSONObject();
 		params.put("type", 1);
-		params.put("sortType",3);
-		
+		params.put("sortType", 3);
 
 		HttpClient client = new HttpClient();
 		PostMethod pm = new PostMethod("https://jinbao.pinduoduo.com/network/api/common/queryTopGoodsList");
@@ -406,7 +410,6 @@
 		return goodsResult;
 	}
 
-
 	private static PDDGoodsDetail parseTodaySaleGoods(JSONObject json) {
 		PDDGoodsDetail goods = new PDDGoodsDetail();
 		goods.setMallName(json.optString("mallName"));
@@ -419,7 +422,7 @@
 		if (json.optString("mallId") != null) {
 			goods.setMallId(json.getLong("mallId"));
 		}
-		
+
 		if (json.optString("goodsImageUrl") != null) {
 			goods.setGoodsImageUrl(json.optString("goodsImageUrl"));
 		}
@@ -431,7 +434,7 @@
 		if (json.optString("minGroupPrice") != null) {
 			goods.setMinGroupPrice(json.getLong("minGroupPrice"));
 		}
-		
+
 		if (json.optString("minNormalPrice") != null) {
 			goods.setMinNormalPrice(json.getLong("minNormalPrice"));
 		}
@@ -477,23 +480,50 @@
 
 		return goods;
 	}
-	
-	public static String getPDDGoodsId(String url) {
+
+	public static String getJDGoodsJS() {
+		InputStream input = JDUtil.class.getClassLoader().getResourceAsStream("pddGoods.js");
+		StringBuilder sb = new StringBuilder();
+		String line;
+		BufferedReader br = new BufferedReader(new InputStreamReader(input));
 		try {
-			if (url.startsWith("https://mobile.yangkeduo.com/goods.html?")
-					|| url.startsWith("http://mobile.yangkeduo.com/goods.html?")||url.contains("yangkeduo.com/duo_coupon_landing.html?")) {
-				String preUrl = url.substring(url.indexOf("?") + 1, url.length());
-				String[] sts = preUrl.split("&");
-				for (String st : sts) {
-					if (st.startsWith("goods_id=")) {
-						return st.split("=")[1].trim();
-					}
-				}
+			while ((line = br.readLine()) != null) {
+				sb.append(line);
+			}
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+		return sb.toString();
+	}
+
+	static String jdGoodsJs = null;
+	static ScriptEngine engine = null;
+	static {
+		if (jdGoodsJs == null)
+			jdGoodsJs = getJDGoodsJS();
+		ScriptEngineManager manager = new ScriptEngineManager();
+		engine = manager.getEngineByName("javascript");
+		try {
+			engine.eval(jdGoodsJs);
+		} catch (ScriptException e) {
+			e.printStackTrace();
+		}
+
+	}
+
+	public static String getPDDGoodsId(String url) {
+
+		try {
+			if (engine instanceof Invocable) {
+				Invocable in = (Invocable) engine;
+				String goodsId = in.invokeFunction("getGoodsId", url).toString();
+				if (!StringUtil.isNullOrEmpty(goodsId))
+					return goodsId.trim();
 			}
 		} catch (Exception e) {
+			e.printStackTrace();
 		}
 		return null;
 	}
-	
-	
+
 }

--
Gitblit v1.8.0