admin
2022-09-16 70ebe043e6b62756be9e257fe954c747d46568b9
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
package com.yeshi.fanli.util.goods;
 
import net.sf.json.JSONObject;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.PostMethod;
import org.yeshi.utils.StringUtil;
 
import java.io.IOException;
import java.util.*;
 
/**
 * @author hxh
 * @title: CSJCPSApiUtil
 * @description: 穿山甲商品联盟
 * 文档:https://lf3-plat.pglstatp-toutiao.com/obj/union-platform/ef1828077907ddfacd07b35665ddd6c3.pdf
 * @date 2022/8/8 15:45
 */
public class CSJCPSApiUtil {
 
    private static String post(String url, String entity) {
        HttpClient client = new HttpClient();
        client.getHostConfiguration().setProxy("192.168.3.122", 8888);
        PostMethod method = new PostMethod(url);
        method.addRequestHeader("Content-Type", "application/json;charset=UTF-8");
        method.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
        method.setRequestBody(entity);
        try {
            client.executeMethod(method);
            return method.getResponseBodyAsString();
        } catch (HttpException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "";
    }
 
 
    private static String baseRequest(String path, JSONObject data, CSJAppInfo appInfo) {
        String url = "http://ecom.pangolin-sdk-toutiao.com" + path;
        com.alibaba.fastjson.JSONObject params = new com.alibaba.fastjson.JSONObject();
        params.put("app_id", appInfo.getAppId());
        params.put("timestamp", System.currentTimeMillis() / 1000);
        params.put("req_id", UUID.randomUUID().toString());
        params.put("data", data.toString());
        List<String> list = new ArrayList<>();
        for (Iterator<String> its = params.keySet().iterator(); its.hasNext(); ) {
            String key = its.next();
            list.add(key + "=" + params.get(key));
        }
        Collections.sort(list);
        String signStr = StringUtil.concat(list, "&") + appInfo.getSecureKey();
        String sign = StringUtil.Md5(signStr);
        params.put("sign", sign);
 
        return post(url, params.toString());
    }
 
    private static String baseRequest(String path, JSONObject data) {
        String appId = "5171164";
        String secureKey = "8a3061d15290ba953f4278a2251b03f4";
        return baseRequest(path, data, new CSJAppInfo(appId, secureKey));
    }
 
    public static void main(String[] args) {
        JSONObject data = new JSONObject();
        data.put("material_id", "10000");
        String result = baseRequest("/aggregate/h5", data);
        JSONObject root = JSONObject.fromObject(result);
        System.out.println(result);
        String h5 = root.optJSONObject("data").optString("h5_page_link");
        System.out.println(h5);
    }
 
 
}
 
class CSJAppInfo {
    private String appId;
    private String secureKey;
 
    public CSJAppInfo() {
    }
 
    public CSJAppInfo(String appId, String secureKey) {
        this.appId = appId;
        this.secureKey = secureKey;
    }
 
    public String getAppId() {
        return appId;
    }
 
    public void setAppId(String appId) {
        this.appId = appId;
    }
 
    public String getSecureKey() {
        return secureKey;
    }
 
    public void setSecureKey(String secureKey) {
        this.secureKey = secureKey;
    }
}