python 微信支付回调通知resource对象解密
微信API文档
from cryptography.hazmat.primitives.ciphers.aead import AESGCM
import base64
from django.conf import settings
def wx_resource(nonce, ciphertext, associated_data):
key_bytes = str.encode(settings.APIV3_KEY) # APIv3_key(商户平台设置)
nonce_bytes = str.encode(nonce)
ad_bytes = str.encode(associated_data)
data = base64.b64decode(ciphertext)
aesgcm = AESGCM(key_bytes)
plaintext = aesgcm.decrypt(nonce_bytes, data, ad_bytes)
plaintext_str = bytes.decode(plaintext)
return eval(plaintext_str)