本文实例为大家分享了Android微信支付获取二次签名Sign的方法,供大家参考,具体内容如下
private String genPayReq() {
// 获取参数的值
PayReq request = new PayReq();
request.appId = ConstantsMember.APP_ID;
request.partnerId = ConstantsMember.MCHID;
request.prepayId = mPrepayId;
request.packageValue = "Sign=WXPay";
request.nonceStr = DataUtil.getGuid();
request.timeStamp = DataUtil.getTimeStamp();
// 把参数的值传进去SortedMap集合里面
SortedMap<Object, Object> parameters = new TreeMap<Object, Object>();
// {appid=wx34df375d7dae8c90, noncestr=3BF34EF2CA4A462DB8D4EA48E785CDC3,
// package=Sign=WXPay, partnerid=1349967601,
// prepayid=wx2016070910354542c7155d4e0846850809, timestamp=1468031760}
parameters.put("appid", request.appId);
parameters.put("noncestr", request.nonceStr);
parameters.put("package", request.packageValue);
parameters.put("partnerid", request.partnerId);
parameters.put("prepayid", request.prepayId);
parameters.put("timestamp", request.timeStamp);
String characterEncoding = "UTF-8";
String mySign = createSign(characterEncoding, parameters);
System.out.println("我的签名是:" + mySign);
return mySign;
}
public static String createSign(String characterEncoding,
SortedMap<Object, Object> parameters) {
StringBuffer sb = new StringBuffer();
Set es = parameters.entrySet();// 所有参与传参的参数按照accsii排序(升序)
Iterator it = es.iterator();
while (it.hasNext()) {
@SuppressWarnings("rawtypes")
Map.Entry entry = (Map.Entry) it.next();
String k = (String) entry.getKey();
Object v = entry.getValue();
if (null != v && !"".equals(v) && !"sign".equals(k)
&& !"key".equals(k)) {
sb.append(k + "=" + v + "&");
}
}
sb.append("key=" + ConstantsMember.KEY); //KEY是商户秘钥
String sign = MD5Util.MD5Encode(sb.toString(), characterEncoding)
.toUpperCase();
return sign; // D3A5D13E7838E1D453F4F2EA526C4766
// D3A5D13E7838E1D453F4F2EA526C4766
}
您可能感兴趣的文章:微信 jssdk 签名错误invalid signature的解决方法C# 微信支付 wx.chooseWXPay 签名错误的解决方法基于微信签名signature获取(实例讲解)微信开发之使用java获取签名signature微信封装的调用微信签名包的类库详解IOS微信上Vue单页面应用JSSDK签名失败解决方案详解Vue开发微信H5微信分享签名失败问题解决方案.NET微信小程序用户数据的签名验证和解密代码VUE解决微信签名及SPA微信invalid signature问题(完美处理)微信js sdk invalid signature签名错误问题的解决方法分析