This commit is contained in:
2026-06-15 10:29:57 +08:00
parent ca0cfbd9d9
commit faa3c165dc
+2 -7
View File
@@ -185,11 +185,9 @@ async def wechat_callback(request: Request, db: AsyncSession = Depends(get_db)):
# API v3 key 需要转换为字节串 # API v3 key 需要转换为字节串
api_v3_key_bytes = api_v3_key.encode('utf-8') api_v3_key_bytes = api_v3_key.encode('utf-8')
# ciphertext 是 Base64 编码的,需要解码 # ciphertext 和 nonce 都是 Base64 编码的,需要解码
ciphertext_bytes = b64decode(ciphertext) ciphertext_bytes = b64decode(ciphertext)
nonce_bytes = b64decode(nonce_str)
# nonce 是十六进制字符串,需要转换为字节
nonce_bytes = bytes.fromhex(nonce_str)
# associated_data 是字符串,直接编码 # associated_data 是字符串,直接编码
associated_data_bytes = associated_data.encode('utf-8') if associated_data else b'' associated_data_bytes = associated_data.encode('utf-8') if associated_data else b''
@@ -204,9 +202,6 @@ async def wechat_callback(request: Request, db: AsyncSession = Depends(get_db)):
except InvalidTag: except InvalidTag:
logger.error("WeChat callback decryption failed: Invalid tag (key or data mismatch)") logger.error("WeChat callback decryption failed: Invalid tag (key or data mismatch)")
raise HTTPException(status_code=400, detail="数据解密失败(密钥或数据不匹配)") raise HTTPException(status_code=400, detail="数据解密失败(密钥或数据不匹配)")
except ValueError as e:
logger.error(f"WeChat callback decryption failed: Invalid hex string or other error: {e}")
raise HTTPException(status_code=400, detail="数据解密失败(格式错误)")
except Exception as e: except Exception as e:
logger.error(f"WeChat callback decryption failed: {e}") logger.error(f"WeChat callback decryption failed: {e}")
raise HTTPException(status_code=400, detail="数据解密失败") raise HTTPException(status_code=400, detail="数据解密失败")