admin
2025-02-25 30d8e227e8d823b6c38c3b9c90ac2df03b63befe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
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, 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;
    }
 
}