admin
2023-04-12 651f2856e9ae10aacbfb8327d967aacbb6d58333
fanli/src/main/java/com/yeshi/fanli/util/taobao/TaoBaoShopUtil.java
@@ -1,98 +1,98 @@
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;
   }
}
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, String 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;
   }
}