From 20d4b8d4225191b9906e257a5c0fce30f3b68fde Mon Sep 17 00:00:00 2001 From: wwwwwwwww <526125649@qq.com> Date: Mon, 15 Jun 2026 10:21:28 +0800 Subject: [PATCH] 1 --- video-gen-api/app/api/v1/payments.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/video-gen-api/app/api/v1/payments.py b/video-gen-api/app/api/v1/payments.py index 58b384ae..c83d2034 100644 --- a/video-gen-api/app/api/v1/payments.py +++ b/video-gen-api/app/api/v1/payments.py @@ -167,11 +167,15 @@ async def wechat_callback(request: Request, db: AsyncSession = Depends(get_db)): # 使用 AES-GCM 解密 try: - # 所有参数都需要转换为字节串 + # API v3 key 需要转换为字节串 api_v3_key_bytes = api_v3_key.encode('utf-8') - ciphertext_bytes = ciphertext.encode('utf-8') if ciphertext else b'' + + # ciphertext 和 nonce 是 Base64 编码的,需要解码 + ciphertext_bytes = b64decode(ciphertext) if ciphertext else b'' + nonce_bytes = b64decode(nonce_str) if nonce_str else b'' + + # associated_data 是字符串,直接编码 associated_data_bytes = associated_data.encode('utf-8') if associated_data else b'' - nonce_bytes = nonce_str.encode('utf-8') if nonce_str else b'' aesgcm = AESGCM(api_v3_key_bytes) decrypted_str = aesgcm.decrypt(ciphertext_bytes, associated_data_bytes, nonce_bytes)