| | |
| | | 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 += "?";
|
| | |
| | | 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()));
|
| | |
| | | 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) {
|
| | | 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;
|
| | | }
|
| | |
|
| | | private static String getSign(Map<String, String> map, String secretKey) {
|
| | | if (map.size() == 0) {
|
| | | return "";
|