update
This commit is contained in:
parent
2e0de79799
commit
4e4248feb5
@ -271,6 +271,12 @@ class WeChatClient:
|
|||||||
dict: 解密后的数据
|
dict: 解密后的数据
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
|
# API v3密钥转换为32字节
|
||||||
|
key_bytes = self.api_v3_key.encode('utf-8')
|
||||||
|
if len(key_bytes) != 32:
|
||||||
|
print(f"API v3密钥长度不正确: {len(key_bytes)} bytes")
|
||||||
|
raise ValueError("API v3密钥必须是32字节")
|
||||||
|
|
||||||
# Base64解码密文和随机串
|
# Base64解码密文和随机串
|
||||||
ciphertext_bytes = base64.b64decode(ciphertext)
|
ciphertext_bytes = base64.b64decode(ciphertext)
|
||||||
nonce_bytes = base64.b64decode(nonce)
|
nonce_bytes = base64.b64decode(nonce)
|
||||||
@ -278,10 +284,14 @@ class WeChatClient:
|
|||||||
# 处理附加数据
|
# 处理附加数据
|
||||||
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''
|
||||||
|
|
||||||
# 使用 API v3 密钥进行解密
|
|
||||||
key_bytes = self.api_v3_key.encode('utf-8')
|
|
||||||
aesgcm = AESGCM(key_bytes)
|
aesgcm = AESGCM(key_bytes)
|
||||||
|
|
||||||
|
print("解密参数:")
|
||||||
|
print(f"密钥长度: {len(key_bytes)} bytes")
|
||||||
|
print(f"Nonce长度: {len(nonce_bytes)} bytes")
|
||||||
|
print(f"密文长度: {len(ciphertext_bytes)} bytes")
|
||||||
|
print(f"附加数据: {associated_data_bytes}")
|
||||||
|
|
||||||
# 解密数据
|
# 解密数据
|
||||||
decrypted_data = aesgcm.decrypt(
|
decrypted_data = aesgcm.decrypt(
|
||||||
nonce_bytes,
|
nonce_bytes,
|
||||||
@ -289,12 +299,16 @@ class WeChatClient:
|
|||||||
associated_data_bytes
|
associated_data_bytes
|
||||||
)
|
)
|
||||||
|
|
||||||
|
print(f"解密后的原始数据: {decrypted_data}")
|
||||||
# 解析JSON数据
|
# 解析JSON数据
|
||||||
return json.loads(decrypted_data)
|
return json.loads(decrypted_data)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"解密回调数据失败: {str(e)}")
|
error_msg = f"解密回调数据失败: {str(e)}"
|
||||||
raise Exception(f"解密回调数据失败: {str(e)}")
|
print(error_msg)
|
||||||
|
import traceback
|
||||||
|
print("详细错误信息:", traceback.format_exc())
|
||||||
|
raise Exception(error_msg)
|
||||||
|
|
||||||
async def verify_payment_notify(self, request: Request) -> dict:
|
async def verify_payment_notify(self, request: Request) -> dict:
|
||||||
"""验证支付回调通知"""
|
"""验证支付回调通知"""
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user