From 744594ef1a2f530fc3e86ea9dc48b62247f79420 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期二, 19 五月 2020 17:13:23 +0800 Subject: [PATCH] 饿了么绘图,添加口碑 --- fanli/src/main/java/com/yeshi/fanli/util/dataoke/DaTaoKeApiUtil.java | 188 +++++++++++++++++++++++++++++++++++++---------- 1 files changed, 148 insertions(+), 40 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 59888c1..6c84500 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; @@ -113,35 +111,6 @@ } 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); } /** @@ -360,7 +329,7 @@ } return null; } - + public static DaTaoKeDetailV2 getGoodsDetailByGoodsId(Long goodsId) { TaoKeAppInfo app = getRandomApp(); Map<String, String> params = new TreeMap<>(); @@ -418,12 +387,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) { @@ -607,17 +690,42 @@ return hotWords; } - class DaTaoKeResult { - Date updateTime; - List<DaTaoKeDetail> dataList; + /** + * 楂樻晥杞摼 + * @Title: convertLink + * @Description: + * @param auctionId + * @param pid + * void 杩斿洖绫诲瀷 + * @throws + */ + public static String convertLink(Long auctionId, String pid) { + TaoKeAppInfo app = APP_KEYS[1]; + Map<String, String> params = new TreeMap<>(); + params.put("version", "v1.1.1"); + params.put("goodsId", auctionId + ""); + params.put("pid", pid); + params.put("appKey", app.getAppKey()); + params.put("sign", getSign(params, app.getAppSecret())); - public DaTaoKeResult(Date updateTime, List<DaTaoKeDetail> dataList) { - this.updateTime = updateTime; - this.dataList = dataList; + String result = null; + try { + result = HttpUtil.get("https://openapi.dataoke.com/api/tb-service/get-privilege-link", params, + new HashMap<>()); + } catch (Exception e) { + result = HttpUtil.get("https://openapi.dataoke.com/api/tb-service/get-privilege-link", params, + new HashMap<>()); } + + System.out.println(result); - public DaTaoKeResult() { - + JSONObject json = JSONObject.fromObject(result); + if (json != null) { + json = json.getJSONObject("data"); + if (json != null) { + return json.optString("couponClickUrl"); + } } + return null; } } -- Gitblit v1.8.0