from wechatpy.enterprise.crypto import WeChatCryptofrom wechatpy.exceptions import InvalidSignatureException
from wechatpy.enterprise.exceptions import InvalidCorpIdException
from wechatpy.enterprise import parse_message
crypto = WeChatCrypto(TOKEN, EncodingAESKey, CorpId)
try:
decrypted_xml = crypto.decrypt_message(
raw_message,
signature,
timestamp,
nonce
)
except (InvalidSignatureException, InvalidCorpIdException):
raise # 处理异常情况
else:
msg = parse_message(decrypted_xml)