| | |
| | | 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 com.yeshi.fanli.entity.taobao.TaoKeAppInfo;
|
| | | import com.yeshi.fanli.entity.taobao.dataoke.DaTaoKeDetail;
|
| | | import com.yeshi.fanli.entity.taobao.dataoke.DaTaoKeDetailV2;
|
| | | import com.yeshi.fanli.log.LogHelper;
|
| | | import com.yeshi.fanli.util.MoneyBigDecimalUtil;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | |
|
| | |
| | |
|
| | | static Gson gson = new Gson();
|
| | |
|
| | | 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;
|
| | | }
|
| | |
|
| | | 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);
|
| | | String result = request(url);
|
| | |
|
| | | JSONObject resultJson = JSONObject.fromObject(result);
|
| | | System.out.println(resultJson);
|
| | | JSONArray array = resultJson.optJSONArray("result");
|
| | |
| | |
|
| | | 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.setUserType(0);
|
| | |
|
| | | // 商品信息
|
| | | taoBaoShopDTO = getDynamicShopGoods(brandId, taoBaoShopDTO);
|
| | |
|
| | | break;
|
| | | }
|
| | | }
|
| | |
| | | params.put("version", "v1.0.0");
|
| | | params.put("appKey", app.getAppKey());
|
| | | params.put("pageSize", 200 + "");
|
| | | // params.put("sort", "1");
|
| | | // params.put("sort", "1");
|
| | | if (!StringUtil.isNullOrEmpty(pageId)) {
|
| | | params.put("pageId", pageId);
|
| | | }
|
| | |
| | | return daTaoKeGoodsResult;
|
| | | }
|
| | |
|
| | | public static DaTaoKeGoodsResult search(String key, List<Integer> cidList, int page, int pageSize, int sort) {
|
| | | public static DaTaoKeDetailV2 getGoodsDetail(Long id) {
|
| | | TaoKeAppInfo app = getRandomApp();
|
| | | DaTaoKeGoodsResult daTaoKeGoodsResult = new DaTaoKeGoodsResult();
|
| | | Map<String, String> params = new TreeMap<>();
|
| | | params.put("version", "v1.0.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 gson.fromJson(dataJson.toString(), DaTaoKeDetailV2.class);
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | | public static DaTaoKeGoodsResult search(String key, List<Integer> cidList, BigDecimal priceLowerLimit,
|
| | | BigDecimal priceUpperLimit, int page, int pageSize, int sort) {
|
| | |
|
| | | TaoKeAppInfo app = getRandomApp();
|
| | | DaTaoKeGoodsResult daTaoKeGoodsResult = new DaTaoKeGoodsResult();
|
| | | Map<String, String> params = new TreeMap<>();
|
| | | params.put("version", "v1.0.0");
|
| | | params.put("appKey", app.getAppKey());
|
| | | params.put("pageSize", 200 + "");
|
| | | 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) {
|
| | |
| | | params.put("sign", getSign(params, app.getAppSecret()));
|
| | | String result = HttpUtil.get("https://openapi.dataoke.com/api/goods/get-dtk-search-goods", params,
|
| | | new HashMap<>());
|
| | |
|
| | | JSONObject json = JSONObject.fromObject(result);
|
| | | JSONObject dataJson = json.optJSONObject("data");
|
| | | if (dataJson != null) {
|
| | |
| | | return StringUtil.Md5(signStr).toUpperCase();
|
| | | }
|
| | |
|
| | | 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;
|
| | | /**
|
| | | * 获取店铺下前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 >= 2) {
|
| | | break;
|
| | | }
|
| | | JSONObject itemGoods = arrayGoods.optJSONObject(i);
|
| | |
|
| | | TaoBaoGoodsBrief taoBaoGoods = new TaoBaoGoodsBrief();
|
| | | taoBaoGoods.setAuctionId(itemGoods.optLong("goodsid"));
|
| | | taoBaoGoods.setBiz30day(itemGoods.optInt("xiaoliang"));
|
| | |
| | |
|
| | | userType = itemGoods.optInt("istmall");
|
| | | }
|
| | | taoBaoShopDTO.setListGoods(listGoods);
|
| | | taoBaoShopDTO.setUserType(userType);
|
| | | taoBaoShopDTO.setListGoods(listGoods);
|
| | | return taoBaoShopDTO;
|
| | | }
|
| | |
|
| | | public static int RANK_TYPE_TIME = 1;// 实时
|
| | | public static int RANK_TYPE_DAY = 2;// 全天榜
|
| | | public static int RANK_TYPE_HOT = 3;// 热推榜
|
| | |
|
| | | /**
|
| | | * 各大榜单
|
| | | * |
| | | * @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.0.0");
|
| | | params.put("appKey", app.getAppKey());
|
| | | params.put("rankType", type + "");
|
| | | if (cid != null)
|
| | | params.put("cid", cid + "");
|
| | | params.put("sign", getSign(params, app.getAppSecret()));
|
| | | String 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");
|
| | |
|
| | | List<DaTaoKeDetailV2> list = new ArrayList<>();
|
| | | for (int i = 0; i < array.size(); i++) {
|
| | | JSONObject itemData = array.optJSONObject(i);
|
| | | DaTaoKeDetailV2 item = gson.fromJson(itemData.toString(), DaTaoKeDetailV2.class);
|
| | | item.setCouponConditions(itemData.optString("quanUsageCondition"));
|
| | | item.setShopType(itemData.optInt("istmall"));
|
| | | item.setOriginalPrice(new BigDecimal(itemData.optString("originPrice")));
|
| | | item.setMainPic(itemData.optString("pic"));
|
| | | list.add(item);
|
| | | }
|
| | | daTaoKeGoodsResult.setGoodsList(list);
|
| | | }
|
| | | return daTaoKeGoodsResult;
|
| | |
|
| | | }
|
| | |
|
| | | class DaTaoKeResult {
|
| | | Date updateTime;
|
| | | List<DaTaoKeDetail> dataList;
|