From cdd852f8e8eff7eb2e8f7c3fceaa955b9fc3f9d3 Mon Sep 17 00:00:00 2001
From: yujian <yujian@123.com>
Date: 星期一, 29 七月 2019 10:46:32 +0800
Subject: [PATCH] 订单商品类型处理

---
 fanli/src/main/java/com/yeshi/fanli/util/pinduoduo/PinDuoDuoApiUtil.java |  140 ++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 128 insertions(+), 12 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 f5e9516..d8ce7d7 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
@@ -20,6 +20,7 @@
 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.Constant;
 import com.yeshi.fanli.util.StringUtil;
 
 import net.sf.json.JSONArray;
@@ -63,11 +64,14 @@
 		}
 		if (url.endsWith("&"))
 			url = url.substring(0, url.length() - 1);
-
-		String result = HttpUtil.post(url);
-		return result;
+		return HttpUtil.postSimple(url);
 	}
 
+	/**
+	 * 澶氬杩涘疂鍟嗗搧鏌ヨ
+	 * @param sf
+	 * @return
+	 */
 	public static PDDGoodsResult searchGoods(PDDSearchFilter sf) {
 		Map<String, String> map = new HashMap<>();
 		map.put("type", "pdd.ddk.goods.search");
@@ -87,15 +91,12 @@
 			map.put("cat_id", sf.getCatId() + "");
 		if (sf.getKw() != null)
 			map.put("keyword", sf.getKw());
+		if (sf.getGoodsIdList() != null)
+			map.put("goods_id_list", "[" + StringUtil.concat(sf.getGoodsIdList(), ",") + "]");
+		
+		
 		map.put("pid", PID_FANLI);
 		String result = baseRequest(map);
-		
-		try {
-			result = new String(result.getBytes("GBK"),"UTF-8");
-//			result = new String(result.getBytes("GBK"),"ISO-8859-1");
-		} catch (UnsupportedEncodingException e) {
-			e.printStackTrace();
-		}
 		
 		JSONObject json = JSONObject.fromObject(result);
 		JSONObject root = json.optJSONObject("goods_search_response");
@@ -105,9 +106,98 @@
 		
 		Gson gson = new GsonBuilder().disableHtmlEscaping().create();
 		List<PDDGoodsDetail> goodsList = gson.fromJson(array.toString(), type);
-		int totalCount = json.optInt("total_count");
+		int totalCount = root.optInt("total_count");
 		return new PDDGoodsResult(totalCount, goodsList);
 	}
