From 4d9994b0a209eb36af9ae25a38f9d5a843864117 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 21:55:56 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=BE=AE=E4=BF=A1=E6=94=AF=E4=BB=98?= =?UTF-8?q?=E8=AF=81=E4=B9=A6=E5=85=AC=E9=92=A5=E9=AA=8C=E8=AF=81=E6=9B=B4?= =?UTF-8?q?=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WePayV3/Contracts/BasicWePay.php | 9 ++++++--- _test/pay-v3-config.php | 18 +++++++++--------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/WePayV3/Contracts/BasicWePay.php b/WePayV3/Contracts/BasicWePay.php index 772724d..a31c820 100644 --- a/WePayV3/Contracts/BasicWePay.php +++ b/WePayV3/Contracts/BasicWePay.php @@ -118,7 +118,7 @@ abstract class BasicWePay } // 自动配置平台证书 - if (empty($this->config['mp_cert_serial']) || empty($this->config['mp_cert_content'])) { + if (empty($options['mp_cert_serial']) || empty($options['mp_cert_content'])) { if ($this->autoCert) $this->_autoCert(); } else { $this->config['mp_cert_serial'] = $options['mp_cert_serial']; @@ -340,8 +340,11 @@ abstract class BasicWePay */ protected function signVerify($data, $sign, $serial) { - $cert = $this->_getCert($serial); - return @openssl_verify($data, base64_decode($sign), openssl_x509_read($cert), 'sha256WithRSAEncryption'); + if (stripos($this->config['mp_cert_serial'], 'PUB_KEY_ID_') !== false) { + return @openssl_verify($data, base64_decode($sign), $this->config['mp_cert_content'], OPENSSL_ALGO_SHA256); + } else { + return @openssl_verify($data, base64_decode($sign), openssl_x509_read($this->_getCert($serial)), 'sha256WithRSAEncryption'); + } } /** diff --git a/_test/pay-v3-config.php b/_test/pay-v3-config.php index d5aa74a..0f6edc0 100644 --- a/_test/pay-v3-config.php +++ b/_test/pay-v3-config.php @@ -16,20 +16,20 @@ $certPublic = << 'wxbbc5782d4d77a43b', + 'appid' => 'wx3760axxxxxxxxxxx', // 必填,微信商户编号ID - 'mch_id' => '1643053551', + 'mch_id' => '152xxxxxxxx', // 必填,微信商户V3接口密钥 - 'mch_v3_key' => 'ThinkAdminThinkAdminThinkAdminTh', + 'mch_v3_key' => '98b7f45xxxxxxxxxxxxxxxxxxxxxxxxxx', // 可选,微信商户证书序列号,可从公钥中提取,请求签名使用 - 'cert_serial' => '', + 'cert_serial' => '49055xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', // 必填,微信商户证书公钥,支持证书内容或文件路径,仅用于提取序号 'cert_public' => $certPublic, - // 必填,微信商户证书私钥,支持证书内容或文件路径,用请求数据签名 + // 必填,微信商户证书私钥,支持证书内容或文件路径,用于请求数据签名 'cert_private' => $certPrivate, // 可选,微信平台证书序号或支付证书序号,用于接口请求序号 - 'mp_cert_serial' => 'PUB_KEY_ID_0116430535512025030300389200001906', + 'mp_cert_serial' => 'PUB_KEY_ID_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', // 可选,微信平台证书内容或支付证书内容 'mp_cert_content' => $certPayment, // 可选,运行时的文件缓存路径