From aad0554cc7f18a6ec05e2e5e646b5e501d41617d Mon Sep 17 00:00:00 2001 From: yujian <yujian@123.com> Date: 星期三, 10 七月 2019 17:13:49 +0800 Subject: [PATCH] 冲突文件 --- fanli/src/main/java/com/yeshi/fanli/util/dataoke/DaTaoKeApiUtil.java | 64 +++++++++++++++++++++++++------ 1 files changed, 51 insertions(+), 13 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/util/dataoke/DaTaoKeApiUtil.java b/fanli/src/main/java/com/yeshi/fanli/util/dataoke/DaTaoKeApiUtil.java index 720fe82..9c9391e 100644 --- a/fanli/src/main/java/com/yeshi/fanli/util/dataoke/DaTaoKeApiUtil.java +++ b/fanli/src/main/java/com/yeshi/fanli/util/dataoke/DaTaoKeApiUtil.java @@ -12,6 +12,9 @@ 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; @@ -27,7 +30,6 @@ 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; @@ -61,13 +63,29 @@ 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 = HttpUtil.get(url); - if (result != null && result.startsWith("<html>")) + result = get(url); + if ((result != null && result.startsWith("<html>")) || StringUtil.isNullOrEmpty(result)) result = null; } catch (Exception e) { try { @@ -143,7 +161,16 @@ 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; } } @@ -390,21 +417,31 @@ 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")); + + /** + * 鑾峰彇搴楅摵涓嬪墠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")); @@ -429,10 +466,11 @@ userType = itemGoods.optInt("istmall"); } - taoBaoShopDTO.setListGoods(listGoods); taoBaoShopDTO.setUserType(userType); + taoBaoShopDTO.setListGoods(listGoods); return taoBaoShopDTO; } + class DaTaoKeResult { Date updateTime; -- Gitblit v1.8.0