admin
2025-02-25 30d8e227e8d823b6c38c3b9c90ac2df03b63befe
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
package com.yeshi.fanli.util;
 
import net.sf.json.JSONObject;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;
import org.yeshi.utils.HttpUtil;
 
import java.io.IOException;
import java.util.*;
 
public class TuanYouUtil {
    private final static String APP_KEY = "appm_h598645363";
    private final static String APP_SECRET = "dec748b401b5df426fc0fa795e2704db";
 
    private static String getSign(Map<String, String> params) {
        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);
        return StringUtil.Md5(APP_SECRET + StringUtil.concat(list, "") + APP_SECRET);
    }
 
    private static Map<String, String> getBaseRequestParams() {
        Map<String, String> map = new HashMap<>();
        map.put("app_key", APP_KEY);
        map.put("timestamp", System.currentTimeMillis() + "");
        return map;
    }
 
    private static String request(String url, Map<String, String> map) {
 
        Iterator<String> its = map.keySet().iterator();
        NameValuePair[] params = new NameValuePair[map.keySet().size()];
 
        for (int p = 0; its.hasNext(); ++p) {
            String key = (String) its.next();
            NameValuePair np = new NameValuePair(key, (String) map.get(key));
            params[p] = np;
        }
 
        HttpClient client = new HttpClient();
        PostMethod method = new PostMethod(url);
        method.addRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        method.setRequestBody(params);
 
        try {
            client.executeMethod(method);
            return method.getResponseBodyAsString();
        } catch (HttpException var8) {
            var8.printStackTrace();
        } catch (IOException var9) {
            var9.printStackTrace();
        }
 
        return "";
    }
 
 
    public static String getAuthCode(String phone) {
        Map<String, String> map = getBaseRequestParams();
        map.put("platformId", "98645363");
        map.put("phone", phone);
        String sign = getSign(map);
        map.put("sign", sign);
 
        String result = request("https://mcs.czb365.com/services/v3/begin/getSecretCode", map);
        JSONObject data = JSONObject.fromObject(result);
        if (data.optInt("code") == 200) {
            return data.optString("result");
        }
        return "";
    }
 
 
}