解决 PHP 项目调用微信支付 API 概率失败问题
后知后觉 暂无评论

公司一 PHP 项目调用支付宝接口正常,调用微信支付接口却出现概率性失败,项目环境为 PHP + NGINX + CentOS7 。

问题

微信报错信息如下:

请求发生错误:NSS: client certificate not found (nickname not specified)

支付宝对接则完全正常,无报错问题。

查看报错信息初步判断为客户端问题,几经排查后排除嫌疑。

使用 curl 命令测试会提示以下错误

errno:35, error: SSL Connect Error

使用抓包工具对成功和失败的请求进行分析

* About to connect() to api.mch.weixin.qq.com port 443 (#0)
* Trying 140.207.69.102… connected
* Connected to api.mch.weixin.qq.com (140.207.69.102) port 443 (#0)
* Initializing NSS with certpath: sql:/etc/pki/nssdb
* CAfile: /etc/pki/tls/certs/ca-bundle.crt
CApath: none
* NSS: client certificate not found (nickname not specified)
* SSL connection using TLS_DHE_RSA_WITH_AES_256_CBC_SHA
* Server certificate:
* subject: CN=payapp.weixin.qq.com,OU=R&D,O=Tencent Technology (Shenzhen) Company Limited,L=shenzhen,ST=guangdong,C=CN
* start date: 4月 28 00:00:00 2015 GMT
* expire date: 4月 27 23:59:59 2016 GMT
* common name: payapp.weixin.qq.com
* issuer: CN=GeoTrust SSL CA – G2,O=GeoTrust Inc.,C=US
> POST /pay/unifiedorder HTTP/1.1
> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.16.2.3 Basic ECC zlib/1.2.3 libidn/1.18 libssh2/1.4.2
> Host: api.mch.weixin.qq.com
> Accept: */*
* About to connect() to api.mch.weixin.qq.com port 443 (#0)
* Trying 140.207.69.102… connected
* Connected to api.mch.weixin.qq.com (140.207.69.102) port 443 (#0)
* Initializing NSS with certpath: sql:/etc/pki/nssdb
* CAfile: /etc/pki/tls/certs/ca-bundle.crt
CApath: none
* NSS error -5990
* Closing connection #0
* SSL connect error
curl: (35) SSL connect error

探索

谷歌后发现部分同样问题的案例后找到解决办法:

升级网络安全服务组件 (Mozilla Network Security Services) 即可。

# For RadHat
sudo yum update nss
小贴士:只升级此组件即可。
# For Debian
sudo apt install nss
小贴士:只升级此组件即可。

附录

参考链接

本文撰写于一年前,如出现图片失效或有任何问题,请在下方留言。博主看到后将及时修正,谢谢!
禁用 / 当前已拒绝评论,仅可查看「历史评论」。