+	
+	
+	/**
+	 *  杩愯惀棰戦亾鍟嗗搧鏌ヨAPI
+	 * @param page
+	 * @param pageSize
+	 * @param channelType  棰戦亾绫诲瀷锛�0, "1.9鍖呴偖", 1, "浠婃棩鐖嗘", 2, "鍝佺墝娓呬粨", 闈炲繀濉� ,榛樿鏄�1
+	 * @return
+	 */
+	public static PDDGoodsResult searchByChannelType(Integer page, Integer pageSize, String channelType) {
+		Map<String, String> map = new HashMap<>();
+		map.put("type", "pdd.ddk.goods.recommend.get");
+		map.put("offset", (page == null?0:page) + "");
+		map.put("offset", (pageSize == null?Constant.PAGE_SIZE:pageSize) + "");
+		
+		if (channelType != null)
+			map.put("channel_type", channelType);
+	
+		map.put("pid", PID_FANLI);
+		String result = baseRequest(map);
+		
+		JSONObject json = JSONObject.fromObject(result);
+		JSONObject root = json.optJSONObject("goods_basic_detail_response");
+		JSONArray array = root.optJSONArray("list");
+		Type type = new TypeToken<List<PDDGoodsDetail>>() {
+		}.getType();
+		
+		Gson gson = new GsonBuilder().disableHtmlEscaping().create();
+		List<PDDGoodsDetail> goodsList = gson.fromJson(array.toString(), type);
+		int totalCount = root.optInt("total");
+		return new PDDGoodsResult(totalCount, goodsList);
+	}
+	
+	public static void getGoodsClass() {
+		Map<String, String> map = new HashMap<>();
+		map.put("type", "pdd.goods.cats.get");
+		map.put("parent_cat_id", "0");
+		String result = baseRequest(map);
+		
+		JSONObject json = JSONObject.fromObject(result);
+		JSONObject root = json.optJSONObject("goods_cats_get_response");
+		JSONArray array = root.optJSONArray("goods_cats_list");
+	}
+	
+	
+	public static void getGoodsOpt() {
+		Map<String, String> map = new HashMap<>();
+		map.put("type", "pdd.goods.opt.get");
+		map.put("parent_opt_id", "0");
+		String result = baseRequest(map);
+		
+		JSONObject json = JSONObject.fromObject(result);
+		JSONObject root = json.optJSONObject("goods_opt_get_response");
+		JSONArray array = root.optJSONArray("goods_opt_list");
+	}
+	
+	
+	/**
+	 * 澶氬瀹㈣幏鍙栫垎娆炬帓琛屽晢鍝佹帴鍙�
+	 * @param pid  鎺ㄥ箍浣峣d    (闈炲繀濉�)
+	 * @param page 浠庡灏戜綅缃紑濮嬭姹傦紱榛樿鍊� 锛� 0     (闈炲繀濉�)
+	 * @param pageSize 璇锋眰鏁伴噺锛涢粯璁ゅ�� 锛�20    (闈炲繀濉�)
+	 * @param sortType 1-瀹炴椂鐑攢姒滐紱2-瀹炴椂鏀剁泭姒�    (闈炲繀濉�)
+	 * @return
+	 */
+	public static PDDGoodsResult getTopList(String pid, Integer page, Integer pageSize, Integer sortType) {
+		Map<String, String> map = new HashMap<>();
+		map.put("type", "pdd.ddk.top.goods.list.query");
+		map.put("offset", (page == null? 0: page) +"");
+		map.put("limit", (pageSize == null? Constant.PAGE_SIZE : pageSize) +"");
+		
+		if (!StringUtil.isNullOrEmpty(pid))
+			map.put("p_id", pid + "");
+		
+		if (sortType != null)
+			map.put("sort_type", sortType + "");
+	
+		String result = baseRequest(map);
+		JSONObject json = JSONObject.fromObject(result);
+		JSONObject root = json.optJSONObject("top_goods_list_get_response");
+		JSONArray array = root.optJSONArray("list");
+		Type type = new TypeToken<List<PDDGoodsDetail>>() {}.getType();
+		
+		Gson gson = new GsonBuilder().disableHtmlEscaping().create();
+		List<PDDGoodsDetail> goodsList = gson.fromJson(array.toString(), type);
+		int totalCount = root.optInt("total");
+		return new PDDGoodsResult(totalCount, goodsList);
+	}
+
 
 	/**
 	 * 鍟嗗搧杞摼
@@ -123,7 +213,7 @@
 		map.put("p_id", pid);
 		map.put("multi_group", "true");
 		map.put("generate_weapp_webview", "true");
-		map.put("generate_weiboapp_webview", "true");
+//		map.put("generate_weiboapp_webview", "true");
 		JSONArray array = new JSONArray();
 		array.add(goodsId);
 		map.put("goods_id_list", array.toString());
@@ -205,5 +295,31 @@
 			return goodsList.get(0);
 		return null;
 	}
+	
+	
+	/**
+	 * 鑾峰彇鍟嗗搧璇︽儏
+	 * 
+	 * @param goodsId
+	 */
+	public static String createGenerate(Long goodsId) {
+		JSONArray array = new JSONArray();
+		array.add(goodsId);
+		Map<String, String> map = new HashMap<>();
+		map.put("type", "pdd.ddk.phrase.generate");
+		map.put("goods_id_list", array.toString());
+		map.put("p_id", PID_FANLI);
+		String result = baseRequest(map);
+		JSONObject resultJson = JSONObject.fromObject(result);
+		System.out.println(result);
+		JSONObject root = resultJson.optJSONObject("ddk_phrase_generate_response");
+		if (root != null) {
+			array = root.optJSONArray("promotion_phrase_list");
+			JSONObject phraseObject = JSONObject.fromObject( array.get(0));
+			return phraseObject.optString("phrase");
+		}
+		
+		return null;
+	}
 
 }

--
Gitblit v1.8.0