一、问题
当平台首付通使用的是平台证书模式,提示公钥不存在 的错误,如图

二、修复
1. 修改代码
public function get()
{
$is = $this->isService ? 'service_payment':'payment'; //如果是自动分账 或者 普通支付但是用的是v3支付 获取公钥
if ($this->app['config']['type'] == 'wechat') {
$public_key = $this->app['config'][$is]['pay_weixin_public_key'];
} else {
$public_key = $this->app['config'][$is]['pay_routine_public_key'];
}
if ($public_key && ($this->isService || $this->app['config']['is_v3'])) {
$certficates = [
'serial_no' => $this->app['config'][$is]['pay_routine_public_key'],
'certificates' => $this->app['config'][$is]['pay_routine_public_id']
];
//如果获取公钥成功则返回
if ($certficates['serial_no'] && $certficates['certificates']) {
return $certficates;
}
}
// v2支付,或者是未获取到公钥,则平台证书获取操作
$driver = Cache::store('file');
$cacheKey = '_wx_v3' . $this->app['config'][$is]['serial_no'];
if ($driver->has($cacheKey)) { return $driver->get($cacheKey);
}
$certficates = $this->getCertficates();
$driver->set($cacheKey, $certficates, 3600 * 24 * 30);
return $certficates;
}
2. 修改代码
$is = $this->isService ? 'service_payment':'payment';
if ($this->app['config']['type'] == 'wechat') {
$public_key = $this->app['config'][$is]['pay_weixin_public_key'];
} else {
$public_key = $this->app['config'][$is]['pay_routine_public_key'];
}
if ($public_key && ($this->isService || $this->app['config']['is_v3'])) {
$public_key = rtrim(public_path(),'/').$public_key;
//如果获取公钥成功则返回
if ($public_key) {
if (!is_file($public_key)) throw new InvalidConfigException('公钥文件不存在');
$public_content = file_get_contents($public_key);
if (openssl_public_encrypt($string, $encrypted, $public_content,OPENSSL_PKCS1_OAEP_PADDING)) {
//base64编码
$sign = base64_encode($encrypted);
return $sign;
} else {
throw new InvalidConfigException('encrypt failed');
}
}
}
三、 重启swoole

