| | |
| | | package com.yeshi.fanli.util.dataoke;
|
| | |
|
| | | import java.io.IOException;
|
| | | import java.io.UnsupportedEncodingException;
|
| | | import java.math.BigDecimal;
|
| | | import java.net.URLEncoder;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Date;
|
| | | import java.util.HashMap;
|
| | | import java.util.Iterator;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | | import java.util.Set;
|
| | | import java.util.TreeMap;
|
| | |
|
| | | import org.apache.commons.httpclient.HttpClient;
|
| | | import org.apache.commons.httpclient.HttpException;
|
| | | import org.apache.commons.httpclient.methods.GetMethod;
|
| | | import org.jsoup.Jsoup;
|
| | | import org.jsoup.nodes.Document;
|
| | | import org.jsoup.nodes.Element;
|
| | | import org.jsoup.select.Elements;
|
| | | import org.yeshi.utils.HttpUtil;
|
| | |
|
| | | import com.google.gson.ExclusionStrategy;
|
| | | import com.google.gson.FieldAttributes;
|
| | | import com.google.gson.Gson;
|
| | | import com.yeshi.fanli.dto.dataoke.DaTaoKeApiResult;
|
| | | import com.google.gson.GsonBuilder;
|
| | | 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.dataoke.DaTaoKeDetail;
|
| | | import com.yeshi.fanli.entity.taobao.TaoKeAppInfo;
|
| | | import com.yeshi.fanli.entity.taobao.dataoke.DaTaoKeDetailV2;
|
| | | import com.yeshi.fanli.util.MoneyBigDecimalUtil;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | | import com.yeshi.fanli.util.TimeUtil;
|
| | |
|
| | | import net.sf.json.JSONArray;
|
| | | import net.sf.json.JSONObject;
|
| | |
| | | public class DaTaoKeApiUtil {
|
| | | final static String API_KEY = "a083abb893";
|
| | | final static String API_KEY_2 = "b7a5ea2cd9";
|
| | | static Gson gson = new Gson();
|
| | |
|
| | | 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 = HttpUtil.get(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));
|
| | | }
|
| | | return new DaTaoKeApiResult(resultJson.optJSONObject("data").optInt("total_num"),
|
| | | resultJson.optJSONObject("data").optString("update_time"), list);
|
| | | final static String APP_KEY = "5cf764636d373";
|
| | | final static String APP_KEY_SECRET = "5ea3c24900743f3aa531fb264f9824f2";
|
| | |
|
| | | final static String APP_KEY_2 = "5cf75b0f2c0e4";
|
| | | final static String APP_KEY_SECRET_2 = "b14f1fa115129a447937ca998b311d1e";
|
| | |
|
| | | // 排序值
|
| | |
|
| | | final public static int SORT_DEFAULT = 0;
|
| | | final public static int SORT_CREATETIME = 1;
|
| | | final public static int SORT_SALES = 2;
|
| | | final public static int SORT_COUPON_NUM = 3;
|
| | | final public static int SORT_COMMISSION = 4;
|
| | | final public static int SORT_PRICE_HIGH_TO_LOW = 5;
|
| | | final public static int SORT_PRICE_LOW_TO_HIGH = 6;
|
| | |
|
| | | final static TaoKeAppInfo[] APP_KEYS = new TaoKeAppInfo[] { new TaoKeAppInfo(APP_KEY, APP_KEY_SECRET),
|
| | | new TaoKeAppInfo(APP_KEY_2, APP_KEY_SECRET_2) };
|
| | |
|
| | | final static String[] APP_SECRETS = new String[] { APP_KEY_SECRET, APP_KEY_SECRET_2 };
|
| | |
|
| | | static Gson gson = null;
|
| | | static {
|
| | | gson = new GsonBuilder().setExclusionStrategies(new ExclusionStrategy() {
|
| | | @Override
|
| | | public boolean shouldSkipField(FieldAttributes f) {
|
| | | return f.getName().equals("createTime");// 忽略createTime的解析
|
| | | }
|
| | |
|
| | | @Override
|
| | | public boolean shouldSkipClass(Class<?> clazz) {
|
| | | return false;
|
| | | }
|
| | | }).create();
|
| | | }
|
| | |
|
| | | |
| | | private static String get(String url) {
|
| | | HttpClient client = new HttpClient();
|
| | | try {
|
| | | client.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
|
| | | client.getHttpConnectionManager().getParams().setSoTimeout(5000);
|
| | | GetMethod method = new GetMethod(url);
|
| | | client.executeMethod(method);
|
| | | return method.getResponseBodyAsString();
|
| | | } catch (HttpException e) {
|
| | | e.printStackTrace();
|
| | | } catch (IOException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | return "";
|
| | | }
|
| | |
|
| | | private static String request(String url) {
|
| | | String result = null;
|
| | |
|
| | | while (result == null) {
|
| | | try {
|
| | | result = get(url);
|
| | | if ((result != null && result.startsWith("<html>")) || StringUtil.isNullOrEmpty(result))
|
| | | result = null;
|
| | | } catch (Exception e) {
|
| | | try {
|
| | | Thread.sleep(400);
|
| | | } catch (InterruptedException e1) {
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | return result;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取大淘客品牌优选 品牌id
|
| | | * |
| | | * @return
|
| | | */
|
| | | public static List<String> getBrandIdList() {
|
| | | List<String> listId = null;
|
| | | List<String> listId = new ArrayList<>();
|
| | | try {
|
| | | Document doc = Jsoup.connect("http://www.dataoke.com/brandFeature").get();
|
| | | Elements els = doc.getElementsByTag("script");
|
| | | for (int i = 0; i < els.size(); i++) {
|
| | | if (els.get(i).html().contains("var brandData")) {
|
| | |
|
| | | JSONObject data = JSONObject
|
| | | .fromObject(els.get(i).html().replace("var brandData =", "").trim().split("};")[0] + "}");
|
| | | listId = convertList(data);
|
| | | break;
|
| | | }
|
| | | Document doc = Jsoup.connect("http://www.dataoke.com/brandFilter?cid=0&sort=1&main=0").get();
|
| | | Element root = doc.getElementsByClass("brand-list").get(0);
|
| | | Elements items = root.getElementsByTag("a");
|
| | | for (int i = 0; i < items.size(); i++) {
|
| | | String id = items.get(i).attr("href").split("\\?")[1].replace("id=", "").trim();
|
| | | listId.add(id);
|
| | | }
|
| | |
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | return listId;
|
| | | }
|
| | |
|
| | | |
| | | public static List<String> convertList(JSONObject data) {
|
| | | List<String> listId = new ArrayList<String>();
|
| | |
|
| | | // 萌趣新生力 夏日好食光栏目
|
| | | JSONArray arrayActs = data.optJSONObject("acts").optJSONArray("list");
|
| | | for (int i = 0; i < arrayActs.size(); i++) {
|
| | | JSONObject item = arrayActs.optJSONObject(i);
|
| | | listId.add(item.optString("brand_id"));
|
| | | }
|
| | |
|
| | | // 热推爆款
|
| | | JSONArray arrayPushs = data.optJSONObject("pushs").optJSONArray("list");
|
| | | for (int i = 0; i < arrayPushs.size(); i++) {
|
| | | JSONObject item = arrayPushs.optJSONObject(i);
|
| | | listId.add(item.optString("brand_id"));
|
| | | }
|
| | |
|
| | | // 热销品牌榜
|
| | | JSONArray arrayRanks = data.optJSONObject("ranks").optJSONArray("list");
|
| | | for (int i = 0; i < arrayRanks.size(); i++) {
|
| | | JSONObject item = arrayRanks.optJSONObject(i);
|
| | | // long id = item.optLong("id");
|
| | | // String title =item.optString("title");
|
| | | JSONArray goods = item.optJSONArray("goods");
|
| | | for (int j = 0; j < goods.size(); j++) {
|
| | | JSONObject good = goods.optJSONObject(j);
|
| | | listId.add(good.optString("brand_id"));
|
| | | }
|
| | | }
|
| | | return listId;
|
| | | }
|
| | |
|
| | | |
| | | /**
|
| | | * 获取店铺下前4个商品、店铺介绍
|
| | | * |
| | | * @param brandId
|
| | | * @return
|
| | | */
|
| | |
| | |
|
| | | JSONObject data = JSONObject
|
| | | .fromObject(els.get(i).html().replace("var brandData =", "").trim().split("};")[0] + "}");
|
| | | taoBaoShopDTO = convertTaoBaoShopDTO(data);
|
| | | taoBaoShopDTO = new TaoBaoShopDTO();
|
| | | JSONObject item = data.optJSONObject("act");
|
| | | taoBaoShopDTO.setSellerId(item.optLong("seller_id"));
|
| | | taoBaoShopDTO.setBrandId(item.optString("brand_id"));
|
| | | taoBaoShopDTO.setBrandDes(item.optString("brand_des"));
|
| | | taoBaoShopDTO.setShopIcon(item.optString("brand_logo"));
|
| | | taoBaoShopDTO.setUserType(0);
|
| | |
|
| | | // 商品信息
|
| | | taoBaoShopDTO = getDynamicShopGoods(brandId, taoBaoShopDTO);
|
| | |
|
| | | break;
|
| | | }
|
| | | }
|
| | |
| | | e.printStackTrace();
|
| | | }
|
| | | return taoBaoShopDTO;
|
| | |
|
| | | }
|
| | |
|
| | | public static TaoBaoShopDTO convertTaoBaoShopDTO(JSONObject data) {
|
| | | TaoBaoShopDTO taoBaoShopDTO = new TaoBaoShopDTO();
|
| | | JSONObject item = data.optJSONObject("act");
|
| | | taoBaoShopDTO.setSellerId(item.optLong("seller_id"));
|
| | | taoBaoShopDTO.setBrandId(item.optString("brand_id"));
|
| | | taoBaoShopDTO.setBrandDes(item.optString("brand_des"));
|
| | | int userType = 0;
|
| | | private static TaoKeAppInfo getRandomApp() {
|
| | | int pos = (int) (Math.random() * APP_KEYS.length);
|
| | | return APP_KEYS[pos];
|
| | | }
|
| | |
|
| | | public static DaTaoKeGoodsResult listAll(String pageId) {
|
| | | 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", 200 + "");
|
| | | // params.put("sort", "1");
|
| | | if (!StringUtil.isNullOrEmpty(pageId)) {
|
| | | params.put("pageId", pageId);
|
| | | }
|
| | | 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;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 失效商品
|
| | | * |
| | | * @param pageId
|
| | | * @return
|
| | | */
|
| | | public static DaTaoKeGoodsResult getInvalidGoodsList(String pageId, String startTime, String endTime) {
|
| | | TaoKeAppInfo app = getRandomApp();
|
| | | DaTaoKeGoodsResult daTaoKeGoodsResult = new DaTaoKeGoodsResult();
|
| | | Map<String, String> params = new TreeMap<>();
|
| | | params.put("version", "v1.0.1");
|
| | | params.put("appKey", app.getAppKey());
|
| | | params.put("pageSize", 200 + "");
|
| | | if (!StringUtil.isNullOrEmpty(startTime))
|
| | | params.put("startTime", startTime);
|
| | |
|
| | | if (!StringUtil.isNullOrEmpty(endTime))
|
| | | params.put("endTime", endTime);
|
| | |
|
| | | if (!StringUtil.isNullOrEmpty(pageId))
|
| | | params.put("pageId", pageId);
|
| | |
|
| | | params.put("sign", getSign(params, app.getAppSecret()));
|
| | | String result = HttpUtil.get("https://openapi.dataoke.com/api/goods/get-stale-goods-by-time", params,
|
| | | new HashMap<>());
|
| | | System.out.println(result);
|
| | | 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 getNewGoodsList(String pageId, String startTime, String endTime) {
|
| | | 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", 200 + "");
|
| | | if (!StringUtil.isNullOrEmpty(startTime))
|
| | | params.put("startTime", startTime);
|
| | |
|
| | | if (!StringUtil.isNullOrEmpty(endTime))
|
| | | params.put("endTime", endTime);
|
| | |
|
| | | if (!StringUtil.isNullOrEmpty(pageId))
|
| | | params.put("pageId", pageId);
|
| | |
|
| | | params.put("sign", getSign(params, app.getAppSecret()));
|
| | | String result = HttpUtil.get("https://openapi.dataoke.com/api/goods/pull-goods-by-time", 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;
|
| | | }
|
| | |
|
| | | public static DaTaoKeGoodsResult getUpdateGoodsList(String pageId, String startTime, String endTime) {
|
| | | 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", 200 + "");
|
| | | if (!StringUtil.isNullOrEmpty(startTime))
|
| | | params.put("startTime", startTime);
|
| | |
|
| | | if (!StringUtil.isNullOrEmpty(endTime))
|
| | | params.put("endTime", endTime);
|
| | |
|
| | | if (!StringUtil.isNullOrEmpty(pageId))
|
| | | params.put("pageId", pageId);
|
| | |
|
| | | params.put("sign", getSign(params, app.getAppSecret()));
|
| | | String result = HttpUtil.get("https://openapi.dataoke.com/api/goods/get-newest-goods", 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;
|
| | | }
|
| | |
|
| | | public static DaTaoKeDetailV2 getGoodsDetail(Long id) {
|
| | | TaoKeAppInfo app = getRandomApp();
|
| | | Map<String, String> params = new TreeMap<>();
|
| | | params.put("version", "v1.1.0");
|
| | | params.put("appKey", app.getAppKey());
|
| | | params.put("id", id + "");
|
| | | params.put("sign", getSign(params, app.getAppSecret()));
|
| | | String result = HttpUtil.get("https://openapi.dataoke.com/api/goods/get-goods-details", params,
|
| | | new HashMap<>());
|
| | | JSONObject json = JSONObject.fromObject(result);
|
| | | JSONObject dataJson = json.optJSONObject("data");
|
| | | if (dataJson != null) {
|
| | | return parseDaTaoKeDetailV2(dataJson);
|
| | | }
|
| | | 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 += "?";
|
| | | while (keys.hasNext()) {
|
| | | String key = keys.next();
|
| | | try {
|
| | | url += String.format("%s=%s&", key, URLEncoder.encode(params.get(key), "UTF-8"));
|
| | | } catch (UnsupportedEncodingException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | | return HttpUtil.get(url, 10000);
|
| | | }
|
| | |
|
| | | public static DaTaoKeGoodsResult search(String key, List<Integer> cidList, BigDecimal priceLowerLimit,
|
| | | BigDecimal priceUpperLimit, 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 + "");
|
| | | 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;
|
| | | }
|
| | |
|
| | | 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 "";
|
| | | }
|
| | | StringBuffer sb = new StringBuffer("");
|
| | | Set<String> keySet = map.keySet();
|
| | | Iterator<String> iter = keySet.iterator();
|
| | | while (iter.hasNext()) {
|
| | | String key = iter.next();
|
| | | sb.append("&" + key + "=" + map.get(key));
|
| | | }
|
| | | sb.deleteCharAt(0);
|
| | | String signStr = "";
|
| | | signStr = sb.toString() + "&key=" + secretKey;
|
| | | return StringUtil.Md5(signStr).toUpperCase();
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取店铺下前4个商品、店铺介绍
|
| | | * |
| | | * @param brandId
|
| | | * @return
|
| | | */
|
| | | public static TaoBaoShopDTO getDynamicShopGoods(String brandId, TaoBaoShopDTO taoBaoShopDTO) {
|
| | | if (brandId == null) {
|
| | | return taoBaoShopDTO;
|
| | | }
|
| | |
|
| | | int userType = 0;
|
| | | List<TaoBaoGoodsBrief> listGoods = new ArrayList<TaoBaoGoodsBrief>();
|
| | | JSONArray arrayGoods = data.optJSONArray("goods");
|
| | |
|
| | | String result = HttpUtil.get("http://www.dataoke.com/brandGoods?id=" + brandId + "&page=1");
|
| | | JSONObject json = JSONObject.fromObject(result);
|
| | | JSONArray arrayGoods = json.optJSONArray("goods");
|
| | |
|
| | | for (int i = 0; i < arrayGoods.size(); i++) {
|
| | | if (i > 3) {
|
| | | if (i >= 2) {
|
| | | break;
|
| | | }
|
| | | JSONObject itemGoods = arrayGoods.optJSONObject(i);
|
| | |
|
| | | TaoBaoGoodsBrief taoBaoGoods = new TaoBaoGoodsBrief();
|
| | | taoBaoGoods.setAuctionId(itemGoods.optLong("goodsid"));
|
| | | taoBaoGoods.setBiz30day(itemGoods.optInt("xiaoliang"));
|
| | |
| | | taoBaoGoods.setTkRate(new BigDecimal(itemGoods.optString("yongjin")));
|
| | | taoBaoGoods.setTkCommFee(new BigDecimal("0"));
|
| | | taoBaoGoods.setState(0);
|
| | | |
| | |
|
| | | listGoods.add(taoBaoGoods);
|
| | | |
| | |
|
| | | userType = itemGoods.optInt("istmall");
|
| | | }
|
| | | taoBaoShopDTO.setListGoods(listGoods);
|
| | | taoBaoShopDTO.setUserType(userType);
|
| | | taoBaoShopDTO.setListGoods(listGoods);
|
| | | return taoBaoShopDTO;
|
| | | }
|
| | | |
| | | class DaTaoKeResult {
|
| | | Date updateTime;
|
| | | List<DaTaoKeDetail> dataList;
|
| | |
|
| | | public DaTaoKeResult(Date updateTime, List<DaTaoKeDetail> dataList) {
|
| | | this.updateTime = updateTime;
|
| | | this.dataList = dataList;
|
| | | public static int RANK_TYPE_TIME = 1;// 实时
|
| | | public static int RANK_TYPE_DAY = 2;// 全天榜
|
| | | public static int RANK_TYPE_HOT = 3;// 热推榜
|
| | | public static int RANK_TYPE_REBUY = 4;// 复购榜
|
| | |
|
| | | /**
|
| | | * 各大榜单
|
| | | * |
| | | * @param type
|
| | | * @return
|
| | | */
|
| | | public static DaTaoKeGoodsResult getRankingList(int type, Integer cid) {
|
| | | 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("rankType", type + "");
|
| | | if (cid != null)
|
| | | params.put("cid", cid + "");
|
| | | params.put("sign", getSign(params, app.getAppSecret()));
|
| | | // 做2次请求
|
| | | String result = null;
|
| | | try {
|
| | | result = HttpUtil.get("https://openapi.dataoke.com/api/goods/get-ranking-list", params, new HashMap<>());
|
| | | } catch (Exception e) {
|
| | | result = HttpUtil.get("https://openapi.dataoke.com/api/goods/get-ranking-list", params, new HashMap<>());
|
| | | }
|
| | | JSONObject json = JSONObject.fromObject(result);
|
| | | if (json != null) {
|
| | | JSONArray array = json.optJSONArray("data");
|
| | |
|
| | | public DaTaoKeResult() {
|
| | |
|
| | | List<DaTaoKeDetailV2> list = new ArrayList<>();
|
| | | for (int i = 0; i < array.size(); i++) {
|
| | | JSONObject itemData = array.optJSONObject(i);
|
| | | DaTaoKeDetailV2 item = parseDaTaoKeDetailV2(itemData);
|
| | | item.setCouponConditions(itemData.optString("couponConditions"));
|
| | | item.setShopType(itemData.optInt("shopType"));
|
| | | item.setOriginalPrice(new BigDecimal(itemData.optString("originalPrice")));
|
| | | item.setMainPic(itemData.optString("mainPic"));
|
| | | list.add(item);
|
| | | }
|
| | | daTaoKeGoodsResult.setGoodsList(list);
|
| | | }
|
| | | return daTaoKeGoodsResult;
|
| | | }
|
| | |
|
| | | private static List<DaTaoKeDetailV2> parseDaTaoKeDetailV2List(JSONArray array) {
|
| | | List<DaTaoKeDetailV2> detailList = new ArrayList<>();
|
| | | for (int i = 0; i < array.size(); i++) {
|
| | | DaTaoKeDetailV2 detail = parseDaTaoKeDetailV2(array.optJSONObject(i));
|
| | | detailList.add(detail);
|
| | | }
|
| | | return detailList;
|
| | | }
|
| | |
|
| | | private static DaTaoKeDetailV2 parseDaTaoKeDetailV2(JSONObject json) {
|
| | | DaTaoKeDetailV2 detail = gson.fromJson(json.toString(), DaTaoKeDetailV2.class);
|
| | | if (StringUtil.isNullOrEmpty(json.optString("createTime"))) {
|
| | | detail.setCreateTime(
|
| | | new Date(TimeUtil.convertToTimeTemp(json.optString("onSaleTime"), "yyyy-MM-dd HH:mm:ss")));
|
| | | } else {
|
| | | detail.setCreateTime(
|
| | | new Date(TimeUtil.convertToTimeTemp(json.optString("createTime"), "yyyy-MM-dd HH:mm:ss")));
|
| | | }
|
| | | return detail;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 各大榜单
|
| | | * |
| | | * @param type
|
| | | * @return
|
| | | */
|
| | | public static String getHotWords() {
|
| | | TaoKeAppInfo app = getRandomApp();
|
| | | Map<String, String> params = new TreeMap<>();
|
| | | params.put("version", "v1.0.1");
|
| | | params.put("appKey", app.getAppKey());
|
| | | params.put("sign", getSign(params, app.getAppSecret()));
|
| | |
|
| | | String result = null;
|
| | | try {
|
| | | result = HttpUtil.get("https://openapi.dataoke.com/api/category/get-top100", params, new HashMap<>());
|
| | | } catch (Exception e) {
|
| | | result = HttpUtil.get("https://openapi.dataoke.com/api/category/get-top100", params, new HashMap<>());
|
| | | }
|
| | |
|
| | | String hotWords = null;
|
| | | JSONObject json = JSONObject.fromObject(result);
|
| | | if (json != null) {
|
| | | json = json.getJSONObject("data");
|
| | | if (json != null) {
|
| | | hotWords = json.optString("hotWords");
|
| | | }
|
| | | }
|
| | | return hotWords;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 高效转链
|
| | | * @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()));
|
| | |
|
| | | 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);
|
| | |
|
| | | JSONObject json = JSONObject.fromObject(result);
|
| | | if (json != null) {
|
| | | json = json.getJSONObject("data");
|
| | | if (json != null) {
|
| | | return json.optString("couponClickUrl");
|
| | | }
|
| | | }
|
| | | return null;
|
| | | }
|
| | | }
|