From 0cc3b905e5945d1b4b02ee5f91a615bcfd8f08d6 Mon Sep 17 00:00:00 2001 From: yujian <yujian@123.com> Date: 星期四, 25 七月 2019 11:44:10 +0800 Subject: [PATCH] 京东兼容 --- fanli/src/main/java/com/yeshi/fanli/util/pinduoduo/PinDuoDuoApiUtil.java | 46 ++++++++++++++++++++++++++++++++++------------ 1 files changed, 34 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..2f1a8ec 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 @@ -63,9 +63,7 @@ } if (url.endsWith("&")) url = url.substring(0, url.length() - 1); - - String result = HttpUtil.post(url); - return result; + return HttpUtil.postSimple(url); } public static PDDGoodsResult searchGoods(PDDSearchFilter sf) { @@ -87,15 +85,13 @@ 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(), ",") + "]"); + + System.out.println(sf.getGoodsIdList().toString()); + 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,7 +101,7 @@ 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); } @@ -123,7 +119,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 +201,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