Explorar o código

fix(wechatpay):修复平台证书配置可选问题
- 在Config类中将platform_cert配置设为可选,避免空值时报错
- 在WechatPayBuilder类中构建certs配置时,仅在platform_no存在时添加platform_cert
- 防止因平台证书未配置导致的初始化失败问题

runphp hai 5 meses
pai
achega
0c1df49151
Modificáronse 2 ficheiros con 7 adicións e 4 borrados
  1. 1 1
      src/Config.php
  2. 6 3
      src/WechatPayBuilder.php

+ 1 - 1
src/Config.php

@@ -48,7 +48,7 @@ class Config
             'apiclient_cert' => $this->getKeyPath($this->options['apiclient_cert'][0]),
             'apiclient_key' => Rsa::from($this->getKeyPath($this->options['apiclient_key'][0])),
             'public_key' => Rsa::from($this->getKeyPath($this->options['public_key'][0]), Rsa::KEY_TYPE_PUBLIC),
-            'platform_cert' => Rsa::from($this->getKeyPath($this->options['platform_cert'][0]), Rsa::KEY_TYPE_PUBLIC),
+            'platform_cert' => isset($this->options['platform_cert'][0]) ? Rsa::from($this->getKeyPath($this->options['platform_cert'][0]), Rsa::KEY_TYPE_PUBLIC) : null,
             default => $this->options[$name] ?? null,
         };
     }

+ 6 - 3
src/WechatPayBuilder.php

@@ -30,15 +30,18 @@ class WechatPayBuilder extends Facade
     {
 
         if ($this->builderChainable === null) {
-            $this->builderChainable = Builder::factory([
+            $config = [
                 'mchid' => $this->config->mchid,
                 'serial' => $this->config->serial_no,
                 'privateKey' => $this->config->apiclient_key,
                 'certs' => [
-                    $this->config->platform_no => $this->config->platform_cert,
                     $this->config->public_key_id => $this->config->public_key,
                 ],
-            ]);
+            ];
+            if ($this->config->platform_no) {
+                $config['certs'][$this->config->platform_no] = $this->config->platform_cert;
+            }
+            $this->builderChainable = Builder::factory($config);
         }
         return $this->builderChainable;
     }