admin
2020-11-25 604be616a6ba9e2604c8616be562c5a1c49f073c
大淘客接口编码修改
5个文件已修改
1501 ■■■■ 已修改文件
facade-goods/src/main/java/com/yeshi/goods/facade/utils/taobao/DaTaoKeApiUtil.java 1419 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/fanli.iml 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/job/UpdateDaTaoKeJob.java 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/resource/env-dev/redis.properties 10 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
utils/src/test/java/com/yeshi/utils/AlipayTest.java 53 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
facade-goods/src/main/java/com/yeshi/goods/facade/utils/taobao/DaTaoKeApiUtil.java
@@ -14,6 +14,7 @@
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.io.IOUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
@@ -23,778 +24,816 @@
import org.yeshi.utils.StringUtil;
import org.yeshi.utils.TimeUtil;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.io.*;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.util.*;
public class DaTaoKeApiUtil {
    final static String API_KEY = "a083abb893";
    final static String API_KEY_2 = "b7a5ea2cd9";
    final static String APP_KEY = "5cf764636d373";
    final static String APP_KEY_SECRET = "5ea3c24900743f3aa531fb264f9824f2";
    final static String API_CHARSET = "ISO-8859-1";
    final static String APP_KEY_2 = "5cf75b0f2c0e4";
    final static String APP_KEY_SECRET_2 = "b14f1fa115129a447937ca998b311d1e";
    final static String API_KEY = "a083abb893";
    final static String API_KEY_2 = "b7a5ea2cd9";
    // 排序值
    final static String APP_KEY = "5cf764636d373";
    final static String APP_KEY_SECRET = "5ea3c24900743f3aa531fb264f9824f2";
    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 String APP_KEY_2 = "5cf75b0f2c0e4";
    final static String APP_KEY_SECRET_2 = "b14f1fa115129a447937ca998b311d1e";
    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 };
    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;
    static Gson gson = null;
    static {
        gson = new GsonBuilder().setExclusionStrategies(new ExclusionStrategy() {
            @Override
            public boolean shouldSkipField(FieldAttributes f) {
                return f.getName().equals("createTime");// 忽略createTime的解析
            }
    final static TaoKeAppInfo[] APP_KEYS = new TaoKeAppInfo[]{new TaoKeAppInfo(APP_KEY, APP_KEY_SECRET),
            new TaoKeAppInfo(APP_KEY_2, APP_KEY_SECRET_2)};
            @Override
            public boolean shouldSkipClass(Class<?> clazz) {
                return false;
            }
        }).create();
    }
    final static String[] APP_SECRETS = new String[]{APP_KEY_SECRET, APP_KEY_SECRET_2};
    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 "";
    }
    static Gson gson = null;
    private static String request(String url) {
        String result = null;
    static {
        gson = new GsonBuilder().setExclusionStrategies(new ExclusionStrategy() {
            @Override
            public boolean shouldSkipField(FieldAttributes f) {
                return f.getName().equals("createTime");// 忽略createTime的解析
            }
        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) {
                }
            }
        }
            @Override
            public boolean shouldSkipClass(Class<?> clazz) {
                return false;
            }
        }).create();
    }
        return result;
    }
    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 "";
    }
    /**
     * 获取大淘客品牌优选 品牌id
     *
     * @return
     */
    public static List<String> getBrandIdList() {
        List<String> listId = new ArrayList<>();
        try {
            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;
    }
    private static String baseGet(String url, Map<String, String> params) {
        HttpClient client = new HttpClient();
        try {
            Iterator<String> keys = params.keySet().iterator();
            String key;
            for (url = url + "?"; keys.hasNext(); url = url + String.format("%s=%s&", key, URLEncoder.encode((String) params.get(key), "UTF-8"))) {
                key = keys.next();
            }
    /**
     * 获取店铺下前4个商品、店铺介绍
     *
     * @param brandId
     * @return
     */
    public static TaoBaoShopDTO getDynamicShopInfo(String brandId) {
        if (brandId == null) {
            return null;
        }
        TaoBaoShopDTO taoBaoShopDTO = null;
            GetMethod method = new GetMethod(url);
            client.executeMethod(method);
            InputStream inputStream = method.getResponseBodyAsStream();
            String result = IOUtils.toString(inputStream, API_CHARSET);
            return result;
        } catch (Exception var7) {
            var7.printStackTrace();
            return "";
        }
    }
        Document doc;
        try {
            doc = Jsoup.connect("http://www.dataoke.com/brandSingle?id=" + brandId).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] + "}");
                    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);
    private static String request(String url) {
        String result = null;
                    // 商品信息
                    taoBaoShopDTO = getDynamicShopGoods(brandId, taoBaoShopDTO);
        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) {
                }
            }
        }
                    break;
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return taoBaoShopDTO;
    }
        return result;
    }
    private static TaoKeAppInfo getRandomApp() {
        int pos = (int) (Math.random() * APP_KEYS.length);
        return APP_KEYS[pos];
    }
    /**
     * 获取大淘客品牌优选 品牌id
     *
     * @return
     */
    public static List<String> getBrandIdList() {
        List<String> listId = new ArrayList<>();
        try {
            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 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;
    }
    /**
     * 获取店铺下前4个商品、店铺介绍
     *
     * @param brandId
     * @return
     */
    public static TaoBaoShopDTO getDynamicShopInfo(String brandId) {
        if (brandId == null) {
            return null;
        }
        TaoBaoShopDTO taoBaoShopDTO = null;
    /**
     * 失效商品
     *
     * @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);
        Document doc;
        try {
            doc = Jsoup.connect("http://www.dataoke.com/brandSingle?id=" + brandId).get();
            Elements els = doc.getElementsByTag("script");
            for (int i = 0; i < els.size(); i++) {
                if (els.get(i).html().contains("var brandData")) {
        if (!StringUtil.isNullOrEmpty(endTime))
            params.put("endTime", endTime);
                    JSONObject data = JSONObject
                            .fromObject(els.get(i).html().replace("var brandData =", "").trim().split("};")[0] + "}");
                    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);
        if (!StringUtil.isNullOrEmpty(pageId))
            params.put("pageId", pageId);
                    // 商品信息
                    taoBaoShopDTO = getDynamicShopGoods(brandId, taoBaoShopDTO);
        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;
    }
                    break;
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return taoBaoShopDTO;
    }
    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);
    private static TaoKeAppInfo getRandomApp() {
        int pos = (int) (Math.random() * APP_KEYS.length);
        return APP_KEYS[pos];
    }
        if (!StringUtil.isNullOrEmpty(endTime))
            params.put("endTime", endTime);
    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 = baseGet("https://openapi.dataoke.com/api/goods/get-goods-list", 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;
    }
        if (!StringUtil.isNullOrEmpty(pageId))
            params.put("pageId", pageId);
    /**
     * 失效商品
     *
     * @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);
        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) {
        if (!StringUtil.isNullOrEmpty(endTime))
            params.put("endTime", endTime);
                List<DaTaoKeDetailV2> list = parseDaTaoKeDetailV2List(array);
                daTaoKeGoodsResult.setGoodsList(list);
            }
            daTaoKeGoodsResult.setPageId(dataJson.optString("pageId"));
            daTaoKeGoodsResult.setTotalCount(dataJson.optLong("totalNum"));
        }
        return daTaoKeGoodsResult;
    }
        if (!StringUtil.isNullOrEmpty(pageId))
            params.put("pageId", pageId);
    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);
        params.put("sign", getSign(params, app.getAppSecret()));
        String result = baseGet("https://openapi.dataoke.com/api/goods/get-stale-goods-by-time", params);
        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;
    }
        if (!StringUtil.isNullOrEmpty(endTime))
            params.put("endTime", endTime);
    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(pageId))
            params.put("pageId", pageId);
        if (!StringUtil.isNullOrEmpty(endTime))
            params.put("endTime", endTime);
        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;
    }
        if (!StringUtil.isNullOrEmpty(pageId))
            params.put("pageId", pageId);
    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;
    }
        params.put("sign", getSign(params, app.getAppSecret()));
        String result = baseGet("https://openapi.dataoke.com/api/goods/pull-goods-by-time", params);
        JSONObject json = JSONObject.fromObject(result);
        JSONObject dataJson = json.optJSONObject("data");
        if (dataJson != null) {
            JSONArray array = dataJson.optJSONArray("list");
            if (array != 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;
    }
                List<DaTaoKeDetailV2> list = parseDaTaoKeDetailV2List(array);
                daTaoKeGoodsResult.setGoodsList(list);
            }
            daTaoKeGoodsResult.setPageId(dataJson.optString("pageId"));
            daTaoKeGoodsResult.setTotalCount(dataJson.optLong("totalNum"));
        }
        return daTaoKeGoodsResult;
    }
    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 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);
    public static DaTaoKeGoodsResult search(String key, List<Integer> cidList, BigDecimal priceLowerLimit,
            BigDecimal priceUpperLimit, int page, int pageSize, Integer sort) {
        if (!StringUtil.isNullOrEmpty(endTime))
            params.put("endTime", endTime);
        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 (!StringUtil.isNullOrEmpty(pageId))
            params.put("pageId", pageId);
        if (cids.endsWith(","))
            cids = cids.substring(0, cids.length() - 1);
        if (!StringUtil.isNullOrEmpty(cids))
            params.put("cids", cids);
        params.put("sign", getSign(params, app.getAppSecret()));
        String result = baseGet("https://openapi.dataoke.com/api/goods/get-newest-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;
    }
        if (StringUtil.isNullOrEmpty(key))
            key = "";
        params.put("keyWords", key);
    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 = baseGet("https://openapi.dataoke.com/api/goods/get-goods-details", params);
        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 = baseGet("https://openapi.dataoke.com/api/goods/get-goods-details", params);
        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();
            }
        }
        String result = HttpUtil.get(url, 10000);
        try {
            if (result != null)
                return new String(result.getBytes("ISO-8859-1"), "UTF-8");
        } catch (UnsupportedEncodingException e) {
        }
        return result;
    }
    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;
    }
        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);
    /**
     * 商品列表
     *
     * @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 + "");
        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;
    }
        if (priceLowerLimit != null)
            params.put("priceLowerLimit", priceLowerLimit + "");
        if (priceUpperLimit != null)
            params.put("priceUpperLimit", priceUpperLimit + "");
    public static DaTaoKeGoodsResult search(String key, List<Integer> cidList, BigDecimal priceLowerLimit,
            BigDecimal priceUpperLimit, Integer couponPriceLowerLimit, int page, int pageSize, Integer sort) {
        if (couponPriceLowerLimit != null)
            params.put("couponPriceLowerLimit", couponPriceLowerLimit + "");
        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 (sort != null)
            params.put("sort", sort + "");
        if (couponPriceLowerLimit != null)
            params.put("couponPriceLowerLimit", couponPriceLowerLimit + "");
        if (cidList != null && cidList.size() > 0) {
            String cids = "";
            for (int cid : cidList)
                cids += cid + ",";
            cids = cids.endsWith(",") ? cids.substring(0, cids.length() - 1) : cids;
        String cids = "";
        if (cidList != null && cidList.size() > 0)
            for (Integer cid : cidList) {
                cids += cid + ",";
            }
            params.put("cids", cids + "");
        }
        if (cids.endsWith(","))
            cids = cids.substring(0, cids.length() - 1);
        if (!StringUtil.isNullOrEmpty(cids))
            params.put("cids", cids);
        params.put("sign", getSign(params, app.getAppSecret()));
        String result = baseGet("https://openapi.dataoke.com/api/goods/get-goods-list", 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;
    }
        if (StringUtil.isNullOrEmpty(key))
            key = "%";
        params.put("keyWords", key);
    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();
    }
        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);
    /**
     * 获取店铺下前4个商品、店铺介绍
     *
     * @param brandId
     * @return
     */
    public static TaoBaoShopDTO getDynamicShopGoods(String brandId, TaoBaoShopDTO taoBaoShopDTO) {
        if (brandId == null) {
            return taoBaoShopDTO;
        }
        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;
    }
        int userType = 0;
        List<TaoBaoGoodsBrief> listGoods = new ArrayList<TaoBaoGoodsBrief>();
    /**
     * 商品列表
     *
     * @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 + "");
        String result = baseGet("http://www.dataoke.com/brandGoods?id=" + brandId + "&page=1", new HashMap<>());
        JSONObject json = JSONObject.fromObject(result);
        JSONArray arrayGoods = json.optJSONArray("goods");
        if (priceLowerLimit != null)
            params.put("priceLowerLimit", priceLowerLimit + "");
        if (priceUpperLimit != null)
            params.put("priceUpperLimit", priceUpperLimit + "");
        for (int i = 0; i < arrayGoods.size(); i++) {
            if (i >= 2) {
                break;
            }
            JSONObject itemGoods = arrayGoods.optJSONObject(i);
        if (couponPriceLowerLimit != null)
            params.put("couponPriceLowerLimit", couponPriceLowerLimit + "");
            TaoBaoGoodsBrief taoBaoGoods = new TaoBaoGoodsBrief();
            taoBaoGoods.setAuctionId(itemGoods.optLong("goodsid"));
            taoBaoGoods.setBiz30day(itemGoods.optInt("xiaoliang"));
            taoBaoGoods.setCouponAmount(new BigDecimal(itemGoods.optString("quan_jine")));
            taoBaoGoods.setCouponInfo(String.format("满%s元减%s元", itemGoods.optString("quan_tiaojian"),
                    MoneyBigDecimalUtil.getWithNoZera(new BigDecimal(itemGoods.optString("quan_jine")))));
            taoBaoGoods.setCouponLeftCount(itemGoods.optInt("quan_num"));
            taoBaoGoods.setCouponStartFee(new BigDecimal(itemGoods.optString("quan_tiaojian")));
            taoBaoGoods.setCouponTotalCount(itemGoods.optInt("quan_num"));
            taoBaoGoods.setPictUrl(itemGoods.optString("pic"));
            taoBaoGoods.setPictUrlWhite(itemGoods.optString("pic"));
            taoBaoGoods.setSellerId(itemGoods.optLong("seller_id"));
            taoBaoGoods.setShopTitle("");
            taoBaoGoods.setTitle(itemGoods.optString("title"));
            taoBaoGoods.setUserType(itemGoods.optInt("istmall"));
            taoBaoGoods.setZkPrice(new BigDecimal(itemGoods.optString("yuanjia")));
            taoBaoGoods.setTkRate(new BigDecimal(itemGoods.optString("yongjin")));
            taoBaoGoods.setTkCommFee(new BigDecimal("0"));
            taoBaoGoods.setState(0);
        if (sort != null)
            params.put("sort", sort + "");
            listGoods.add(taoBaoGoods);
        if (cidList != null && cidList.size() > 0) {
            String cids = "";
            for (int cid : cidList)
                cids += cid + ",";
            cids = cids.endsWith(",") ? cids.substring(0, cids.length() - 1) : cids;
            userType = itemGoods.optInt("istmall");
        }
        taoBaoShopDTO.setUserType(userType);
        taoBaoShopDTO.setListGoods(listGoods);
        return taoBaoShopDTO;
    }
            params.put("cids", cids + "");
        }
    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;// 复购榜
        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 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 = baseGet("https://openapi.dataoke.com/api/goods/get-ranking-list", params);
        } catch (Exception e) {
            result = baseGet("https://openapi.dataoke.com/api/goods/get-ranking-list", params);
        }
    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();
    }
        try {
    /**
     * 获取店铺下前4个商品、店铺介绍
     *
     * @param brandId
     * @return
     */
    public static TaoBaoShopDTO getDynamicShopGoods(String brandId, TaoBaoShopDTO taoBaoShopDTO) {
        if (brandId == null) {
            return taoBaoShopDTO;
        }
//            System.out.println("GBK:"+new String(result.getBytes("GBK"),"UTF-8"));
//            System.out.println("ISO-8859-1:"+new String(result.getBytes("ISO-8859-1"),"UTF-8"));
//            System.out.println("GB2312:"+new String(result.getBytes("GB2312"),"UTF-8"));
        int userType = 0;
        List<TaoBaoGoodsBrief> listGoods = new ArrayList<TaoBaoGoodsBrief>();
            result = new String(result.getBytes("ISO-8859-1"), "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        String result = HttpUtil.get("http://www.dataoke.com/brandGoods?id=" + brandId + "&page=1");
        JSONObject json = JSONObject.fromObject(result);
        JSONArray arrayGoods = json.optJSONArray("goods");
        JSONObject json = JSONObject.fromObject(result);
        if (json != null) {
            JSONArray array = json.optJSONArray("data");
        for (int i = 0; i < arrayGoods.size(); i++) {
            if (i >= 2) {
                break;
            }
            JSONObject itemGoods = arrayGoods.optJSONObject(i);
            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;
    }
            TaoBaoGoodsBrief taoBaoGoods = new TaoBaoGoodsBrief();
            taoBaoGoods.setAuctionId(itemGoods.optLong("goodsid"));
            taoBaoGoods.setBiz30day(itemGoods.optInt("xiaoliang"));
            taoBaoGoods.setCouponAmount(new BigDecimal(itemGoods.optString("quan_jine")));
            taoBaoGoods.setCouponInfo(String.format("满%s元减%s元", itemGoods.optString("quan_tiaojian"),
                    MoneyBigDecimalUtil.getWithNoZera(new BigDecimal(itemGoods.optString("quan_jine")))));
            taoBaoGoods.setCouponLeftCount(itemGoods.optInt("quan_num"));
            taoBaoGoods.setCouponStartFee(new BigDecimal(itemGoods.optString("quan_tiaojian")));
            taoBaoGoods.setCouponTotalCount(itemGoods.optInt("quan_num"));
            taoBaoGoods.setPictUrl(itemGoods.optString("pic"));
            taoBaoGoods.setPictUrlWhite(itemGoods.optString("pic"));
            taoBaoGoods.setSellerId(itemGoods.optLong("seller_id"));
            taoBaoGoods.setShopTitle("");
            taoBaoGoods.setTitle(itemGoods.optString("title"));
            taoBaoGoods.setUserType(itemGoods.optInt("istmall"));
            taoBaoGoods.setZkPrice(new BigDecimal(itemGoods.optString("yuanjia")));
            taoBaoGoods.setTkRate(new BigDecimal(itemGoods.optString("yongjin")));
            taoBaoGoods.setTkCommFee(new BigDecimal("0"));
            taoBaoGoods.setState(0);
    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;
    }
            listGoods.add(taoBaoGoods);
    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;
    }
            userType = itemGoods.optInt("istmall");
        }
        taoBaoShopDTO.setUserType(userType);
        taoBaoShopDTO.setListGoods(listGoods);
        return taoBaoShopDTO;
    }
    /**
     * 各大榜单
     *
     * @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()));
    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;// 复购榜
        String result = null;
        try {
            result = baseGet("https://openapi.dataoke.com/api/category/get-top100", params);
        } catch (Exception e) {
            result = baseGet("https://openapi.dataoke.com/api/category/get-top100", params);
        }
    /**
     * 各大榜单
     *
     * @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");
        String hotWords = null;
        JSONObject json = JSONObject.fromObject(result);
        if (json != null) {
            json = json.getJSONObject("data");
            if (json != null) {
                hotWords = json.optString("hotWords");
            }
        }
        return hotWords;
    }
            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;
    }
    /**
     * 高效转链
     *
     * @param auctionId
     * @param pid       void 返回类型
     * @throws
     * @Title: convertLink
     * @Description:
     */
    public static String convertLink(Long auctionId, String pid) {
        TaoKeAppInfo app = APP_KEYS[0];
        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()));
    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;
    }
        String result = null;
        try {
            result = baseGet("https://openapi.dataoke.com/api/tb-service/get-privilege-link", params);
        } catch (Exception e) {
            result = baseGet("https://openapi.dataoke.com/api/tb-service/get-privilege-link", params);
        }
    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;
    }
        System.out.println(result);
    /**
     * 各大榜单
     *
     * @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()));
        JSONObject json = JSONObject.fromObject(result);
        if (json != null) {
            json = json.getJSONObject("data");
            if (json != null) {
                return json.optString("couponClickUrl");
            }
        }
        return null;
    }
        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<>());
        }
    /**
     * 朋友圈
     *
     * @param pageId
     * @return
     */
    public static DaTaoKeGoodsResult getFriendsFircleList(String pageId, int pageSize) {
        DaTaoKeGoodsResult daTaoKeGoodsResult = new DaTaoKeGoodsResult();
        String hotWords = null;
        JSONObject json = JSONObject.fromObject(result);
        if (json != null) {
            json = json.getJSONObject("data");
            if (json != null) {
                hotWords = json.optString("hotWords");
            }
        }
        return hotWords;
    }
        TaoKeAppInfo app = getRandomApp();
        Map<String, String> params = new TreeMap<>();
        params.put("version", "v1.2.2");
        params.put("appKey", app.getAppKey());
        params.put("pageSize", pageSize + "");
        if (!StringUtil.isNullOrEmpty(pageId))
            params.put("pageId", pageId);
        params.put("sign", getSign(params, app.getAppSecret()));
    /**
     * 高效转链
     * @Title: convertLink
     * @Description:
     * @param auctionId
     * @param pid
     * void 返回类型
     * @throws
     */
    public static String convertLink(Long auctionId, String pid) {
        TaoKeAppInfo app = APP_KEYS[0];
        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 = baseGet("https://openapi.dataoke.com/api/goods/friends-circle-list", params);
        } catch (Exception e) {
            result = baseGet("https://openapi.dataoke.com/api/goods/friends-circle-list", 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;
    }
        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;
    }
    /**
     * 朋友圈
     * @param pageId
     * @return
     */
    public static DaTaoKeGoodsResult getFriendsFircleList(String pageId, int pageSize) {
        DaTaoKeGoodsResult daTaoKeGoodsResult = new DaTaoKeGoodsResult();
        TaoKeAppInfo app = getRandomApp();
        Map<String, String> params = new TreeMap<>();
        params.put("version", "v1.2.2");
        params.put("appKey", app.getAppKey());
        params.put("pageSize", pageSize + "");
        if (!StringUtil.isNullOrEmpty(pageId))
            params.put("pageId", pageId);
        params.put("sign", getSign(params, app.getAppSecret()));
    /**
     * 9.9包邮精选
     *
     * @param pageId
     * @return
     */
    public static DaTaoKeGoodsResult getNineGoodsList(Integer pageId, int pageSize) {
        DaTaoKeGoodsResult daTaoKeGoodsResult = new DaTaoKeGoodsResult();
        String result = null;
        try {
            result = HttpUtil.get("https://openapi.dataoke.com/api/goods/friends-circle-list", params, new HashMap<>());
        } catch (Exception e) {
            result = HttpUtil.get("https://openapi.dataoke.com/api/goods/friends-circle-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;
    }
        TaoKeAppInfo app = getRandomApp();
        Map<String, String> params = new TreeMap<>();
        params.put("version", "v1.2.2");
        params.put("appKey", app.getAppKey());
        params.put("pageSize", pageSize + "");
        params.put("nineCid", "-1");
    /**
     * 9.9包邮精选
     * @param pageId
     * @return
     */
    public static DaTaoKeGoodsResult getNineGoodsList(Integer pageId, int pageSize) {
        DaTaoKeGoodsResult daTaoKeGoodsResult = new DaTaoKeGoodsResult();
        TaoKeAppInfo app = getRandomApp();
        Map<String, String> params = new TreeMap<>();
        params.put("version", "v1.2.2");
        params.put("appKey", app.getAppKey());
        params.put("pageSize", pageSize + "");
        params.put("nineCid", "-1");
        if (pageId != null)
            params.put("pageId", pageId + "");
        params.put("sign", getSign(params, app.getAppSecret()));
        if (pageId != null)
            params.put("pageId", pageId + "");
        params.put("sign", getSign(params, app.getAppSecret()));
        String result = null;
        try {
            result = HttpUtil.get("https://openapi.dataoke.com/api/goods/nine/op-goods-list", params, new HashMap<>());
        } catch (Exception e) {
            result = HttpUtil.get("https://openapi.dataoke.com/api/goods/nine/op-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;
    }
        String result = null;
        try {
            result = baseGet("https://openapi.dataoke.com/api/goods/nine/op-goods-list", params);
        } catch (Exception e) {
            result = baseGet("https://openapi.dataoke.com/api/goods/nine/op-goods-list", 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;
    }
}
fanli/fanli.iml
@@ -39,7 +39,7 @@
    <orderEntry type="sourceFolder" forTests="false" />
    <orderEntry type="inheritedJdk" />
    <orderEntry type="library" name="javas" level="project" />
    <orderEntry type="module" module-name="utils" />
    <orderEntry type="library" name="Maven: com.yeshi:utils:0.0.1-SNAPSHOT" level="project" />
    <orderEntry type="library" name="Maven: com.opencsv:opencsv:4.3.2" level="project" />
    <orderEntry type="library" name="Maven: org.apache.commons:commons-text:1.3" level="project" />
    <orderEntry type="library" name="Maven: org.apache.commons:commons-collections4:4.2" level="project" />
fanli/src/main/java/com/yeshi/fanli/job/UpdateDaTaoKeJob.java
@@ -7,6 +7,13 @@
import javax.annotation.Resource;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import com.yeshi.fanli.entity.AppVersionInfo;
import com.yeshi.fanli.entity.SystemEnum;
import com.yeshi.fanli.entity.common.Config;
import com.yeshi.fanli.entity.system.ConfigKeyEnum;
import com.yeshi.fanli.util.StringUtil;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@@ -18,6 +25,7 @@
import com.yeshi.fanli.service.inter.taobao.ShareHotGoodsService;
import com.yeshi.goods.facade.service.DaTaoKeGoodsDetailV2Service;
import com.yeshi.fanli.util.Constant;
import org.yeshi.utils.AppMarketUtil;
import org.yeshi.utils.TimeUtil;
import com.yeshi.fanli.util.taobao.TaoBaoUtil;
import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
@@ -58,6 +66,15 @@
        }
    }
    //同步大淘客所有商品
    @XxlJob("dataoke-syncAllGoods")
    public ReturnT<String> doSyncJobNew(String param) throws Exception {
        daTaoKeGoodsDetailV2Service.startSyncGoods();
        return ReturnT.SUCCESS;
    }
    @Scheduled(cron = "0 0/10 * * * ? ")
    public void doUpdateJobNew() {
        if (!Constant.IS_TASK)
fanli/src/main/resource/env-dev/redis.properties
@@ -1,9 +1,9 @@
redis.addr=192.168.3.253
redis.port=6379
redis.auth=123456
#redis.addr=193.112.34.40
#redis.addr=192.168.3.253
#redis.port=6379
#redis.auth=weikou2014
#redis.auth=123456
redis.addr=193.112.34.40
redis.port=6379
redis.auth=weikou2014
redis.max_total=1024
redis.max_idle=200
redis.max_wait=10000
utils/src/test/java/com/yeshi/utils/AlipayTest.java
@@ -2,13 +2,11 @@
import com.alipay.api.AlipayApiException;
import org.yeshi.utils.alipay.AlipayUtil;
import org.yeshi.utils.entity.alipay.AlipayAppInfo;
import org.yeshi.utils.alipay.AlipayXcxUtil;
import org.yeshi.utils.entity.alipay.AlipayAppInfo;
import org.yeshi.utils.entity.alipay.AlipayCertInfo;
import org.yeshi.utils.entity.alipay.AlipayTransferAccount;
import org.yeshi.utils.entity.alipay.AlipayTransferInfo;
import org.yeshi.utils.exception.AlipayCommonException;
import org.yeshi.utils.exception.AlipayTransferException;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@@ -49,34 +47,33 @@
        }
    }
    private static void transfer() {
        AlipayTransferInfo info = new AlipayTransferInfo();
        new AlipayTransferAccount("2088812685461771");
        info.setAccount(new AlipayTransferAccount("贺小辉", "18581318252"));
        info.setMark("备注");
        info.setMoney(new BigDecimal("0.01"));
        info.setOrderTitle("标题");
        info.setOutBizNo("TEST-6");
        info.setPayerName("*");
        info.setBizScene(AlipayTransferInfo.AlipayBizSceneEnum.DIRECT_TRANSFER);
        info.setProductCode(AlipayTransferInfo.AlipayProductCodeEnum.STD_RED_PACKET);
        try {
            AlipayUtil.alipayFundTransUniTransfer(getAppInfo(), info, getCertInfo());
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (AlipayApiException e) {
            e.printStackTrace();
        } catch (AlipayTransferException e) {
            e.printStackTrace();
        }
    }
//    private static void transfer() {
//        AlipayTransferInfo info = new AlipayTransferInfo();
//        new AlipayTransferAccount("2088812685461771");
//        info.setAccount(new AlipayTransferAccount("贺小辉", "18581318252"));
//        info.setMark("备注");
//        info.setMoney(new BigDecimal("0.01"));
//        info.setOrderTitle("标题");
//        info.setOutBizNo("TEST-6");
//        info.setPayerName("*");
//        info.setBizScene(AlipayTransferInfo.AlipayBizSceneEnum.DIRECT_TRANSFER);
//        info.setProductCode(AlipayTransferInfo.AlipayProductCodeEnum.STD_RED_PACKET);
//        try {
//            AlipayUtil.alipayFundTransUniTransfer(getAppInfo(), info, getCertInfo());
//        } catch (FileNotFoundException e) {
//            e.printStackTrace();
//        } catch (AlipayApiException e) {
//            e.printStackTrace();
//        } catch (AlipayTransferException e) {
//            e.printStackTrace();
//        }
//
//    }
    private static void getBalance() {
        try {
            BigDecimal balance = AlipayUtil.getAccountBalance(getAppInfo(), getCertInfo(), "2088431211483485");
            BigDecimal balance = AlipayUtil.getAccountBalance(getAppInfo(), "2088431211483485");
            System.out.println(balance);
        } catch (FileNotFoundException e) {
        } catch (AlipayApiException e) {
            e.printStackTrace();
        } catch (AlipayCommonException e) {
@@ -87,7 +84,7 @@
    private static void getOrderDetail() {
        try {
            AlipayUtil.getOrderDetail(getAppInfo(), getCertInfo(), AlipayTransferInfo.AlipayProductCodeEnum.STD_RED_PACKET, AlipayTransferInfo.AlipayBizSceneEnum.DIRECT_TRANSFER, "TEST-5");
            AlipayUtil.getOrderDetail(getAppInfo(), AlipayTransferInfo.AlipayProductCodeEnum.STD_RED_PACKET, AlipayTransferInfo.AlipayBizSceneEnum.DIRECT_TRANSFER, "TEST-5");
        } catch (Exception e) {
            e.printStackTrace();
        }