// 5. 初始化微信支付
$this->instance = Builder::factory([
'mchid' => $this->mchid,
'serial' => $this->serialNo,
'privateKey' => $merchantPrivateKey,
'certs' => [
// $platformCertificateSerial => $onePlatformPublicKeyInstance, // 平台证书
$platformCertificateSerialOrPublicKeyId => $wechatpayPublicKey, // 支付公钥
],
'secret' => $this->apiV3Key,
]);
$resp = $this->instance->chain('v3/pay/transactions/native')
->post(['json' => [
'appid' => $this->appid,
'mchid' => $this->mchid,
'description' => $params['description'],
'out_trade_no' => $params['out_trade_no'],
'notify_url' => $params['notify_url'],
'amount' => [
'total' => $params['amount'],
'currency' => 'CNY'
],
],
'headers' => [
'Accept' => 'application/json'
]
]);
使用的php sdk 1.4版本从平台证书转换为支付公钥。post请求时会抛出异常
Cannot found the serial(`1F81026B4B*******************`)'s configuration, which's from the response(header:Wechatpay-Serial), your's PUB_KEY_ID_011340*******************. 200 OK
微信平台后台已经打开了灰度开始切换公钥
phpSDK需要在调接口时额外在请求头增加wechatpay-serial,值要传公钥ID,这样微信给你应答时就全用公钥了
切换期间需要同时配置平台证书和平台公钥