package com.yeshi.buwan.util.tb;
|
|
import com.yeshi.buwan.dto.tb.TaoKeAppInfo;
|
import net.sf.json.JSONObject;
|
import org.yeshi.utils.HttpUtil;
|
import org.yeshi.utils.StringUtil;
|
|
import java.util.*;
|
|
public class DaTaoKeApiUtil {
|
|
final static String APP_KEY = "5cf764636d373";
|
final static String APP_KEY_SECRET = "5ea3c24900743f3aa531fb264f9824f2";
|
|
final static String APP_KEY_2 = "5cf75b0f2c0e4";
|
final static String APP_KEY_SECRET_2 = "b14f1fa115129a447937ca998b311d1e";
|
|
final static TaoKeAppInfo[] APP_KEYS = new TaoKeAppInfo[]{new TaoKeAppInfo(APP_KEY, APP_KEY_SECRET),
|
new TaoKeAppInfo(APP_KEY_2, APP_KEY_SECRET_2)};
|
|
public static String convertLink(Long auctionId, String pid) {
|
TaoKeAppInfo app = APP_KEYS[0];
|
Map<String, String> params = new TreeMap<>();
|
params.put("version", "v1.1.1");
|
params.put("goodsId", auctionId + "");
|
params.put("pid", pid);
|
params.put("appKey", app.getAppKey());
|
params.put("sign", getSign(params, app.getAppSecret()));
|
|
String result = null;
|
try {
|
result = HttpUtil.get("https://openapi.dataoke.com/api/tb-service/get-privilege-link", params,
|
new HashMap<>());
|
} catch (Exception e) {
|
result = HttpUtil.get("https://openapi.dataoke.com/api/tb-service/get-privilege-link", params,
|
new HashMap<>());
|
}
|
|
System.out.println(result);
|
|
JSONObject json = JSONObject.fromObject(result);
|
if (json != null) {
|
json = json.getJSONObject("data");
|
if (json != null) {
|
return StringUtil.isNullOrEmpty(json.optString("couponClickUrl"))?json.optString("itemUrl"):json.optString("couponClickUrl");
|
}
|
}
|
return null;
|
}
|
|
|
private static String getSign (Map < String, String > map, String secretKey){
|
if (map.size() == 0) {
|
return "";
|
}
|
StringBuffer sb = new StringBuffer("");
|
Set<String> keySet = map.keySet();
|
Iterator<String> iter = keySet.iterator();
|
while (iter.hasNext()) {
|
String key = iter.next();
|
sb.append("&" + key + "=" + map.get(key));
|
}
|
sb.deleteCharAt(0);
|
String signStr = "";
|
signStr = sb.toString() + "&key=" + secretKey;
|
return StringUtil.Md5(signStr).toUpperCase();
|
}
|
}
|