From a5bc9c4e52f98032b287a42fd243c2ffcb7d58f6 Mon Sep 17 00:00:00 2001
From: yujian <yujian@163.com>
Date: 星期一, 13 四月 2020 09:52:16 +0800
Subject: [PATCH] 消息
---
fanli/src/main/java/com/yeshi/fanli/util/dataoke/DaTaoKeApiUtil.java | 177 ++++++++++++++++++++++++++++++++++++++++++++--------------
1 files changed, 133 insertions(+), 44 deletions(-)
diff --git a/fanli/src/main/java/com/yeshi/fanli/util/dataoke/DaTaoKeApiUtil.java b/fanli/src/main/java/com/yeshi/fanli/util/dataoke/DaTaoKeApiUtil.java
index 08b28b1..bc57941 100644
--- a/fanli/src/main/java/com/yeshi/fanli/util/dataoke/DaTaoKeApiUtil.java
+++ b/fanli/src/main/java/com/yeshi/fanli/util/dataoke/DaTaoKeApiUtil.java
@@ -26,12 +26,10 @@
import com.google.gson.FieldAttributes;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
-import com.yeshi.fanli.dto.dataoke.DaTaoKeApiResult;
import com.yeshi.fanli.dto.dataoke.DaTaoKeGoodsResult;
import com.yeshi.fanli.dto.taobao.TaoBaoShopDTO;
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
import com.yeshi.fanli.entity.taobao.TaoKeAppInfo;
-import com.yeshi.fanli.entity.taobao.dataoke.DaTaoKeDetail;
import com.yeshi.fanli.entity.taobao.dataoke.DaTaoKeDetailV2;
import com.yeshi.fanli.util.MoneyBigDecimalUtil;
import com.yeshi.fanli.util.StringUtil;
@@ -115,34 +113,7 @@
return result;
}
- public static DaTaoKeApiResult goodsList(int page) {
- List<DaTaoKeDetail> list = new ArrayList<>();
- String url = String.format("http://api.dataoke.com/index.php?r=Port/index&type=total&appkey=%s&v=2&page=%s",
- Math.random() > 0.5 ? API_KEY : API_KEY_2, page + "");
- String result = request(url);
-
- JSONObject resultJson = JSONObject.fromObject(result);
- System.out.println(resultJson);
- JSONArray array = resultJson.optJSONArray("result");
- for (int i = 0; i < array.size(); i++) {
- list.add(gson.fromJson(array.optJSONObject(i).toString(), DaTaoKeDetail.class));
- }
-
- for (DaTaoKeDetail dt : list)
- if (!dt.getPic().startsWith("http"))
- dt.setPic("https:" + dt.getPic());
-
- return new DaTaoKeApiResult(resultJson.optJSONObject("data").optInt("total_num"),
- resultJson.optJSONObject("data").optString("update_time"), list);
- }
-
- public static DaTaoKeDetail getGoodsDetailV1(Long id) {
- String url = String.format("http://api.dataoke.com/index.php?r=Port/index&type=total&appkey=%s&v=2&id=%s",
- Math.random() > 0.5 ? API_KEY : API_KEY_2, id + "");
- String result = request(url);
- JSONObject resultJson = JSONObject.fromObject(result);
- return gson.fromJson(resultJson.optJSONArray("result").optJSONObject(0).toString(), DaTaoKeDetail.class);
- }
+
/**
* 鑾峰彇澶ф窐瀹㈠搧鐗屼紭閫� 鍝佺墝id
@@ -361,6 +332,24 @@
return null;
}
+ public static DaTaoKeDetailV2 getGoodsDetailByGoodsId(Long goodsId) {
+ TaoKeAppInfo app = getRandomApp();
+ Map<String, String> params = new TreeMap<>();
+ params.put("version", "v1.1.1");
+ params.put("appKey", app.getAppKey());
+ params.put("goodsId", goodsId + "");
+ params.put("sign", getSign(params, app.getAppSecret()));
+ String result = HttpUtil.get("https://openapi.dataoke.com/api/goods/get-goods-details", params,
+ new HashMap<>());
+ System.out.println(result);
+ JSONObject json = JSONObject.fromObject(result);
+ JSONObject dataJson = json.optJSONObject("data");
+ if (dataJson != null) {
+ return parseDaTaoKeDetailV2(dataJson);
+ }
+ return null;
+ }
+
private static String requestGet(String url, Map<String, String> params) {
Iterator<String> keys = params.keySet().iterator();
url += "?";
@@ -400,12 +389,126 @@
if (!StringUtil.isNullOrEmpty(cids))
params.put("cids", cids);
+ if (StringUtil.isNullOrEmpty(key))
+ key = "";
params.put("keyWords", key);
+
if (sort != null)
params.put("sort", sort + "");
params.put("sign", getSign(params, app.getAppSecret()));
String result = requestGet("https://openapi.dataoke.com/api/goods/get-dtk-search-goods", params);
+ JSONObject json = JSONObject.fromObject(result);
+ JSONObject dataJson = json.optJSONObject("data");
+ if (dataJson != null) {
+ JSONArray array = dataJson.optJSONArray("list");
+ if (array != null) {
+ List<DaTaoKeDetailV2> list = parseDaTaoKeDetailV2List(array);
+ daTaoKeGoodsResult.setGoodsList(list);
+ }
+ daTaoKeGoodsResult.setPageId(dataJson.optString("pageId"));
+ daTaoKeGoodsResult.setTotalCount(dataJson.optLong("totalNum"));
+ }
+ return daTaoKeGoodsResult;
+ }
+
+ public static DaTaoKeGoodsResult search(String key, List<Integer> cidList, BigDecimal priceLowerLimit,
+ BigDecimal priceUpperLimit, Integer couponPriceLowerLimit, int page, int pageSize, Integer sort) {
+
+ TaoKeAppInfo app = getRandomApp();
+ DaTaoKeGoodsResult daTaoKeGoodsResult = new DaTaoKeGoodsResult();
+ Map<String, String> params = new TreeMap<>();
+ params.put("version", "v2.1.0");
+ params.put("appKey", app.getAppKey());
+ params.put("pageSize", pageSize + "");
+ params.put("pageId", page + "");
+ if (priceLowerLimit != null)
+ params.put("priceLowerLimit", priceLowerLimit + "");
+ if (priceUpperLimit != null)
+ params.put("priceUpperLimit", priceUpperLimit + "");
+
+ if (couponPriceLowerLimit != null)
+ params.put("couponPriceLowerLimit", couponPriceLowerLimit + "");
+
+ String cids = "";
+ if (cidList != null && cidList.size() > 0)
+ for (Integer cid : cidList) {
+ cids += cid + ",";
+ }
+
+ if (cids.endsWith(","))
+ cids = cids.substring(0, cids.length() - 1);
+ if (!StringUtil.isNullOrEmpty(cids))
+ params.put("cids", cids);
+
+ if (StringUtil.isNullOrEmpty(key))
+ key = "%";
+ params.put("keyWords", key);
+
+ if (sort != null)
+ params.put("sort", sort + "");
+ params.put("sign", getSign(params, app.getAppSecret()));
+ String result = requestGet("https://openapi.dataoke.com/api/goods/get-dtk-search-goods", params);
+
+ JSONObject json = JSONObject.fromObject(result);
+ JSONObject dataJson = json.optJSONObject("data");
+ if (dataJson != null) {
+ JSONArray array = dataJson.optJSONArray("list");
+ if (array != null) {
+ List<DaTaoKeDetailV2> list = parseDaTaoKeDetailV2List(array);
+ daTaoKeGoodsResult.setGoodsList(list);
+ }
+ daTaoKeGoodsResult.setPageId(dataJson.optString("pageId"));
+ daTaoKeGoodsResult.setTotalCount(dataJson.optLong("totalNum"));
+ }
+ return daTaoKeGoodsResult;
+ }
+
+ /**
+ * 鍟嗗搧鍒楄〃
+ *
+ * @param key
+ * @param cidList
+ * @param priceLowerLimit
+ * @param priceUpperLimit
+ * @param couponPriceLowerLimit
+ * @param pageId
+ * @param pageSize
+ * @param sort
+ * @return
+ */
+ public static DaTaoKeGoodsResult getGoodsList(String key, List<Integer> cidList, BigDecimal priceLowerLimit,
+ BigDecimal priceUpperLimit, Integer couponPriceLowerLimit, int pageId, int pageSize, Integer sort) {
+ TaoKeAppInfo app = getRandomApp();
+ DaTaoKeGoodsResult daTaoKeGoodsResult = new DaTaoKeGoodsResult();
+ Map<String, String> params = new TreeMap<>();
+ params.put("version", "v1.1.0");
+ params.put("appKey", app.getAppKey());
+ params.put("pageSize", pageSize + "");
+ params.put("pageId", pageId + "");
+
+ if (priceLowerLimit != null)
+ params.put("priceLowerLimit", priceLowerLimit + "");
+ if (priceUpperLimit != null)
+ params.put("priceUpperLimit", priceUpperLimit + "");
+
+ if (couponPriceLowerLimit != null)
+ params.put("couponPriceLowerLimit", couponPriceLowerLimit + "");
+
+ if (sort != null)
+ params.put("sort", sort + "");
+
+ if (cidList != null && cidList.size() > 0) {
+ String cids = "";
+ for (int cid : cidList)
+ cids += cid + ",";
+ cids = cids.endsWith(",") ? cids.substring(0, cids.length() - 1) : cids;
+
+ params.put("cids", cids + "");
+ }
+
+ params.put("sign", getSign(params, app.getAppSecret()));
+ String result = HttpUtil.get("https://openapi.dataoke.com/api/goods/get-goods-list", params, new HashMap<>());
JSONObject json = JSONObject.fromObject(result);
JSONObject dataJson = json.optJSONObject("data");
if (dataJson != null) {
@@ -587,19 +690,5 @@
}
}
return hotWords;
- }
-
- class DaTaoKeResult {
- Date updateTime;
- List<DaTaoKeDetail> dataList;
-
- public DaTaoKeResult(Date updateTime, List<DaTaoKeDetail> dataList) {
- this.updateTime = updateTime;
- this.dataList = dataList;
- }
-
- public DaTaoKeResult() {
-
- }
}
}
--
Gitblit v1.8.0