Android微信支付获取二次签名Sign Android微信支付获取二次签名Sign的方法
志向远大 人气:0想了解Android微信支付获取二次签名Sign的方法的相关内容吗,志向远大在本文为您仔细讲解Android微信支付获取二次签名Sign的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:Android微信支付获取签名Sign,Android微信获取二次签名Sign,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 }
加载全部内容