admin
2019-04-26 8e30aa7c1f0384f09278699318b4902b815b42a7
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
99
100
101
102
103
104
105
106
107
108
109
110
111
package com.yeshi.fanli.util.pinduoduo;
 
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
 
import org.yeshi.utils.HttpUtil;
 
import com.yeshi.fanli.util.StringUtil;
 
import net.sf.json.JSONArray;
 
public class PinDuoDuoApiUtil {
    private final static String CLIENT_ID = "9f6ee5ebd3b94c2080c4d51c2427e9fa";
    private final static String CLIENT_SECRET = "95e1f1904385664bf4b87d4b34de12f9f31c505d";
 
    private static String getSign(Map<String, String> map) {
        List<String> keyList = new ArrayList<>();
        Iterator<String> keys = map.keySet().iterator();
        while (keys.hasNext()) {
            String key = keys.next();
            keyList.add(key);
        }
        Collections.sort(keyList);
        String org = "";
        for (String key : keyList) {
            org += key + map.get(key);
        }
        return StringUtil.Md5(CLIENT_SECRET + org + CLIENT_SECRET).toUpperCase();
    }
 
    private static String baseRequest(Map<String, String> map) {
        map.put("client_id", CLIENT_ID);
        map.put("timestamp", System.currentTimeMillis() / 1000 + "");
        map.put("sign", getSign(map));
        Iterator<String> keys = map.keySet().iterator();
        String url = "https://gw-api.pinduoduo.com/api/router?";
        while (keys.hasNext()) {
            String key = keys.next();
            try {
                url += key + "=" + URLEncoder.encode(map.get(key), "UTF-8") + "&";
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        }
        if (url.endsWith("&"))
            url = url.substring(0, url.length() - 1);
 
        String result = HttpUtil.post(url);
        return result;
    }
 
    public static void searchGoods(String key) {
        Map<String, String> map = new HashMap<>();
        map.put("type", "pdd.ddk.goods.search");
        map.put("keyword", key);
        String result = baseRequest(map);
        System.out.println(result);
    }
 
    public static void convert(Long goodsId) {
        Map<String, String> map = new HashMap<>();
        map.put("type", "pdd.ddk.goods.promotion.url.generate");
        map.put("p_id", "8590899_61877633");
        JSONArray array = new JSONArray();
        array.add(goodsId);
        map.put("goods_id_list", array.toString());
        map.put("custom_parameters", "437032");
 
        String result = baseRequest(map);
        System.out.println(result);
    }
 
    public static void createPid() {
        Map<String, String> map = new HashMap<>();
        map.put("type", "pdd.ddk.goods.pid.generate");
        map.put("number", "1");
        String result = baseRequest(map);
        System.out.println(result);
    }
 
    public static void getOrders() {
        Map<String, String> map = new HashMap<>();
        map.put("type", "pdd.ddk.order.list.increment.get");
        map.put("start_update_time", System.currentTimeMillis() / 1000 - 60 * 60 + "");
        map.put("end_update_time", System.currentTimeMillis() / 1000 + "");
        String result = baseRequest(map);
        System.out.println(result);
    }
 
    /**
     * 获取商品详情
     * 
     * @param goodsId
     */
    public static void getGoodsDetail(Long goodsId) {
        JSONArray array = new JSONArray();
        array.add(goodsId);
        Map<String, String> map = new HashMap<>();
        map.put("type", "pdd.ddk.goods.detail");
        map.put("goods_id_list", array.toString());
        String result = baseRequest(map);
        System.out.println(result);
    }
 
}