微信支付HTTPS服务器证书验证

Linux服务器

1、 
生成随机串和签名: 
这里用的PHP

$mch_id = '1247485801'; // 商户号
$key = 'qwertyuiopasdfghjklzxcvbnm123456'; // 商户支付密钥
$nonce_str = strtoupper(md5('3123123131')); // 随机字符串

// 开始生成sign
$str = "mch_id=".$mch_id."&nonce_str=".$nonce_str."&key=".$key;
$sign = strtoupper(md5( $str ));

// 打印字符串和签名
echo $nonce_str;
echo "<br />";
echo $sign;
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

2、 
登陆要校验的服务器后台, 
通过shell创建 data.xml 
内容如下:

<xml>
  <mch_id>1247485801</mch_id>
  <nonce_str>D5EC8AFAEA782F14A4553DEC3509CDE6</nonce_str>
  <sign>D4F88BCAB5C5AC6BC6408A8A5FF7952F</sign>
</xml>
  • 1
  • 2
  • 3
  • 4
  • 5

3、 
开始验证证书!

curl -X POST -H 'content-type: application/xml' -d @/home/data.xml https://apitest.mch.weixin.qq.com/sandboxnew/pay/getsignkey
  • 1

4、 
校验结果

<xml>
  <mch_id>1247485801</mch_id>
  <nonce_str>D5EC8AFAEA782F14A4553DEC3509CDE6</nonce_str>
  <sign>D4F88BCAB5C5AC6BC6408A8A5FF7952F</sign>
</xml>
  • 1
  • 2
  • 3
  • 4
  • 5

成功会返回如上结果,反之失败!

猜你喜欢

转载自blog.csdn.net/dahuzix/article/details/80232482