Android微信支付获取二次签名Sign的方法
程序员文章站
2024-03-31 15:52:52
本文实例为大家分享了android微信支付获取二次签名sign的方法,供大家参考,具体内容如下
/**
* 获取sign签名
*
* @ret...
本文实例为大家分享了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 }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。