@@ -367,35 +367,28 @@ protected function signVerify($data, $sign, $serial)
367
367
protected function _getCert ($ serial = '' )
368
368
{
369
369
$ 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 ' ])) {
371
371
Cert::instance ($ this ->config )->download ();
372
372
$ certs = $ this ->tmpFile ("{$ this ->config ['mch_id ' ]}_certs " );
373
373
}
374
374
foreach ($ certs as $ cert ) {
375
- if ($ certs [ $ serial] ['expire ' ] > time ()) {
375
+ if (! empty ( $ cert [ ' serial ' ]) && ! empty ( $ cert [ ' content ' ]) && $ cert ['expire ' ] > time ()) {
376
376
$ 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 ' ]) ) {
378
378
$ this ->config ['mp_cert_serial ' ] = $ cert ['serial ' ];
379
379
$ this ->config ['mp_cert_content ' ] = $ cert ['content ' ];
380
380
}
381
381
}
382
382
}
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 ' ])) {
385
386
return $ this ->config ['mp_cert_content ' ];
386
- }
387
-
388
- // 遍历证书数组,找到匹配的证书
389
- if ($ cert = $ this ->withCertPayment ()) {
387
+ } elseif ($ cert = $ this ->withCertPayment ()) {
390
388
return $ cert ;
391
- }
392
-
393
- // 检查指定序号的证书是否存在
394
- if (!isset ($ this ->config ['cert_package ' ][$ serial ])) {
389
+ } else {
395
390
throw new InvalidResponseException ("读取平台证书失败! " );
396
391
}
397
-
398
- return $ this ->config ['cert_package ' ][$ serial ];
399
392
}
400
393
401
394
/**
0 commit comments