签名需要规定参数顺序不能错。
一开始是这么写的
JSONObject param = new JSONObject();
param.put("idcard", user.getIdCard());
param.put("mobile", user.getPhone());
param.put("uid", user.getId());
param.put("username", user.getName());
期望得到的顺序应该是:
{"idcard":"370781199901230125","mobile":"156****2845","uid":1,"username":"张三"}
但是实际得到的顺序却是:
{"uid":1,"idcard":"370781199901230125","mobile":"156****2845","username":"张三"}
解决方法1:
JSONObject param = new JSONObject(true);
param.put("idcard", user.getIdCard());
param.put("mobile", user.getPhone());
param.put("username", user.getName());
param.put("uid", user.getId());
得到:{"idcard":"370781199901230125","mobile":"156****2845","username":"张三","uid":1}
解决方法2:
JSONObject param = new JSONObject(new LinkedHashMap<>());
param.put("idcard", user.getIdCard());
param.put("mobile", user.getPhone());
param.put("username", user.getName());
param.put("uid", user.getId());
同样得到:{"idcard":"370781199901230125","mobile":"156****2845","username":"张三","uid":1}
标签:username,顺序,uid,JSONObject,idcard,param,参数,user,put From: https://blog.51cto.com/u_16087786/8634195