admin
2025-02-20 f537abe9f3646c739beaf15076246a2f71a347e9
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
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();
    }
}