From dadacf7c1065876248bec86cf17c06ca4be1b97c Mon Sep 17 00:00:00 2001 From: yujian <yujian@123.com> Date: 星期二, 30 七月 2019 14:55:17 +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/PinDuoDuoApiUtil.java | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 100 insertions(+), 2 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 2f1a8ec..9be6d77 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; @@ -28,6 +29,7 @@ public class PinDuoDuoApiUtil { public final static String PID_FANLI = "8590899_72067894"; public final static String PID_SHARE = "8590899_72067895"; + public final static String PID_COUPON = "8590899_102657575"; private final static String CLIENT_ID = "9f6ee5ebd3b94c2080c4d51c2427e9fa"; private final static String CLIENT_SECRET = "95e1f1904385664bf4b87d4b34de12f9f31c505d"; @@ -66,6 +68,11 @@ 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"); @@ -88,7 +95,6 @@ if (sf.getGoodsIdList() != null) map.put("goods_id_list", "[" + StringUtil.concat(sf.getGoodsIdList(), ",") + "]"); - System.out.println(sf.getGoodsIdList().toString()); map.put("pid", PID_FANLI); String result = baseRequest(map); @@ -104,6 +110,96 @@ 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-1) * Constant.PAGE_SIZE) +""); + 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"); + int totalCount = 400; // 榛樿璁剧疆鎴�400 + return new PDDGoodsResult(totalCount, goodsList); + } + /** * 鍟嗗搧杞摼 @@ -123,7 +219,9 @@ JSONArray array = new JSONArray(); array.add(goodsId); map.put("goods_id_list", array.toString()); - map.put("custom_parameters", customParams); + if (!StringUtil.isNullOrEmpty(customParams)) { + map.put("custom_parameters", customParams); + } String result = baseRequest(map); JSONObject root = JSONObject.fromObject(result); -- Gitblit v1.8.0