wechatpay-apiv3 / wechatpay-php

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

平台证书正常生成后,Fatal error: Uncaught UnexpectedValueException: Cannot load publicKey from(string), please take care about the \$thing input #98

Closed sunkangchina closed 2 years ago

sunkangchina commented 2 years ago

运行环境

No response

描述你的问题现象

Fatal error: Uncaught UnexpectedValueException: Cannot load publicKey from(string), please take care about the \$thing input. in vendor\wechatpay\wechatpay\src\Crypto\Rsa.php:165 Stack trace: #0

是否有明确错误提示,这提示不能加载publicKey, image

用的https://github.com/wechatpay-apiv3/wechatpay-php/blob/main/bin/README.md 生成平台证书。

sunkangchina commented 2 years ago

证书

-----BEGIN CERTIFICATE-----
这里的内容就不贴了
-----END CERTIFICATE-----
sunkangchina commented 2 years ago
openssl verify -verbose -CAfile ./CertTrustChain.pem ./WeChatPayPlatform.pem
输出
./WeChatPayPlatform.pem: OK
MichonneHsu commented 2 years ago

你是不看文档的?有你这样子引入的? 这样才对"file:///$absRootPath_cert",这个变量是你的文件地址

sunkangchina commented 2 years ago

file://.$绝对地址 或者

$platformCertificateFilePath =  file_get_contents($platformCertificateFilePath);
sunkangchina commented 2 years ago
$platformCertificateFilePath = 'file:///path/to/wechatpay/cert.pem';

这种写法让人无语。一般定义Path就是个路径,这里的file:// 后面跟绝对地址,这个手册需要优化下。 或者改成

$platformCertificateFilePath = '/path/to/wechatpay/cert.pem';
$platformCertificateFilePath =  file_get_contents($platformCertificateFilePath);
TheNorthMemory commented 2 years ago

建议看下README末尾的 PHP密钥/证书参数 相关说明 说明,加深一下对PHP这门语言的理解。

密钥/证书参数

相当一部分的 openssl 函数需要密钥或者证书参数。可通过以下途径获取这些参数。

证书

证书签名请求 (CSRs)

公钥/私钥

MichonneHsu commented 2 years ago

file://.$绝对地址 或者

$platformCertificateFilePath =  file_get_contents($platformCertificateFilePath);

支付SDK你写的?!并不是,那你要按照文档的格式去做

sunkangchina commented 2 years ago

后面2位回复多余。