From f111025b1c2c8bb95e64f4f9e23c09813b7938d2 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期二, 24 十二月 2019 10:53:30 +0800 Subject: [PATCH] 维权日志添加,京东短链解析添加缓存 --- fanli/src/main/java/com/yeshi/fanli/util/taobao/TaoBaoUtil.java | 50 +++++++++++++++++++++++++++++++------------------- 1 files changed, 31 insertions(+), 19 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..cf4c61d 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; } @@ -2133,7 +2145,7 @@ Matcher m = r.matcher(str); while (m.find()) { String group = m.group(0); - if (!StringUtil.isNullOrEmpty(group)) + if (!StringUtil.isNullOrEmpty(group) && group.length() >= 10) return group; } return null; -- Gitblit v1.8.0