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