From 198421778b7197440be22a20ba6b2988c1278193 Mon Sep 17 00:00:00 2001 From: Billy <641833868@qq.com> Date: Mon, 27 Oct 2025 16:09:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../library/ccblife/CcbPaymentService.php | 29 ++++--------------- 1 file changed, 5 insertions(+), 24 deletions(-) diff --git a/addons/shopro/library/ccblife/CcbPaymentService.php b/addons/shopro/library/ccblife/CcbPaymentService.php index 49e0af5..3c8bd77 100644 --- a/addons/shopro/library/ccblife/CcbPaymentService.php +++ b/addons/shopro/library/ccblife/CcbPaymentService.php @@ -445,35 +445,16 @@ class CcbPaymentService throw new \Exception('服务方公钥未配置'); } - // ✅ 关键修复:提取商户公钥模数的十六进制表示的后30位 + // ✅ 关键修复:直接取商户公钥十六进制字符串的后30位 try { - // 格式化商户公钥为PEM格式 - $merchantPemKey = $this->formatPublicKeyToPem($merchantPublicKey); - - // 解析商户公钥,提取模数(modulus) - $keyResource = openssl_pkey_get_public($merchantPemKey); - if (!$keyResource) { - throw new \Exception('商户公钥格式错误: ' . openssl_error_string()); - } - - $keyDetails = openssl_pkey_get_details($keyResource); - openssl_free_key($keyResource); - - if (!isset($keyDetails['rsa']['n'])) { - throw new \Exception('无法提取商户公钥RSA模数'); - } - - // 将模数转换为十六进制字符串(去掉前导0x) - $modulusHex = bin2hex($keyDetails['rsa']['n']); - - // 取后30位十六进制字符 - $last30Chars = substr($modulusHex, -30); + // 商户公钥已经是十六进制格式,直接取后30位 + $last30Chars = substr($merchantPublicKey, -30); if (strlen($last30Chars) < 30) { - throw new \Exception('商户公钥模数长度不足30位'); + throw new \Exception('商户公钥长度不足30位'); } - Log::info('[建行支付] 商户公钥模数后30位: ' . $last30Chars); + Log::info('[建行支付] 商户公钥后30位: ' . $last30Chars); // 使用服务方公钥加密这30位十六进制字符串 // CcbRSA::encrypt 会自动进行base64编码