From 70cbdf51b3b559d4f114e69b149db2ce6f17efe7 Mon Sep 17 00:00:00 2001 From: Hankin Date: Fri, 24 Apr 2026 17:53:41 +0800 Subject: [PATCH] transfer --- app/Services/WechatPayService.php | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/app/Services/WechatPayService.php b/app/Services/WechatPayService.php index 3341c24..1caa11f 100644 --- a/app/Services/WechatPayService.php +++ b/app/Services/WechatPayService.php @@ -181,14 +181,32 @@ class WechatPayService } $resource = $data['resource']; - $ciphertext = base64_decode($resource['ciphertext']); $nonce = $resource['nonce']; $associatedData = $resource['associated_data'] ?? ''; + + // 1. 检查原始 ciphertext 的类型和长度(它应该是 Base64 字符串) + $originalCiphertext = $resource['ciphertext']; + Log::info('原始 ciphertext 信息', [ + 'type' => gettype($originalCiphertext), // 应该是 string + 'length' => strlen($originalCiphertext), // 通常是一个正整数,如 344 + 'is_base64' => base64_encode(base64_decode($originalCiphertext, true)) === $originalCiphertext, // 应该是 true + ]); + + // 2. 检查一次解码后的二进制数据长度 + $binaryCiphertext = base64_decode($originalCiphertext); + Log::info('解码后二进制密文长度', [ + 'binary_length' => strlen($binaryCiphertext), // 通常会是 16 的倍数 + ]); + + // 3. 再次确认你的 APIv3 密钥是否是 32 字节 $apiV3Key = config("wechatpay.payment.api3_key"); - Log::info("解密数据", ["ciphertext" => $ciphertext, "apiV3Key" => $apiV3Key, "nonce" => $nonce, "associatedData" => $associatedData]); + Log::info('APIv3 密钥长度', [ + 'key_length' => strlen($apiV3Key), // 必须输出 32 + ]); + Log::info("解密数据", ["ciphertext" => $binaryCiphertext, "apiV3Key" => $apiV3Key, "nonce" => $nonce, "associatedData" => $associatedData]); // PHP 7.1+ 原生支持 AES-256-GCM $decrypted = AesGcm::decrypt( - $ciphertext, // Base64解码后的密文(包含tag) + $binaryCiphertext, // Base64解码后的密文(包含tag) $apiV3Key, $nonce, $associatedData