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;
|
}
|
}
|