From cae79aac4897fff4547457b52c4f8f1f4ecea623 Mon Sep 17 00:00:00 2001 From: Ethan Date: Mon, 24 Feb 2025 18:09:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=BE=AE=E4=BF=A1=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E7=B1=BB=E5=9E=8B=2049=EF=BC=88=E8=81=8A=E5=A4=A9?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=EF=BC=89=E7=9A=84=E6=94=AF=E6=8C=81=EF=BC=8C?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=A4=84=E7=90=86=E8=81=8A=E5=A4=A9=E8=AE=B0?= =?UTF-8?q?=E5=BD=95=E7=B1=BB=E5=9E=8B=E7=9A=84=E5=BE=AE=E4=BF=A1=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 微信聊天记录是 xml 数据格式,本质上也是字符串,可以按照字符串Plain类型来处理。 --- pkg/platform/sources/gewechat.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/pkg/platform/sources/gewechat.py b/pkg/platform/sources/gewechat.py index 9d3921fc..62f3de7d 100644 --- a/pkg/platform/sources/gewechat.py +++ b/pkg/platform/sources/gewechat.py @@ -79,6 +79,32 @@ class GewechatMessageConverter(adapter.MessageConverter): [platform_message.Image(base64=f"data:image/jpeg;base64,{image_base64}")] ) + elif message["Data"]["MsgType"] == 49: + # 支持微信聊天记录的消息类型,将 XML 内容转换为 MessageChain 传递 + try: + # 首先确保内容是字符串 + content = message["Data"]["Content"]["string"] + + # 如果内容已经是base64编码,尝试解码 + try: + # 先将字符串编码为UTF-8字节 + content_bytes = content.encode('utf-8') + # 然后进行base64解码 + decoded_content = base64.b64decode(content_bytes) + return platform_message.MessageChain( + [platform_message.Unknown(content=decoded_content)] + ) + except Exception as e: + # 如果解码失败,直接返回原始内容 + return platform_message.MessageChain( + [platform_message.Plain(text=content)] + ) + except Exception as e: + print(f"Error processing type 49 message: {str(e)}") + return platform_message.MessageChain( + [platform_message.Plain(text="[无法解析的消息]")] + ) + class GewechatEventConverter(adapter.EventConverter): @staticmethod