From d338a8fc8cdf3f5d96566c3dec958c96d0ef2ed3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=AF=E7=AB=8B?= Date: Mon, 3 Mar 2025 22:46:02 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E5=BE=AE=E4=BF=A1V3?= =?UTF-8?q?=E6=94=AF=E4=BB=98=E9=85=8D=E7=BD=AE=E5=8F=8A=E8=B0=83=E7=94=A8?= =?UTF-8?q?DEMO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/controller/Config.php | 5 +-- .../src/service/WechatService.php | 15 ++++--- .../src/view/config/payment.html | 44 ++++++++++--------- 3 files changed, 34 insertions(+), 30 deletions(-) diff --git a/plugin/think-plugs-wechat/src/controller/Config.php b/plugin/think-plugs-wechat/src/controller/Config.php index c452daba9..867752a23 100644 --- a/plugin/think-plugs-wechat/src/controller/Config.php +++ b/plugin/think-plugs-wechat/src/controller/Config.php @@ -188,8 +188,7 @@ class Config extends Controller if (empty($wechat['mch_ssl_p12']) || !$local->has($wechat['mch_ssl_p12'], true)) { $this->error('商户证书 P12 不能为空!'); } - $content = $local->get($wechat['mch_ssl_p12'], true); - if (openssl_pkcs12_read($content, $certs, $wechat['mch_id'])) { + if (openssl_pkcs12_read($local->get($wechat['mch_ssl_p12'], true), $certs, $wechat['mch_id'])) { $name1 = "wxpay/{$wechat['mch_id']}_cer.pem"; $name2 = "wxpay/{$wechat['mch_id']}_key.pem"; $wechat['mch_ssl_cer'] = $local->set($name1, $certs['cert'], true)['url']; @@ -206,7 +205,7 @@ class Config extends Controller 'mch_key' => $wechat['mch_key'], 'mch_v3_key' => $wechat['mch_v3_key'], 'ssl_pay_id' => $wechat['mch_v3_payid'] ?? '', - 'ssl_pay_text' => $local->get($wechat['ssl_cer_pay'], true), + 'ssl_pay_text' => $local->get($wechat['mch_ssl_pay'], true), 'ssl_key_text' => $local->get($wechat['mch_ssl_key'], true), 'ssl_cer_text' => $local->get($wechat['mch_ssl_cer'], true), ]); diff --git a/plugin/think-plugs-wechat/src/service/WechatService.php b/plugin/think-plugs-wechat/src/service/WechatService.php index 7000283dc..364b110cb 100644 --- a/plugin/think-plugs-wechat/src/service/WechatService.php +++ b/plugin/think-plugs-wechat/src/service/WechatService.php @@ -226,24 +226,23 @@ class WechatService extends Service public static function withWxpayCert(array $options): array { // 文本模式主要是为了解决分布式部署 - $local = LocalStorage::instance(); $name1 = "wxpay/{$options['mch_id']}_cer.pem"; $name2 = "wxpay/{$options['mch_id']}_key.pem"; + $local = LocalStorage::instance(); if ($local->has($name1, true) && $local->has($name2, true)) { $sslCer = $local->path($name1, true); $sslKey = $local->path($name2, true); } + $data = sysdata('plugin.wechat.payment'); if (empty($sslCer) || empty($sslKey)) { - if (!empty($data = sysdata('plugin.wechat.payment'))) { - if (!empty($data['ssl_key_text']) && !empty($data['ssl_cer_text'])) { - $sslCer = $local->set($name1, $data['ssl_cer_text'], true)['file']; - $sslKey = $local->set($name2, $data['ssl_key_text'], true)['file']; - } - } else { + if (empty($data)) { $sslCer = $local->path(sysconf('wechat.mch_ssl_cer'), true); $sslKey = $local->path(sysconf('wechat.mch_ssl_key'), true); if (!$local->has($sslCer, true)) unset($sslCer); if (!$local->has($sslKey, true)) unset($sslKey); + } elseif (!empty($data['ssl_key_text']) && !empty($data['ssl_cer_text'])) { + $sslCer = $local->set($name1, $data['ssl_cer_text'], true)['file']; + $sslKey = $local->set($name2, $data['ssl_key_text'], true)['file']; } } if (isset($sslCer) && isset($sslKey)) { @@ -251,6 +250,8 @@ class WechatService extends Service $options['ssl_key'] = $sslKey; $options['cert_public'] = $sslCer; $options['cert_private'] = $sslKey; + $options['mp_cert_serial'] = $data['ssl_pay_id'] ?? ''; + $options['mp_cert_content'] = $data['ssl_pay_text'] ?? ''; } return $options; } diff --git a/plugin/think-plugs-wechat/src/view/config/payment.html b/plugin/think-plugs-wechat/src/view/config/payment.html index 9b1adfa93..4888da6e3 100644 --- a/plugin/think-plugs-wechat/src/view/config/payment.html +++ b/plugin/think-plugs-wechat/src/view/config/payment.html @@ -18,27 +18,41 @@ +
+ +
+ 微信 V3 支付证书公钥MCH_V3_PAYCERT +
+
+ + +
+
+
+
@@ -57,11 +71,6 @@ - - -
@@ -74,11 +83,6 @@ - - -
@@ -99,7 +103,7 @@ (function (type) { layui.form.val('payment', {'wechat.mch_ssl_type': type}); layui.form.on('radio(data-mch-type)', apply) && apply({value: type}); - ['wechat.mch_ssl_p12', 'wechat.mch_ssl_key', 'wechat.mch_ssl_cer'].forEach(function (type) { + ['wechat.mch_ssl_p12', 'wechat.mch_ssl_key', 'wechat.mch_ssl_cer', 'wechat.mch_ssl_pay'].forEach(function (type) { $('input[name="' + type + '"]').on('change', function () { let that = this, $button = $(this).next('button'); if (typeof that.value === 'string' && that.value.length > 5) {