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