private function decryptResource($resource)
{
$ciphertext = base64_decode($resource['ciphertext']);
$associatedData = $resource['associated_data'];
$nonce = $resource['nonce'];
$apiKeyV3 = '1234567890abcdefgh888888888888';
if (strlen($apiKeyV3) !== 32) {
pr_log('API V3密钥长度错误,必须为32位: ' . strlen($apiKeyV3), 3);
return false;
}
if (empty($ciphertext) || empty($associatedData) || empty($nonce)) {
pr_log('解密参数不完整', 3);
return false;
}
$decrypted = openssl_decrypt($ciphertext, 'aes-256-gcm', $apiKeyV3, OPENSSL_RAW_DATA, $nonce, $associatedData);
if ($decrypted === false) {
$errors = [];
while ($error = openssl_error_string()) {
$errors[] = $error;
}
pr_log('解密失败 - 所有错误信息: ' . implode('|', $errors), 3);
pr_log('解密失败 - ciphertext长度: ' . strlen($ciphertext), 3);
pr_log('解密失败 - associated_data: ' . $associatedData, 3);
pr_log('解密失败 - nonce: ' . $nonce, 3);
pr_log('解密失败 - API V3密钥: ' . $apiKeyV3, 3);
pr_log('解密失败 - API V3密钥长度: ' . strlen($apiKeyV3), 3);
pr_log('请确认API V3密钥设置正确:登录微信商户平台 -> 账户中心 -> API安全 -> 设置APIv3密钥', 3);
return false;
}
pr_log('解密成功: ' . $decrypted, 3);
return json_decode($decrypted, true);
}
截取到的错误:error:0909006C:PEM routines:get_name:no start line , 不知道是什么引起的?
秘钥我打码了, 我重置了4回,apiv3的秘钥 , 签名过了,解密一直不过, 我测试了openssl是支持aes-256-gcm加密方式,解密一直失败



来这里验证一下V3key对不对 https://tools.aifuwu.net/wechat-pay-tools/apiv3-key-validator