From aba5dee7a341ecb60fe02f088684aa982ac037f9 Mon Sep 17 00:00:00 2001
From: yujian <yujian@123.com>
Date: 星期二, 11 六月 2019 09:10:23 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 fanli/src/main/java/com/yeshi/fanli/util/pinduoduo/PinDuoDuoApiUtil.java |  102 ++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 88 insertions(+), 14 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/util/pinduoduo/PinDuoDuoApiUtil.java b/fanli/src/main/java/com/yeshi/fanli/util/pinduoduo/PinDuoDuoApiUtil.java
index 8d3c57d..27d076a 100644
--- a/fanli/src/main/java/com/yeshi/fanli/util/pinduoduo/PinDuoDuoApiUtil.java
+++ b/fanli/src/main/java/com/yeshi/fanli/util/pinduoduo/PinDuoDuoApiUtil.java
@@ -1,6 +1,7 @@
 package com.yeshi.fanli.util.pinduoduo;
 
 import java.io.UnsupportedEncodingException;
+import java.lang.reflect.Type;
 import java.net.URLEncoder;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -11,11 +12,22 @@
 
 import org.yeshi.utils.HttpUtil;
 
+import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
+import com.yeshi.fanli.dto.pdd.PDDGoodsDetail;
+import com.yeshi.fanli.dto.pdd.PDDGoodsResult;
+import com.yeshi.fanli.dto.pdd.PDDOrderResult;
+import com.yeshi.fanli.dto.pdd.PDDSearchFilter;
+import com.yeshi.fanli.entity.pdd.PDDOrder;
 import com.yeshi.fanli.util.StringUtil;
 
 import net.sf.json.JSONArray;
+import net.sf.json.JSONObject;
 
 public class PinDuoDuoApiUtil {
+	public final static String PID_FANLI = "8590899_72067894";
+	public final static String PID_SHARE = "8590899_72067895";
+
 	private final static String CLIENT_ID = "9f6ee5ebd3b94c2080c4d51c2427e9fa";
 	private final static String CLIENT_SECRET = "95e1f1904385664bf4b87d4b34de12f9f31c505d";
 
@@ -55,42 +67,96 @@
 		return result;
 	}
 
