From ca25d0433f3ff727b54e457a292bdc4a79eedcab Mon Sep 17 00:00:00 2001 From: chenzhenkun Date: Thu, 14 Sep 2023 17:52:11 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=8E=A5=E8=AF=AD?= =?UTF-8?q?=E9=9F=B3=E5=9B=9E=E5=A4=8D=E5=A4=B1=E6=95=88=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- channel/wework/wework_channel.py | 3 +++ channel/wework/wework_message.py | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/channel/wework/wework_channel.py b/channel/wework/wework_channel.py index b82935f..722cc3e 100644 --- a/channel/wework/wework_channel.py +++ b/channel/wework/wework_channel.py @@ -302,5 +302,8 @@ class WeworkChannel(ChatChannel): wework.send_video(receiver, video_path) logger.info("[WX] sendVideo, receiver={}".format(receiver)) elif reply.type == ReplyType.VOICE: + current_dir = os.getcwd() + voice_file = reply.content.split("/")[-1] + reply.content = os.path.join(current_dir, "tmp", voice_file) wework.send_file(receiver, reply.content) logger.info("[WX] sendFile={}, receiver={}".format(reply.content, receiver)) diff --git a/channel/wework/wework_message.py b/channel/wework/wework_message.py index bd08091..e9f1187 100644 --- a/channel/wework/wework_message.py +++ b/channel/wework/wework_message.py @@ -69,6 +69,12 @@ def c2c_download_and_convert(wework, message, file_name): wav_file = base_name + ".wav" pilk.silk_to_wav(save_path, wav_file, rate=24000) + # 删除SILK文件 + try: + os.remove(save_path) + except Exception as e: + pass + class WeworkMessage(ChatMessage): def __init__(self, wework_msg, wework, is_group=False): From ba6c671051a5df74672d9384f3a63a01de0adcbb Mon Sep 17 00:00:00 2001 From: chenzhenkun Date: Thu, 14 Sep 2023 23:39:07 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=94=B6=E5=88=B0?= =?UTF-8?q?=E5=9B=BE=E7=89=87=E6=B6=88=E6=81=AF=E4=BF=9D=E5=AD=98=E5=88=B0?= =?UTF-8?q?=E6=9C=AC=E5=9C=B0=E5=A4=B1=E8=B4=A5=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- channel/chat_channel.py | 6 ++++-- channel/wework/wework_message.py | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/channel/chat_channel.py b/channel/chat_channel.py index 6d904d3..4aa17be 100644 --- a/channel/chat_channel.py +++ b/channel/chat_channel.py @@ -202,8 +202,10 @@ class ChatChannel(Channel): reply = self._generate_reply(new_context) else: return - elif context.type == ContextType.IMAGE or context.type == ContextType.FUNCTION \ - or context.type == ContextType.FILE: # 图片/文件消息及函数调用等,当前无默认逻辑 + elif context.type == ContextType.IMAGE: # 图片消息,当前仅做下载保存到本地的逻辑 + cmsg = context["msg"] + cmsg.prepare() + elif context.type == ContextType.FUNCTION or context.type == ContextType.FILE: # 文件消息及函数调用等,当前无默认逻辑 pass else: logger.error("[WX] unknown context type: {}".format(context.type)) diff --git a/channel/wework/wework_message.py b/channel/wework/wework_message.py index e9f1187..dd24aa4 100644 --- a/channel/wework/wework_message.py +++ b/channel/wework/wework_message.py @@ -39,16 +39,16 @@ def get_room_info(wework, conversation_id): def cdn_download(wework, message, file_name): data = message["data"] - url = data["cdn"]["url"] - auth_key = data["cdn"]["auth_key"] aes_key = data["cdn"]["aes_key"] file_size = data["cdn"]["size"] + file_type = 2 + file_id = data["cdn"]["file_id"] # 获取当前工作目录,然后与文件名拼接得到保存路径 current_dir = os.getcwd() save_path = os.path.join(current_dir, "tmp", file_name) - result = wework.wx_cdn_download(url, auth_key, aes_key, file_size, save_path) + result = wework.c2c_cdn_download(file_id, aes_key, file_size, file_type, save_path) logger.debug(result)