首页 > 系统 > Android > 正文

Android微信支付获取二次签名Sign的方法

2019-12-12 04:29:30
字体:
来源:转载
供稿:网友

本文实例为大家分享了Android微信支付获取二次签名Sign的方法,供大家参考,具体内容如下

/**  * 获取sign签名  *   * @return  */ 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; } /**  * 微信支付签名算法sign  *   * @param characterEncoding  * @param parameters  * @return  */ 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 }

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持武林网。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表