PHP8.0,wechatpaySDK1.4 ,guzzle7.9,thinkphp8.1.2, 安装正常,APIv2已经在使用多年正常,现在开始使用开发APIv3。
已经申请了“微信支付公钥”并开始灰度转换 4月24结束。 刚开始调试APIv3。 使用安装文档“SDK&开发工具”->“使用PHP SDK” ->“使用微信公钥初始化”程序, 发送native 。已经将该程序中的参数都已替代成商户参数。 发送后出现“[error] [200]Cannot found the serial(`5A931B056B4AD8704EFEFABF26FFDE**********`)'s configuration, which's from the response(header:Wechatpay-Serial), your's PUB_KEY_ID_011601011800202504140035**********.”。 这个serial是平台证书的序列号。
平台证书到微信支付公钥的灰度转换没有结束,转换后能正常吗,是转换的问题吗。发送程序中已经使用微信公鈅初始化程序,为啥微信后台还指向平台证书?
public function ttt(){
// 设置参数
// 商户号
$merchantId = '16********';
// 从本地文件中加载「商户API私钥」,「商户API私钥」会用来生成请求的签名
$merchantPrivateKeyFilePath = 'file://../app/controller/api/cert/apiclient_key.pem';
$merchantPrivateKeyInstance = Rsa::from($merchantPrivateKeyFilePath, Rsa::KEY_TYPE_PRIVATE);
// 「商户API证书」的「证书序列号」
$merchantCertificateSerial = '2CEB4187930D****************************'; //证书号
//从本地文件中加载「微信支付公钥」,用来验证微信支付应答的签名
$platformPublicKeyFilePath = 'file://../app/controller/api/cert/pub_key.pem';
$twoPlatformPublicKeyInstance = Rsa::from($platformPublicKeyFilePath, Rsa::KEY_TYPE_PUBLIC);
// 「微信支付公钥」的「微信支付公钥ID」
// 需要在 商户平台 -> 账户中心 -> API安全 查询
$platformPublicKeyId = 'PUB_KEY_ID_01160*****************************';
// 构造一个 APIv3 客户端实例
$instance = Builder::factory([
'mchid' => $merchantId,
'serial' => $merchantCertificateSerial,
'privateKey' => $merchantPrivateKeyInstance,
'certs' => [
$platformPublicKeyId => $twoPlatformPublicKeyInstance,
],
]);
// 以 Native 支付为例,发送请求
$resp = $instance
->chain('v3/pay/transactions/native')
->post(['json' => [
'mchid' => '16**********',
'out_trade_no' => '22345612177525012014070332331',
'appid' => 'wxc63a48************',
'description' => 'Image形象店',
'notify_url' => 'https://*******.com/Mpwxpay/notifyUrl',
'amount' => [
'total' => 1,
'currency' => 'CNY'
],
]]) ;
echo $resp->getBody(), PHP_EOL;
}
}
切换期间需要同时配置平台证书和平台公钥,你请求不携带平台公钥ID就不会是以公钥模式返回