diff --git a/woa/init.py b/woa/init.py index 224dd01..9939c18 100644 --- a/woa/init.py +++ b/woa/init.py @@ -38,7 +38,7 @@ class WOAHandler: if encoding_aes_key: # 微信的 AES Key 是 base64 编码的 32 字节字符串 self.aes_key = base64.b64decode(encoding_aes_key + "=") - self.encoding_aes_key = self.aes_key + self.aes_key = None self.media_manager = WeChatMediaManager(self.app_id, self.secret) def _check_signature(self, signature: str, timestamp: str, nonce: str) -> bool: @@ -132,7 +132,7 @@ class WOAHandler: # 如果开启加密,echostr 也需要解密 debug(f'handle_get():{request.query=}') return web.Response(text=echostr) - if self.encoding_aes_key: + if self.aes_key: try: echostr = self._decrypt_msg(echostr) except Exception as e: @@ -217,7 +217,7 @@ class WOAHandler: xml_str = body.decode('utf-8') # 3. 如果开启加密,先解密 - if self.encoding_aes_key: + if self.aes_key: root = ET.fromstring(xml_str) encrypt_node = root.find('Encrypt') if encrypt_node is not None and encrypt_node.text: @@ -237,7 +237,7 @@ class WOAHandler: debug(f'收到微信消息:{msg_dict} 返回:{reply_xml}') # 5. 如果需要加密回复 - if self.encoding_aes_key and reply_xml: + if self.aes_key and reply_xml: # 1. 生成新的时间戳和随机数 (不要用请求里的旧数据) timestamp = str(int(time.time())) nonce = ''.join([str(random.randint(0, 9)) for _ in range(10)])