Post请求参数排序
/**
* 对提交的参数转正Map后转正TreeMap进⾏排序
* @return
*/
// public static Map<String, String> buildOrderParamMap(String uuid, boolean rsa2,String userName,String Password) { public static void buildOrderParamMap(String uuid, boolean rsa2,String userName,String Password) {
Map<String, String> keyValues = new HashMap<String, String>();
// orderNo 只能是数字不能是⽂字描述
keyValues.put("uuid", uuid);
keyValues.put("account", userName);
keyValues.put("password", Password);
Log.e("OKGo⽹络请求测试post1",String());
// Map<Integer, Person> map = new HashMap<Integer, Person>();
TreeMap treemap = new TreeMap(keyValues);
Log.e("OKGo⽹络请求测试post1",String());
buildOrderParam(treemap);
// return keyValues;
}
/**
* md5签名
*/
public static void buildOrderParam(Map<String, String> map) {
List<String> keys = new ArrayList<String>(map.keySet());
StringBuilder sb = new StringBuilder();
for (int i = 0; i < keys.size() - 1; i++) {
String key = (i);
String value = (key);
sb.append(buildKeyValue(key, value, true));
sb.append("&");
}
String tailKey = (keys.size() - 1);
String tailValue = (tailKey);
sb.append(buildKeyValue(tailKey, tailValue, true));
// Log.e("OKGo⽹络请求测试post1",sb.append("&key=Gemar").toString());
String md5str = sb.append("&key=Gemar").toString();
Log.e("OKGo⽹络请求测试post1111",md5str);
md5strToken = MD5Str(md5str);
Log.e("OKGo⽹络请求测试post1",String());
// return md5strToken;
}
/**
* 拼接键值对
* 拼接键值对
*
*/
private static String buildKeyValue(String key, String value, boolean isEncode) { StringBuilder sb = new StringBuilder();
sb.append(key);
sb.append("=");
if (isEncode) {
手机总是闪退是什么原因try {
sb.de(value, "UTF-8"));
} catch (UnsupportedEncodingException e) {
sb.append(value);
}
} else {
sb.append(value);
}
String();
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论