From 577dc0d175904d4323ccc002e240e34a04198046 Mon Sep 17 00:00:00 2001 From: Dong_master <2213070223@qq.com> Date: Wed, 23 Apr 2025 02:25:58 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BA=86=E5=A4=84?= =?UTF-8?q?=E7=90=86=E8=AF=AD=E9=9F=B3=E6=B6=88=E6=81=AF=E5=92=8C=E5=A4=84?= =?UTF-8?q?=E7=90=86=E7=BE=A4=E8=81=8A=E5=9B=BE=E7=89=87=E6=B6=88=E6=81=AF?= =?UTF-8?q?=EF=BC=8C=E5=A2=9E=E5=8A=A0=E4=BA=86=E5=8F=91=E9=80=81=E8=AF=AD?= =?UTF-8?q?=E9=9F=B3=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/platform/sources/gewechat.py | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/pkg/platform/sources/gewechat.py b/pkg/platform/sources/gewechat.py index cac732a1..ba8f0490 100644 --- a/pkg/platform/sources/gewechat.py +++ b/pkg/platform/sources/gewechat.py @@ -58,6 +58,8 @@ class GewechatMessageConverter(adapter.MessageConverter): elif isinstance(component, platform_message.WeChatLink): content_list.append({'type': 'WeChatLink', 'link_title': component.link_title, 'link_desc': component.link_desc, 'link_thumb_url': component.link_thumb_url, 'link_url': component.link_url}) + elif isinstance(component, platform_message.WeChatForwardLink): + content_list.append({'type': 'WeChatLink', 'xml_data': component.xml_data}) elif isinstance(component, platform_message.Voice): @@ -108,6 +110,9 @@ class GewechatMessageConverter(adapter.MessageConverter): elif message["Data"]["MsgType"] == 3: image_xml = message["Data"]["Content"]["string"] + if image_xml.startswith('wxid'): # 此处处理群聊发送图片会有微信id开头 + xml_list = image_xml.split('\n')[2:] + image_xml = '\n'.join(xml_list) if not image_xml: return platform_message.MessageChain([ platform_message.Plain(text="[图片内容为空]") @@ -135,10 +140,15 @@ class GewechatMessageConverter(adapter.MessageConverter): platform_message.Plain(text=f"[图片处理失败]") ]) elif message["Data"]["MsgType"] == 34: - audio_base64 = message["Data"]["ImgBuf"]["buffer"] - return platform_message.MessageChain( - [platform_message.Voice(base64=f"data:audio/silk;base64,{audio_base64}")] - ) + try: + audio_base64 = message["Data"]["ImgBuf"]["buffer"] + return platform_message.MessageChain( + [platform_message.Voice(base64=f"data:audio/silk;base64,{audio_base64}")] + ) + except Exception as e: + return platform_message.MessageChain( + [platform_message.Plain(text="[无法解析群聊语音的消息]")] # 小测了一下,免费版拿不到群聊语音消息的base64,或者用什么办法解析xml里的url? + ) elif message["Data"]["MsgType"] == 49: # 支持微信聊天记录的消息类型,将 XML 内容转换为 MessageChain 传递 try: @@ -389,6 +399,11 @@ class GeWeChatAdapter(adapter.MessagePlatformAdapter): ,title=msg['link_title'], desc=msg['link_desc'] , link_url=msg['link_url'], thumb_url=msg['link_thumb_url']) + elif msg['type'] == 'WeChatForwardMiniPrograms': + self.bot.forward_mini_app(app_id=self.config['app_id'], to_wxid=target_id, xml=msg['xml_data']) + elif msg['type'] == 'voice': + self.bot.post_voice(app_id=self.config['app_id'], to_wxid=target_id, voice_url=msg['voice_url'],voice_duration=msg['length']) + async def reply_message( @@ -437,6 +452,9 @@ class GeWeChatAdapter(adapter.MessagePlatformAdapter): self.bot.post_link(app_id=self.config['app_id'], to_wxid=target_id , title=msg['link_title'], desc=msg['link_desc'] , link_url=msg['link_url'], thumb_url=msg['link_thumb_url']) + elif msg['type'] == 'voice': + self.bot.post_voice(app_id=self.config['app_id'], to_wxid=target_id, voice_url=msg['voice_url'], + voice_duration=msg['length']) async def is_muted(self, group_id: int) -> bool: pass From 8ca714853a77962d33d4374206db6fb8ee7199a1 Mon Sep 17 00:00:00 2001 From: Dong_master <2213070223@qq.com> Date: Wed, 23 Apr 2025 02:28:39 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E5=BE=AE?= =?UTF-8?q?=E4=BF=A1=E8=BD=AC=E5=8F=91=E9=93=BE=E6=8E=A5=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/platform/types/message.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkg/platform/types/message.py b/pkg/platform/types/message.py index b6b87596..857a10f2 100644 --- a/pkg/platform/types/message.py +++ b/pkg/platform/types/message.py @@ -860,3 +860,10 @@ class WeChatLink(MessageComponent): """链接略缩图""" link_thumb_url: str = '' + +class WeChatForwardLink(MessageComponent): + """转发链接。个人微信专用组件。""" + type: str = 'WeChatLink' + """xml数据""" + xml_data: str + From 5c26ce215b314108611e6a65cd3df69932fd4d41 Mon Sep 17 00:00:00 2001 From: Dong_master <2213070223@qq.com> Date: Wed, 23 Apr 2025 02:36:36 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E8=BD=AC?= =?UTF-8?q?=E5=8F=91=E9=93=BE=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/platform/sources/gewechat.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pkg/platform/sources/gewechat.py b/pkg/platform/sources/gewechat.py index ba8f0490..796cabe2 100644 --- a/pkg/platform/sources/gewechat.py +++ b/pkg/platform/sources/gewechat.py @@ -59,7 +59,7 @@ class GewechatMessageConverter(adapter.MessageConverter): content_list.append({'type': 'WeChatLink', 'link_title': component.link_title, 'link_desc': component.link_desc, 'link_thumb_url': component.link_thumb_url, 'link_url': component.link_url}) elif isinstance(component, platform_message.WeChatForwardLink): - content_list.append({'type': 'WeChatLink', 'xml_data': component.xml_data}) + content_list.append({'type': 'WeChatForwardLink', 'xml_data': component.xml_data}) elif isinstance(component, platform_message.Voice): @@ -399,8 +399,8 @@ class GeWeChatAdapter(adapter.MessagePlatformAdapter): ,title=msg['link_title'], desc=msg['link_desc'] , link_url=msg['link_url'], thumb_url=msg['link_thumb_url']) - elif msg['type'] == 'WeChatForwardMiniPrograms': - self.bot.forward_mini_app(app_id=self.config['app_id'], to_wxid=target_id, xml=msg['xml_data']) + elif msg['type'] == 'WeChatForwardLink': + self.bot.forward_url(app_id=self.config['app_id'], to_wxid=target_id, xml=msg['xml_data']) elif msg['type'] == 'voice': self.bot.post_voice(app_id=self.config['app_id'], to_wxid=target_id, voice_url=msg['voice_url'],voice_duration=msg['length']) @@ -452,6 +452,8 @@ class GeWeChatAdapter(adapter.MessagePlatformAdapter): self.bot.post_link(app_id=self.config['app_id'], to_wxid=target_id , title=msg['link_title'], desc=msg['link_desc'] , link_url=msg['link_url'], thumb_url=msg['link_thumb_url']) + elif msg['type'] == 'WeChatForwardLink': + self.bot.forward_url(app_id=self.config['app_id'], to_wxid=target_id, xml=msg['xml_data']) elif msg['type'] == 'voice': self.bot.post_voice(app_id=self.config['app_id'], to_wxid=target_id, voice_url=msg['voice_url'], voice_duration=msg['length']) From 00cafb1188e5d9995fc75acfcbb9ffd9dab7fb0a Mon Sep 17 00:00:00 2001 From: Dong_master <2213070223@qq.com> Date: Thu, 24 Apr 2025 00:00:49 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E5=86=85=E5=AE=B9=E6=89=8B=E8=AF=AF=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/platform/types/message.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/platform/types/message.py b/pkg/platform/types/message.py index 857a10f2..20ca399b 100644 --- a/pkg/platform/types/message.py +++ b/pkg/platform/types/message.py @@ -863,7 +863,7 @@ class WeChatLink(MessageComponent): class WeChatForwardLink(MessageComponent): """转发链接。个人微信专用组件。""" - type: str = 'WeChatLink' + type: str = 'WeChatForwardLink' """xml数据""" xml_data: str From 112f99d6d9ab33610ced7c2a76ea755dae76a01a Mon Sep 17 00:00:00 2001 From: Dong_master <2213070223@qq.com> Date: Thu, 24 Apr 2025 21:12:30 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=94=B6=E5=88=B0?= =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F=EF=BC=8C=E5=85=AC=E4=BC=97=E5=8F=B7?= =?UTF-8?q?=E8=BD=AC=E8=B4=A6=E7=AD=89=E6=B6=88=E6=81=AF=E6=97=B6=E5=B0=86?= =?UTF-8?q?=E5=85=B6=E9=80=9A=E8=BF=87unknown=E4=BC=A0=E9=80=92=E5=87=BA?= =?UTF-8?q?=E6=9D=A5=EF=BC=8C=E5=B9=B6=E4=BF=AE=E5=A4=8Dvoice=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E5=86=99=E9=94=99=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/platform/sources/gewechat.py | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/pkg/platform/sources/gewechat.py b/pkg/platform/sources/gewechat.py index 796cabe2..da4a6b99 100644 --- a/pkg/platform/sources/gewechat.py +++ b/pkg/platform/sources/gewechat.py @@ -151,8 +151,9 @@ class GewechatMessageConverter(adapter.MessageConverter): ) elif message["Data"]["MsgType"] == 49: # 支持微信聊天记录的消息类型,将 XML 内容转换为 MessageChain 传递 + content = message["Data"]["Content"]["string"] try: - content = message["Data"]["Content"]["string"] + # content = message["Data"]["Content"]["string"] # 有三种可能的消息结构weid开头,私聊直接和直接 if content.startswith('wxid'): xml_list = content.split('\n')[2:] @@ -192,24 +193,29 @@ class GewechatMessageConverter(adapter.MessageConverter): return platform_message.MessageChain(message_list) elif data_type == '51': return platform_message.MessageChain( - [platform_message.Plain(text=f'[视频号消息]')] + [ # platform_message.Plain(text=f'[视频号消息]'), + platform_message.Unknown(text=content)] ) # print(content_data) elif data_type == '2000': return platform_message.MessageChain( - [platform_message.Plain(text=f'[转账消息]')] + [ # platform_message.Plain(text=f'[转账消息]'), + platform_message.Unknown(text=content)] ) elif data_type == '2001': return platform_message.MessageChain( - [platform_message.Plain(text=f'[红包消息]')] + [ # platform_message.Plain(text=f'[红包消息]'), + platform_message.Unknown(text=content)] ) elif data_type == '5': return platform_message.MessageChain( - [platform_message.Plain(text=f'[公众号消息]')] + [ # platform_message.Plain(text=f'[公众号消息]'), + platform_message.Unknown(text=content)] ) elif data_type == '33' or data_type == '36': return platform_message.MessageChain( - [platform_message.Plain(text=f'[小程序消息]')] + [ # platform_message.Plain(text=f'[小程序消息]'), + platform_message.Unknown(text=content)] ) # print(data_type.text) else: @@ -219,8 +225,8 @@ class GewechatMessageConverter(adapter.MessageConverter): content_bytes = content.encode('utf-8') decoded_content = base64.b64decode(content_bytes) return platform_message.MessageChain( - [platform_message.Unknown(content=decoded_content)] - ) + [platform_message.Unknown(text=decoded_content)] + ) # 不对劲,十分有九分不对劲这里这么写不对吧 except Exception as e: return platform_message.MessageChain( [platform_message.Plain(text=content)] @@ -228,7 +234,8 @@ class GewechatMessageConverter(adapter.MessageConverter): except Exception as e: print(f"Error processing type 49 message: {str(e)}") return platform_message.MessageChain( - [platform_message.Plain(text="[无法解析的消息]")] + [ # platform_message.Plain(text="[无法解析的消息]"), + platform_message.Unknown(text=content)] ) class GewechatEventConverter(adapter.EventConverter): @@ -402,7 +409,7 @@ class GeWeChatAdapter(adapter.MessagePlatformAdapter): elif msg['type'] == 'WeChatForwardLink': self.bot.forward_url(app_id=self.config['app_id'], to_wxid=target_id, xml=msg['xml_data']) elif msg['type'] == 'voice': - self.bot.post_voice(app_id=self.config['app_id'], to_wxid=target_id, voice_url=msg['voice_url'],voice_duration=msg['length']) + self.bot.post_voice(app_id=self.config['app_id'], to_wxid=target_id, voice_url=msg['url'],voice_duration=msg['length']) @@ -455,7 +462,7 @@ class GeWeChatAdapter(adapter.MessagePlatformAdapter): elif msg['type'] == 'WeChatForwardLink': self.bot.forward_url(app_id=self.config['app_id'], to_wxid=target_id, xml=msg['xml_data']) elif msg['type'] == 'voice': - self.bot.post_voice(app_id=self.config['app_id'], to_wxid=target_id, voice_url=msg['voice_url'], + self.bot.post_voice(app_id=self.config['app_id'], to_wxid=target_id, voice_url=msg['url'], voice_duration=msg['length']) async def is_muted(self, group_id: int) -> bool: From cb7f7b80df05af17a9ab0c7bca0fb2b3fdc4172d Mon Sep 17 00:00:00 2001 From: Dong_master <2213070223@qq.com> Date: Thu, 24 Apr 2025 22:05:54 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E6=9C=89=E4=B8=80?= =?UTF-8?q?=E5=A4=84=E5=B0=86=E6=95=B0=E6=8D=AE=E5=BD=93=E4=BD=9Cbase64?= =?UTF-8?q?=E5=A4=84=E7=90=86=E5=B9=B6=E9=80=9A=E8=BF=87unknown=E4=B8=ADco?= =?UTF-8?q?ntent(=E4=BD=86=E6=98=AF=E6=B2=A1=E6=9C=89=E5=95=8A)=E4=BC=A0?= =?UTF-8?q?=E9=80=92=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/platform/sources/gewechat.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/pkg/platform/sources/gewechat.py b/pkg/platform/sources/gewechat.py index da4a6b99..06e1378b 100644 --- a/pkg/platform/sources/gewechat.py +++ b/pkg/platform/sources/gewechat.py @@ -219,18 +219,20 @@ class GewechatMessageConverter(adapter.MessageConverter): ) # print(data_type.text) else: - - - try: - content_bytes = content.encode('utf-8') - decoded_content = base64.b64decode(content_bytes) - return platform_message.MessageChain( - [platform_message.Unknown(text=decoded_content)] - ) # 不对劲,十分有九分不对劲这里这么写不对吧 - except Exception as e: - return platform_message.MessageChain( - [platform_message.Plain(text=content)] + return platform_message.MessageChain( + [platform_message.Unknown(text=content)] ) + + # try: + # content_bytes = content.encode('utf-8') + # decoded_content = base64.b64decode(content_bytes) + # return platform_message.MessageChain( + # [platform_message.Unknown(content=decoded_content)] + # ) # unknown中没有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(