From 3eb64b02a585e6d385d09cd23e70e337b3ed4319 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期二, 30 六月 2020 14:39:44 +0800
Subject: [PATCH] RocketMQ消息改造
---
fanli/src/main/java/com/yeshi/fanli/util/pinduoduo/PinDuoDuoApiUtil.java | 134 +++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 129 insertions(+), 5 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 c15b551..e132364 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
@@ -19,7 +19,10 @@
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;
@@ -77,6 +80,7 @@
* @return
*/
public static PDDGoodsResult searchGoods(PDDSearchFilter sf) {
+ Gson gson = new GsonBuilder().disableHtmlEscaping().create();
Map<String, String> map = new HashMap<>();
map.put("type", "pdd.ddk.goods.search");
if (sf.getOptId() != null)
@@ -97,7 +101,13 @@
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() + "");
+
+ if (sf.getRangeList() != null && sf.getRangeList().size() > 0) {
+ map.put("range_list",gson.toJson(sf.getRangeList()).toString());
+ }
+
map.put("pid", PID_FANLI);
String result = baseRequest(map);
JSONObject json = JSONObject.fromObject(result);
@@ -114,10 +124,20 @@
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_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;
}
/**
@@ -257,12 +277,13 @@
* @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");
JSONArray array = new JSONArray();
array.add(goodsId);
@@ -278,8 +299,61 @@
return null;
}
JSONArray resultArray = json.optJSONArray("goods_promotion_url_list");
- if (resultArray != null && resultArray.size() > 0)
- return resultArray.optJSONObject(0).optString("short_url");
+ 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;
}
@@ -315,6 +389,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) {
@@ -324,6 +399,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;
}
@@ -396,4 +485,39 @@
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