transfer
This commit is contained in:
parent
6a043fc827
commit
70cbdf51b3
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user