android 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",keyValues.toString());
//        Map<Integer, Person> map = new HashMap<Integer, Person>();
TreeMap treemap = new TreeMap(keyValues);
Log.e("OKGo网络请求测试post1",treemap.toString());
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 = keys.get(i);
String value = map.get(key);
sb.append(buildKeyValue(key, value, true));
sb.append("&");
}
String tailKey = keys.get(keys.size() - 1);
String tailValue = map.get(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 = Md5utils.getMD5Str(md5str);
Log.e("OKGo网络请求测试post1",md5strToken.toString());
//        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.append(URLEncoder.encode(value, "UTF-8"));
} catch (UnsupportedEncodingException e) {
sb.append(value);
}
} else {
sb.append(value);
}
return sb.toString();
}

人已赞赏
Android文章

Android图片滚动,加入自动播放功能,使用自定义属性实现,霸气十足!

2020-3-19 22:41:39

Android文章

Android实现图片滚动控件,含页签功能,让你的应用像淘宝一样炫起来

2020-3-19 23:43:06

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
有新消息 消息中心
搜索