From 0f9a0a76b170bceac867dd5cd009e518ac6646e4 Mon Sep 17 00:00:00 2001 From: yujian <yujian@163.com> Date: 星期三, 20 十一月 2019 11:04:07 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/div' into div --- fanli/src/main/java/com/yeshi/fanli/util/taobao/TaoBaoUtil.java | 48 ++++++++++++++++++++++++++++++------------------ 1 files changed, 30 insertions(+), 18 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/util/taobao/TaoBaoUtil.java b/fanli/src/main/java/com/yeshi/fanli/util/taobao/TaoBaoUtil.java index 471c85b..5705127 100644 --- a/fanli/src/main/java/com/yeshi/fanli/util/taobao/TaoBaoUtil.java +++ b/fanli/src/main/java/com/yeshi/fanli/util/taobao/TaoBaoUtil.java @@ -1844,6 +1844,12 @@ return url; } + /** + * 鑾峰彇娣樺疂鐨勫晢鍝佽鎯� + * + * @param actionId + * @return + */ public static TaoBaoGoodsBrief getSimpleGoodsBrief(Long actionId) { JSONObject data = new JSONObject(); data.put("itemNumId", actionId + ""); @@ -1855,6 +1861,7 @@ } catch (UnsupportedEncodingException e) { e.printStackTrace(); } + HttpClient client = new HttpClient(); GetMethod gm = new GetMethod(url); String result = null; @@ -1879,25 +1886,30 @@ JSONObject resultOBJ = JSONObject.fromObject(result); if (resultOBJ.optJSONObject("data") != null) { data = resultOBJ.optJSONObject("data"); - JSONObject item = data.optJSONObject("item"); - JSONObject seller = data.optJSONObject("seller"); - TaoBaoGoodsBrief goods = new TaoBaoGoodsBrief(); - goods.setTitle(item.optString("title")); - goods.setAuctionId(item.optLong("itemId")); - goods.setTitle(item.optString("title")); - if (item.optJSONArray("images") != null && item.optJSONArray("images").size() > 0) { - String picture = item.optJSONArray("images").optString(0); - goods.setPictUrl(picture.startsWith("http") ? picture : "https:" + picture); + if (data != null) { + JSONObject item = data.optJSONObject("item"); + if (item != null) { + JSONObject seller = data.optJSONObject("seller"); + TaoBaoGoodsBrief goods = new TaoBaoGoodsBrief(); + goods.setTitle(item.optString("title")); + goods.setAuctionId(item.optLong("itemId")); + goods.setTitle(item.optString("title")); + if (item.optJSONArray("images") != null && item.optJSONArray("images").size() > 0) { + String picture = item.optJSONArray("images").optString(0); + goods.setPictUrl(picture.startsWith("http") ? picture : "https:" + picture); + } + if (seller != null) { + goods.setSellerId(seller.optLong("shopId")); + String shopType = seller.optString("shopType"); + if ("B".equalsIgnoreCase(shopType)) { + goods.setUserType(1); + } else + goods.setUserType(0); + goods.setShopTitle(seller.optString("shopName")); + } + return goods; + } } - goods.setSellerId(seller.optLong("shopId")); - String shopType = seller.optString("shopType"); - if ("B".equalsIgnoreCase(shopType)) { - goods.setUserType(1); - } else - goods.setUserType(0); - - goods.setShopTitle(seller.optString("shopName")); - return goods; } return null; } -- Gitblit v1.8.0