-	public static void searchGoods(String key) {
+	public static PDDGoodsResult searchGoods(PDDSearchFilter sf) {
 		Map<String, String> map = new HashMap<>();
 		map.put("type", "pdd.ddk.goods.search");
-		map.put("keyword", key);
+		if (sf.getOptId() != null)
+			map.put("opt_id", sf.getOptId() + "");
+		if (sf.getPage() != null)
+			map.put("page", sf.getPage() + "");
+		if (sf.getPageSize() != null)
+			map.put("page_size", sf.getPageSize() + "");
+		if (sf.getSortType() != null)
+			map.put("sort_type", sf.getSortType() + "");
+		if (sf.getHasCoupon() != null)
+			map.put("with_coupon", sf.getHasCoupon() + "");
+		if (sf.getCatId() != null)
+			map.put("cat_id", sf.getCatId() + "");
+		if (sf.getKw() != null)
+			map.put("keyword", sf.getKw());
+		map.put("pid", PID_FANLI);
 		String result = baseRequest(map);
-		System.out.println(result);
+		JSONObject json = JSONObject.fromObject(result);
+		JSONObject root = json.optJSONObject("goods_search_response");
+		JSONArray array = root.optJSONArray("goods_list");
+		Type type = new TypeToken<List<PDDGoodsDetail>>() {
+		}.getType();
+		List<PDDGoodsDetail> goodsList = new Gson().fromJson(array.toString(), type);
+		int totalCount = json.optInt("total_count");
+		return new PDDGoodsResult(totalCount, goodsList);
 	}
 
-	public static void convert(Long goodsId) {
+	/**
+	 * 鍟嗗搧杞摼
+	 * 
+	 * @param goodsId
+	 * @param pid
+	 * @param customParams
+	 * @return
+	 */
+	public static String convert(Long goodsId, String pid, String customParams) {
 		Map<String, String> map = new HashMap<>();
 		map.put("type", "pdd.ddk.goods.promotion.url.generate");
-		map.put("p_id", "8590899_61877633");
+		map.put("p_id", pid);
+		map.put("multi_group", "true");
+		map.put("generate_weapp_webview", "true");
+		map.put("generate_weiboapp_webview", "true");
 		JSONArray array = new JSONArray();
 		array.add(goodsId);
 		map.put("goods_id_list", array.toString());
-		map.put("custom_parameters", "437032");
+		map.put("custom_parameters", customParams);
 
 		String result = baseRequest(map);
-		System.out.println(result);
+		JSONObject root = JSONObject.fromObject(result);
+		JSONObject json = root.optJSONObject("goods_promotion_url_generate_response");
+		array = json.optJSONArray("goods_promotion_url_list");
+		if (array != null && array.size() > 0)
+			return array.optJSONObject(0).optString("short_url");
+		return null;
 	}
 
 	public static void createPid() {
 		Map<String, String> map = new HashMap<>();
 		map.put("type", "pdd.ddk.goods.pid.generate");
-		map.put("number", "1");
+		map.put("number", "2");
+		JSONArray array = new JSONArray();
+		array.add("杩斿埄PID");
+		array.add("鍒嗕韩PID");
+		map.put("p_id_name_list", array.toString());
+
 		String result = baseRequest(map);
 		System.out.println(result);
 	}
 
-	public static void getOrders() {
+	public static PDDOrderResult getOrders(int page, int pageSize, long startTime, long endTime) {
 		Map<String, String> map = new HashMap<>();
 		map.put("type", "pdd.ddk.order.list.increment.get");
-		map.put("start_update_time", System.currentTimeMillis() / 1000 - 60 * 60 + "");
-		map.put("end_update_time", System.currentTimeMillis() / 1000 + "");
+		map.put("start_update_time", startTime / 1000 + "");
+		map.put("end_update_time", endTime / 1000 + "");
+		map.put("page", page + "");
+		map.put("page_size", pageSize + "");
 		String result = baseRequest(map);
-		System.out.println(result);
+		JSONObject json = JSONObject.fromObject(result);
+		JSONObject root = json.optJSONObject("order_list_get_response");
+		if (root != null) {
+			int totalCount = root.optInt("total_count");
+			JSONArray array = root.optJSONArray("order_list");
+			Type type = new TypeToken<List<PDDOrder>>() {
+			}.getType();
+			List<PDDOrder> orderList = new Gson().fromJson(array.toString(), type);
+			return new PDDOrderResult(totalCount, orderList);
+		}
+		return null;
 	}
 
 	/**
@@ -98,14 +164,22 @@
 	 * 
 	 * @param goodsId
 	 */
-	public static void getGoodsDetail(Long goodsId) {
+	public static PDDGoodsDetail getGoodsDetail(Long goodsId) {
 		JSONArray array = new JSONArray();
 		array.add(goodsId);
 		Map<String, String> map = new HashMap<>();
 		map.put("type", "pdd.ddk.goods.detail");
 		map.put("goods_id_list", array.toString());
 		String result = baseRequest(map);
-		System.out.println(result);
+		JSONObject resultJson = JSONObject.fromObject(result);
+		JSONObject root = resultJson.optJSONObject("goods_detail_response");
+		array = root.optJSONArray("goods_details");
+		Type type = new TypeToken<List<PDDGoodsDetail>>() {
+		}.getType();
+		List<PDDGoodsDetail> goodsList = new Gson().fromJson(array.toString(), type);
+		if (goodsList != null && goodsList.size() > 0)
+			return goodsList.get(0);
+		return null;
 	}
 
 }

--
Gitblit v1.8.0