Skip to content

Commit 1f0b17f

Browse files
committed
fix: 更新平台证书下载及证书读取
1 parent 989fd68 commit 1f0b17f

File tree

2 files changed

+12
-18
lines changed

2 files changed

+12
-18
lines changed

WePayV3/Cert.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,14 @@ class Cert extends BasicWePay
4242
public function download()
4343
{
4444
try {
45-
$aes = new DecryptAes($this->config['mch_v3_key']);
46-
$result = $this->doRequest('GET', '/v3/certificates');
4745
$certs = [];
46+
$result = $this->doRequest('GET', '/v3/certificates');
47+
$decrypt = new DecryptAes($this->config['mch_v3_key']);
4848
foreach ($result['data'] as $vo) {
4949
$certs[$vo['serial_no']] = [
5050
'expire' => strtotime($vo['expire_time']),
51-
'content' => $aes->decryptToString(
51+
'serial' => $vo['serial_no'],
52+
'content' => $decrypt->decryptToString(
5253
$vo['encrypt_certificate']['associated_data'],
5354
$vo['encrypt_certificate']['nonce'],
5455
$vo['encrypt_certificate']['ciphertext']

WePayV3/Contracts/BasicWePay.php

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -367,35 +367,28 @@ protected function signVerify($data, $sign, $serial)
367367
protected function _getCert($serial = '')
368368
{
369369
$certs = $this->tmpFile("{$this->config['mch_id']}_certs");
370-
if (empty($certs) || empty($certs[$serial]['content'])) {
370+
if (empty($certs) || empty($certs[$serial]['serial']) || empty($certs[$serial]['content'])) {
371371
Cert::instance($this->config)->download();
372372
$certs = $this->tmpFile("{$this->config['mch_id']}_certs");
373373
}
374374
foreach ($certs as $cert) {
375-
if ($certs[$serial]['expire'] > time()) {
375+
if (!empty($cert['serial']) && !empty($cert['content']) && $cert['expire'] > time()) {
376376
$this->config['cert_package'][$cert['serial']] = $cert['content'];
377-
if (empty($this->config['mp_cert_serial'])) {
377+
if (empty($this->config['mp_cert_serial']) && (empty($serial) || $serial === $cert['serial'])) {
378378
$this->config['mp_cert_serial'] = $cert['serial'];
379379
$this->config['mp_cert_content'] = $cert['content'];
380380
}
381381
}
382382
}
383-
// 未设置序号时,直接返回默认证书内容
384-
if (empty($serial) && !empty($this->config['mp_cert_content'])) {
383+
if (isset($this->config['cert_package'][$serial])) {
384+
return $this->config['cert_package'][$serial];
385+
} elseif (!empty($this->config['mp_cert_content'])) {
385386
return $this->config['mp_cert_content'];
386-
}
387-
388-
// 遍历证书数组,找到匹配的证书
389-
if ($cert = $this->withCertPayment()) {
387+
} elseif ($cert = $this->withCertPayment()) {
390388
return $cert;
391-
}
392-
393-
// 检查指定序号的证书是否存在
394-
if (!isset($this->config['cert_package'][$serial])) {
389+
} else {
395390
throw new InvalidResponseException("读取平台证书失败!");
396391
}
397-
398-
return $this->config['cert_package'][$serial];
399392
}
400393

401394
/**

0 commit comments

Comments
 (0)