From d1f26741bddf6f512d62c0100d42c52be8d37e76 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期六, 06 二月 2021 15:35:40 +0800 Subject: [PATCH] 工具类优化 --- fanli/src/main/java/com/yeshi/fanli/util/taobao/TaoBaoShopUtil.java | 197 ++++++++++++++++++++++++------------------------ 1 files changed, 98 insertions(+), 99 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/util/taobao/TaoBaoShopUtil.java b/fanli/src/main/java/com/yeshi/fanli/util/taobao/TaoBaoShopUtil.java index f8fc372..a6d184a 100644 --- a/fanli/src/main/java/com/yeshi/fanli/util/taobao/TaoBaoShopUtil.java +++ b/fanli/src/main/java/com/yeshi/fanli/util/taobao/TaoBaoShopUtil.java @@ -1,99 +1,98 @@ -package com.yeshi.fanli.util.taobao; - -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.net.URLEncoder; -import java.util.List; - -import org.jsoup.Jsoup; -import org.jsoup.nodes.Document; -import org.jsoup.nodes.Element; - -import com.yeshi.fanli.entity.taobao.TaoBaoShopInfo; -import org.yeshi.utils.HttpUtil; - -import net.sf.json.JSONObject; - -public class TaoBaoShopUtil { - - public static TaoBaoShopInfo getTaoBaoShopInfo(String title, Long sellerId, Long auctionId) { - int page = 1; - TaoBaoShopInfo shop = null; - while (shop == null && page < 4) { - List<TaoBaoShopInfo> list = TaoKeApiUtil.searchShop(title, page); - shop = selectShop(sellerId, list); - page++; - } - - if (shop == null) { - JSONObject data = new JSONObject(); - data.put("itemNumId", auctionId + ""); - String url = ""; - try { - url = String.format( - "https://acs.m.taobao.com/h5/mtop.taobao.detail.getdetail/6.0/?data=%s&qq-pf-to=pcqq.group", - URLEncoder.encode(data.toString(), "UTF-8")); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } - - try { - String result = HttpUtil.get(url); - JSONObject resultObj = JSONObject.fromObject(result); - JSONObject seller = resultObj.optJSONObject("data").optJSONObject("seller"); - shop = new TaoBaoShopInfo(); - shop.setPictureUrl("http:" + seller.optString("shopIcon")); - shop.setSellerNick(seller.optString("sellerNick")); - shop.setShopTitle(seller.optString("shopName")); - shop.setShopType(seller.optString("shopType")); - shop.setShopUrl(seller.optString("shopUrl")); - shop.setUserId(seller.optLong("userId")); - } catch (Exception e) { - - } - - } - - if (shop != null) { - if ("C".equalsIgnoreCase(shop.getShopType())) - shop.setShopType("http://hcj-1255749512.file.myqcloud.com/resource/app/shop_icon_tb.png"); - else - shop.setShopType("http://hcj-1255749512.file.myqcloud.com/resource/app/shop_icon_tm.png"); - } - - return shop; - } - - private static TaoBaoShopInfo selectShop(Long sellerId, List<TaoBaoShopInfo> list) { - if (sellerId == null) - return null; - if (list != null) - for (TaoBaoShopInfo shop : list) - if (shop != null && shop.getUserId() != null && shop.getUserId().longValue() == sellerId.longValue()) - return shop; - return null; - } - - public static TaoBaoShopInfo getTaoBaoShopInfoFromDaTaoKe(Long sellerId) throws Exception { - - TaoBaoShopInfo shopInfo = new TaoBaoShopInfo(); - Document doc = Jsoup.connect("http://dataoke.yeshitv.com/index.php?r=p/shop&seller_id=" + sellerId) - .userAgent( - "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.92 Mobile Safari/537.36") - .get(); - Element goodsShop = doc.getElementsByClass("goods_shop").get(0); - String imgSrc = goodsShop.getElementsByTag("img").get(0).attr("src"); - String title = goodsShop.getElementsByClass("text").get(0).getElementsByTag("h3").get(0).text(); - shopInfo.setPictureUrl(imgSrc); - shopInfo.setSellerNick(title); - shopInfo.setShopTitle(title); - shopInfo.setUserId(sellerId); - if (goodsShop.getElementsByClass("text").get(0).toString().contains("icon-detail_tmall")) { - shopInfo.setShopType("B"); - } else { - shopInfo.setShopType("C"); - } - return shopInfo; - } - -} +package com.yeshi.fanli.util.taobao; + +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.util.List; + +import org.jsoup.Jsoup; +import org.jsoup.nodes.Document; +import org.jsoup.nodes.Element; + +import com.yeshi.common.entity.taobao.TaoBaoShopInfo; +import org.yeshi.utils.HttpUtil; + +import net.sf.json.JSONObject; + +public class TaoBaoShopUtil { + + public static TaoBaoShopInfo getTaoBaoShopInfo(String title, Long sellerId, Long auctionId) { + int page = 1; + TaoBaoShopInfo shop = null; + while (shop == null && page < 4) { + List<TaoBaoShopInfo> list = TaoKeApiUtil.searchShop(title, page); + shop = selectShop(sellerId, list); + page++; + } + + if (shop == null) { + JSONObject data = new JSONObject(); + data.put("itemNumId", auctionId + ""); + String url = ""; + try { + url = String.format( + "https://acs.m.taobao.com/h5/mtop.taobao.detail.getdetail/6.0/?data=%s&qq-pf-to=pcqq.group", + URLEncoder.encode(data.toString(), "UTF-8")); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + + try { + String result = HttpUtil.get(url); + JSONObject resultObj = JSONObject.fromObject(result); + JSONObject seller = resultObj.optJSONObject("data").optJSONObject("seller"); + shop = new TaoBaoShopInfo(); + shop.setPictureUrl("http:" + seller.optString("shopIcon")); + shop.setSellerNick(seller.optString("sellerNick")); + shop.setShopTitle(seller.optString("shopName")); + shop.setShopType(seller.optString("shopType")); + shop.setShopUrl(seller.optString("shopUrl")); + shop.setUserId(seller.optLong("userId")); + } catch (Exception e) { + + } + + } + + if (shop != null) { + if ("C".equalsIgnoreCase(shop.getShopType())) + shop.setShopType("http://hcj-1255749512.file.myqcloud.com/resource/app/shop_icon_tb.png"); + else + shop.setShopType("http://hcj-1255749512.file.myqcloud.com/resource/app/shop_icon_tm.png"); + } + + return shop; + } + + private static TaoBaoShopInfo selectShop(Long sellerId, List<TaoBaoShopInfo> list) { + if (sellerId == null) + return null; + if (list != null) + for (TaoBaoShopInfo shop : list) + if (shop != null && shop.getUserId() != null && shop.getUserId().longValue() == sellerId.longValue()) + return shop; + return null; + } + + public static TaoBaoShopInfo getTaoBaoShopInfoFromDaTaoKe(Long sellerId) throws Exception { + + TaoBaoShopInfo shopInfo = new TaoBaoShopInfo(); + Document doc = Jsoup.connect("http://dataoke.yeshitv.com/index.php?r=p/shop&seller_id=" + sellerId) + .userAgent( + "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.92 Mobile Safari/537.36") + .get(); + Element goodsShop = doc.getElementsByClass("goods_shop").get(0); + String imgSrc = goodsShop.getElementsByTag("img").get(0).attr("src"); + String title = goodsShop.getElementsByClass("text").get(0).getElementsByTag("h3").get(0).text(); + shopInfo.setPictureUrl(imgSrc); + shopInfo.setSellerNick(title); + shopInfo.setShopTitle(title); + shopInfo.setUserId(sellerId); + if (goodsShop.getElementsByClass("text").get(0).toString().contains("icon-detail_tmall")) { + shopInfo.setShopType("B"); + } else { + shopInfo.setShopType("C"); + } + return shopInfo; + } + +} -- Gitblit v1.8.0