This commit is contained in:
2026-06-15 10:17:55 +08:00
parent b87c0e8f01
commit fa6543ea54
+3 -2
View File
@@ -167,10 +167,11 @@ async def wechat_callback(request: Request, db: AsyncSession = Depends(get_db)):
# 使用 AES-GCM 解密 # 使用 AES-GCM 解密
try: try:
# API v3 key 需要转换为字节串 # API v3 key 和 nonce 需要转换为字节串
api_v3_key_bytes = api_v3_key.encode('utf-8') api_v3_key_bytes = api_v3_key.encode('utf-8')
nonce_bytes = nonce_str.encode('utf-8')
aesgcm = AESGCM(api_v3_key_bytes) aesgcm = AESGCM(api_v3_key_bytes)
decrypted_str = aesgcm.decrypt(ciphertext, associated_data, nonce_str) decrypted_str = aesgcm.decrypt(ciphertext, associated_data, nonce_bytes)
except InvalidTag: except InvalidTag:
logger.error("WeChat callback decryption failed: Invalid tag") logger.error("WeChat callback decryption failed: Invalid tag")
raise HTTPException(status_code=400, detail="数据解密失败") raise HTTPException(status_code=400, detail="数据解密失败")