wechatpay-apiv3 / wechatpay-php

微信支付 APIv3 的官方 PHP Library,同时也支持 APIv2
Apache License 2.0
475 stars 98 forks source link

微信支付平台证书异常 #122

Closed tashuo closed 11 months ago

tashuo commented 11 months ago

运行环境

- OS: CentOS 7.9.2009
- PHP: 7.4.5
- wechatpay-php: 1.4.8

描述你的问题现象

  1. 微信支付平台证书我是在本机(Mac)上使用CertificateDownloader.php工具生成并上传至服务器
  2. 在使用文档中native下单的示例代码时报错: UnexpectedValueException: Read the $certificate failed, please check it whether or nor correct in file /var/www/vendor/wechatpay/wechatpay/src/Util/PemUtil.php on line 90

商户api私钥apiclient_key.pem处理没问题,这个是微信支付平台证书的报错,请问是因为平台(mac -> linux)的原因导致证书处理异常吗?还是其他原因?

附生成的微信支付平台证书格式:

-----BEGIN CERTIFICATE-----
xxxx
xxxx
xxxx
-----END CERTIFICATE-----
TheNorthMemory commented 11 months ago

https://github.com/wechatpay-apiv3/wechatpay-php/blob/fbe8d7c2b3b367e42bf98caa0cce582b3205d427/README.md?plain=1#L90-L95

https://github.com/wechatpay-apiv3/wechatpay-php/blob/fbe8d7c2b3b367e42bf98caa0cce582b3205d427/src/Util/PemUtil.php#L86-L94

README上的L91行决定了L95行的解析,进而影响PemUtil.php:L90行,请检查你初始化参数平台证书路径是否带了file://协议。

tashuo commented 11 months ago

https://github.com/wechatpay-apiv3/wechatpay-php/blob/fbe8d7c2b3b367e42bf98caa0cce582b3205d427/README.md?plain=1#L90-L95

https://github.com/wechatpay-apiv3/wechatpay-php/blob/fbe8d7c2b3b367e42bf98caa0cce582b3205d427/src/Util/PemUtil.php#L86-L94

README上的L91行决定了L95行的解析,进而影响PemUtil.php:L90行,请检查你初始化参数平台证书路径是否带了file://协议。

加了file://前缀的,商户私钥证书都可以解析出来,后来直接用openssl_pkey_get_public(file_get_contents($platformCertificateFilePath))的方式可以正常解析,刚试回file://的形式突然又没问题了,多谢解答!