微信扫码支付(3):获取验签秘钥

官方文档:https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=23_1&index=1

1.签名生成代码

import java.util.HashMap;
import java.util.Map;

public class WXTest {

  public static void main(String[] args) throws Exception {
    Map<String, String> params = new HashMap<String, String>();
    params.put("mch_id", "1**24****");//商户号
    params.put("nonce_str", WXPayUtil.generateNoncestr());//随机字符串
    System.out.println(WXPayUtil.generateSignature(params, "f29c41d964c211e980b998e7f44d86dd"));//打印签名
  }
}

2.用postman获得验签密钥

image

数据是以XML方式提交,sign就是上面代码打印值:

<xml>
    <nonce_str>hl7PokYEfq7Yh4cDCOmlTURMP0lSNZLi</nonce_str>
    <mch_id>1**24****</mch_id>
    <sign>6FDACB4ADA0246923DDB7FD1A797BEA7</sign>
</xml>

并以XML方式返回

<xml>
  <return_code><![CDATA[SUCCESS]]></return_code>
  <return_msg><![CDATA[ok]]></return_msg>
  <sandBox_signkey><![CDATA[************************]]></sandBox_signkey>
</xml>

sandBox_signkey对应的就是沙箱验签密钥。

相关文章

php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念