From d40e978df4717d91f72f6e295c58f98524bbd29c Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期三, 08 一月 2020 14:27:28 +0800
Subject: [PATCH] 跳转方式增加小程序
---
fanli/src/main/java/com/yeshi/fanli/util/pinduoduo/PinDuoDuoApiUtil.java | 353 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 331 insertions(+), 22 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..e9ddfc3 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
@@ -5,6 +5,7 @@
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@@ -18,9 +19,14 @@
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.PDDPromotionUrl;
import com.yeshi.fanli.dto.pdd.PDDSearchFilter;
+import com.yeshi.fanli.dto.pdd.PDDShopDetail;
+import com.yeshi.fanli.dto.pdd.PDDShopResult;
import com.yeshi.fanli.entity.pdd.PDDOrder;
+import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.StringUtil;
+import com.yeshi.fanli.util.TimeUtil;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
@@ -28,6 +34,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";
@@ -63,11 +70,15 @@
}
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,25 +98,169 @@
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(), ",") + "]");
+ if (sf.getMerchantType() != null)
+ map.put("merchant_type", sf.getMerchantType() + "");
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");
+ if (root == null) {
+ return null;
+ }
+
JSONArray array = root.optJSONArray("goods_list");
+ if (array == null) {
+ return null;
+ }
+
Type type = new TypeToken<List<PDDGoodsDetail>>() {
}.getType();
-
+
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);
+ }
+
+ public static List<PDDGoodsDetail> listGoodsDetail(List<Long> goodsIds) {
+ PDDSearchFilter filter = new PDDSearchFilter();
+ Long[] ids = new Long[goodsIds.size()];
+ goodsIds.toArray(ids);
+ filter.setGoodsIdList(ids);
+ PDDGoodsResult result = searchGoods(filter);
+ if (result != null)
+ return result.getGoodsList();
+ return null;
+ }
+
+ /**
+ * 杩愯惀棰戦亾鍟嗗搧鏌ヨ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");
+ if (root == null) {
+ return null;
+ }
+ JSONArray array = root.optJSONArray("list");
+ if (array == null) {
+ return null;
+ }
+
+ 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 getThemes(Integer page, Integer pageSize) {
+ Map<String, String> map = new HashMap<>();
+ map.put("type", "pdd.ddk.theme.list.get");
+ map.put("page", page + "");
+ map.put("page_size", pageSize + "");
+ String result = baseRequest(map);
+
+ JSONObject json = JSONObject.fromObject(result);
+ JSONObject root = json.optJSONObject("theme_list_get_response");
+ JSONArray array = root.optJSONArray("theme_list");
+ for (int i = 0; i < array.size(); i++) {
+ System.out.println(array.optJSONObject(i).optString("id"));
+ System.out.println(array.optJSONObject(i).optString("name"));
+ System.out.println(array.optJSONObject(i).optString("image_url"));
+ System.out.println(array.optJSONObject(i).optString("goods_num"));
+ System.out.println("-------------------------------------------");
+ }
+
+ System.out.println(root.optLong("total"));
+ }
+
+ 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");
+ if (root == null) {
+ return null;
+ }
+ JSONArray array = root.optJSONArray("list");
+ if (array == null) {
+ return null;
+ }
+
+ 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);
}
@@ -117,24 +272,83 @@
* @param customParams
* @return
*/
- public static String convert(Long goodsId, String pid, String customParams) {
+ public static PDDPromotionUrl 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", 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());
- map.put("custom_parameters", customParams);
+ if (!StringUtil.isNullOrEmpty(customParams)) {
+ map.put("custom_parameters", customParams);
+ }
String result = baseRequest(map);
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");
+ if (json == null) {
+ return null;
+ }
+ JSONArray resultArray = json.optJSONArray("goods_promotion_url_list");
+ if (resultArray != null && resultArray.size() > 0) {
+ Type type = new TypeToken<PDDPromotionUrl>() {
+ }.getType();
+ Gson gson = new GsonBuilder().disableHtmlEscaping().create();
+ return gson.fromJson(resultArray.optJSONObject(0).toString(), type);
+ }
+ return null;
+ }
+
+ /**
+ * 寰俊灏忕▼搴忚浆閾� @Title: convertWXMP @Description: @param goodsId @param
+ * pid @param customParams @return PDDPromotionUrl 杩斿洖绫诲瀷 @throws
+ */
+ public static String convertWXMP(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", pid);
+ map.put("multi_group", "true");
+ map.put("generate_we_app", "true");
+
+ JSONArray array = new JSONArray();
+ array.add(goodsId);
+ map.put("goods_id_list", array.toString());
+ if (!StringUtil.isNullOrEmpty(customParams)) {
+ map.put("custom_parameters", customParams);
+ }
+
+ String result = baseRequest(map);
+ JSONObject root = JSONObject.fromObject(result);
+ JSONObject json = root.optJSONObject("goods_promotion_url_generate_response");
+ if (json == null) {
+ return null;
+ }
+ JSONArray resultArray = json.optJSONArray("goods_promotion_url_list");
+ if (resultArray != null && resultArray.size() > 0) {
+ JSONObject weApp = resultArray.optJSONObject(0).optJSONObject("we_app_info");
+ if (weApp != null)
+ return weApp.optString("page_path");
+ }
+ return null;
+ }
+
+ /**
+ * 鍟嗗搧杞摼
+ *
+ * @param goodsId
+ * @param pid
+ * @param customParams
+ * @return
+ */
+ public static String getPromotionUrl(Long goodsId, String pid, String customParams) {
+ PDDPromotionUrl promotion = convert(goodsId, pid, customParams);
+ if (promotion != null) {
+ return promotion.getShortUrl();
+ }
return null;
}
@@ -162,7 +376,7 @@
* 涓庡紑濮嬫椂闂翠笉寰楀ぇ浜�24灏忔椂
* @return
*/
- public static PDDOrderResult getOrders(int page, int pageSize, long startTime, long endTime) {
+ public static PDDOrderResult getOrdersList(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", startTime / 1000 + "");
@@ -170,6 +384,7 @@
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) {
@@ -179,6 +394,20 @@
}.getType();
List<PDDOrder> orderList = new Gson().fromJson(array.toString(), type);
return new PDDOrderResult(totalCount, orderList);
+ }
+ return null;
+ }
+
+ public static PDDOrder getOrderDetail(String orderSn) {
+ Map<String, String> map = new HashMap<>();
+ map.put("type", "pdd.ddk.order.detail.get");
+ map.put("order_sn", orderSn);
+ String result = baseRequest(map);
+ System.out.println(result);
+ JSONObject json = JSONObject.fromObject(result);
+ JSONObject root = json.optJSONObject("order_detail_response");
+ if (root != null) {
+ return new Gson().fromJson(root.toString(), PDDOrder.class);
}
return null;
}
@@ -197,13 +426,93 @@
String result = baseRequest(map);
JSONObject resultJson = JSONObject.fromObject(result);
JSONObject root = resultJson.optJSONObject("goods_detail_response");
- array = root.optJSONArray("goods_details");
+ if (root == null) {
+ return null;
+ }
+
+ JSONArray resultArray = root.optJSONArray("goods_details");
+ if (resultArray == null) {
+ return null;
+ }
+
Type type = new TypeToken<List<PDDGoodsDetail>>() {
}.getType();
- List<PDDGoodsDetail> goodsList = new Gson().fromJson(array.toString(), type);
+ List<PDDGoodsDetail> goodsList = new Gson().fromJson(resultArray.toString(), type);
if (goodsList != null && goodsList.size() > 0)
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;
+ }
+
+ public static Date getSystemTime() {
+ try {
+ Map<String, String> map = new HashMap<>();
+ map.put("type", "pdd.time.get");
+ String result = baseRequest(map);
+ String time = JSONObject.fromObject(result).optJSONObject("time_get_response").optString("time");
+ return new Date(TimeUtil.convertToTimeTemp(time, "yyyy-MM-dd HH:mm:ss"));
+ } catch (Exception e) {
+ }
+ return null;
+ }
+
+ /**
+ * 鑾峰彇鍟嗗搧璇︽儏
+ *
+ * @param goodsId
+ */
+ public static PDDShopResult getShopList(Integer page, Long catId) {
+ JSONArray arrayType = new JSONArray();
+ arrayType.add(3);
+
+ Map<String, String> map = new HashMap<>();
+ map.put("type", "pdd.ddk.merchant.list.get");
+ if (catId != null)
+ map.put("cat_id", catId + "");
+ if (page != null)
+ map.put("page_number", page + "");
+
+ if (page != null)
+ map.put("page_number", page + "");
+
+ map.put("merchant_type_list", arrayType.toString());
+
+ String result = baseRequest(map);
+ JSONObject resultJson = JSONObject.fromObject(result);
+ JSONObject root = resultJson.optJSONObject("merchant_list_response");
+ if (root != null) {
+ int totalCount = root.optInt("total");
+
+ JSONArray array = root.optJSONArray("mall_search_info_vo_list");
+ Type type = new TypeToken<List<PDDShopDetail>>() {
+ }.getType();
+ List<PDDShopDetail> listShop = new Gson().fromJson(array.toString(), type);
+ return new PDDShopResult(totalCount, listShop);
+ }
+ return null;
+ }
}
--
Gitblit v1.8.0