Quellcode durchsuchen

feat(微信支付): 添加平台证书相关配置

- 新增平台证书序列号(platform_no)和平台证书(platform_cert)配置项
- 更新微信支付公钥配置,改为公钥ID(public_key_id)
- 修复证书上传接口的URL和认证问题
runphp vor 6 Monaten
Ursprung
Commit
d90ff81104
3 geänderte Dateien mit 52 neuen und 8 gelöschten Zeilen
  1. 43 6
      config.php
  2. 5 1
      src/Config.php
  3. 4 1
      src/Trait/ApiTrait.php

+ 43 - 6
config.php

@@ -32,8 +32,11 @@ return json_decode(<<<'JSON'
     "info": "商户API证书",
     "$required": false,
     "props": {
-      "action": "/admin/flysystem/file",
+      "action": "{{API_BASE_URL}}/admin/filesystem/file",
       "name":"file",
+      "headers": {
+        "Authorization": "Bearer {{API_TOKEN}}"
+      },
       "onSuccess": "$FNX:const res = $inject.args[0];\nconsole.log(res);if(res.code!=200 &&res.code!=0){alert(res.msg);return;}\nconst file = $inject.args[1];\n\nfile.url = res.data.file_url;",
       "limit": 1
     },
@@ -48,8 +51,11 @@ return json_decode(<<<'JSON'
     "info": "商户API私钥",
     "$required": false,
     "props": {
-      "action": "/admin/flysystem/file",
+      "action": "{{API_BASE_URL}}/admin/filesystem/file",
       "name":"file",
+      "headers": {
+        "Authorization": "Bearer {{API_TOKEN}}"
+      },
       "onSuccess": "$FNX:const res = $inject.args[0];\nconst file = $inject.args[1];\n\nfile.url = res.data.file_url;",
       "limit": 1
     },
@@ -76,8 +82,11 @@ return json_decode(<<<'JSON'
     "info": "微信支付公钥",
     "$required": false,
     "props": {
-      "action": "/admin/flysystem/file",
+      "action": "{{API_BASE_URL}}/admin/filesystem/file",
       "name":"file",
+      "headers": {
+        "Authorization": "Bearer {{API_TOKEN}}"
+      },
       "onSuccess": "$FNX:const res = $inject.args[0];\nconst file = $inject.args[1];\n\nfile.url = res.data.file_url;",
       "limit": 1
     },
@@ -89,8 +98,8 @@ return json_decode(<<<'JSON'
   },
   {
     "type": "input",
-    "field": "wechatpay_serial",
-    "title": "wechatpay_serial",
+    "field": "public_key_id",
+    "title": "public_key_id",
     "info": "微信支付公钥id",
     "$required": false,
     "_fc_id": "id_F8prmd1e9yx9auc",
@@ -111,7 +120,35 @@ return json_decode(<<<'JSON'
     "hidden": false,
     "_fc_drag_tag": "input"
   },
-    {
+  {
+    "type": "input",
+    "field": "platform_no",
+    "title": "platform_no",
+    "info": "平台证书序列号",
+    "$required": false,
+    "_fc_id": "id_Floymd1ech8faxc",
+    "name": "ref_Fdp2md1ech8fayc",
+    "display": true,
+    "hidden": false,
+    "_fc_drag_tag": "input"
+  },
+  {
+    "type": "upload",
+    "field": "platform_cert",
+    "title": "平台证书",
+    "info": "平台证书",
+    "$required": false,
+    "props": {
+      "action": "{{API_BASE_URL}}/admin/filesystem/file",
+      "name":"file",
+      "headers": {
+        "Authorization": "Bearer {{API_TOKEN}}"
+      },
+      "onSuccess": "$FNX:const res = $inject.args[0];\nconst file = $inject.args[1];\n\nfile.url = res.data.file_url;",
+      "limit": 1
+    }
+  },
+  {
     "type": "switch",
     "title": "启用沙箱环境",
     "field": "sandbox",

+ 5 - 1
src/Config.php

@@ -12,12 +12,15 @@ use WeChatPay\Crypto\Rsa;
  * @property string $mchid 商户号
  * @property string $appid 应用ID
  * @property string $serial_no 商户证书序列号
- * @property string $wechatpay_serial 微信支付证书序列号
+ * @property string $public_key_id 微信支付公钥id
  * @property string $api_v3_key APIv3密钥
  * @property string $notify_url 微信支付回调地址
  * @property string $apiclient_cert 微信支付证书  用于服务端API请求报文签名
  * @property string $apiclient_key 微信支付证书密钥 用于生成接口请求签名
  * @property string $public_key 微信支付公钥
+ * @property string $platform_no 平台证书序列号
+ * @property string $platform_cert 平台证书
+ *
  */
 class Config
 {
@@ -42,6 +45,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),
             default => $this->options[$name] ?? null,
         };
     }

+ 4 - 1
src/Trait/ApiTrait.php

@@ -23,13 +23,15 @@ trait ApiTrait
     }
     private function getBuilderChainable(): BuilderChainable
     {
+
         if ($this->builderChainable === null) {
             $this->builderChainable = Builder::factory([
                 'mchid' => $this->config->mchid,
                 'serial' => $this->config->serial_no,
                 'privateKey' => $this->config->apiclient_key,
                 'certs' => [
-                    $this->config->wechatpay_serial => $this->config->public_key,
+                    $this->config->platform_no => $this->config->platform_cert,
+                    $this->config->public_key_id => $this->config->public_key,
                 ],
             ]);
         }
@@ -45,6 +47,7 @@ trait ApiTrait
             })
             ->otherwise(function ($e) {
                 if ($e instanceof \GuzzleHttp\Exception\RequestException && $e->hasResponse()) {
+
                     $errorBody = json_decode((string)$e->getResponse()->getBody());
                     throw new ErrorException(message: trim($errorBody->message));
                 }