@@ -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