From 90cdff327c43b0a6debe5deeff55a3307fcfe67e Mon Sep 17 00:00:00 2001 From: chenzhenkun Date: Fri, 15 Sep 2023 19:07:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=94=B6=E5=88=B0=E4=BB=8E?= =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E5=8F=91=E5=87=BA=E7=9A=84=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E4=BF=9D=E5=AD=98=E5=88=B0=E6=9C=AC=E5=9C=B0?= =?UTF-8?q?=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/wework/wework_message.py | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/channel/wework/wework_message.py b/channel/wework/wework_message.py index dd24aa4..e95dfb1 100644 --- a/channel/wework/wework_message.py +++ b/channel/wework/wework_message.py @@ -8,6 +8,7 @@ import pilk from bridge.context import ContextType from channel.chat_message import ChatMessage from common.log import logger +from ntwork.const import send_type def get_with_retry(get_func, max_retries=5, delay=5): @@ -41,15 +42,37 @@ def cdn_download(wework, message, file_name): data = message["data"] 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.c2c_cdn_download(file_id, aes_key, file_size, file_type, save_path) - logger.debug(result) + # 下载保存图片到本地 + if "url" in data["cdn"].keys() and "auth_key" in data["cdn"].keys(): + url = data["cdn"]["url"] + auth_key = data["cdn"]["auth_key"] + # result = wework.wx_cdn_download(url, auth_key, aes_key, file_size, save_path) # ntwork库本身接口有问题,缺失了aes_key这个参数 + """ + 下载wx类型的cdn文件,以https开头 + """ + data = { + 'url': url, + 'auth_key': auth_key, + 'aes_key': aes_key, + 'size': file_size, + 'save_path': save_path + } + result = wework._WeWork__send_sync(send_type.MT_WXCDN_DOWNLOAD_MSG, data) # 直接用wx_cdn_download的接口内部实现来调用 + elif "file_id" in data["cdn"].keys(): + file_type = 2 + file_id = data["cdn"]["file_id"] + result = wework.c2c_cdn_download(file_id, aes_key, file_size, file_type, save_path) + else: + logger.error(f"something is wrong, data: {data}") + return + + # 输出下载结果 + logger.debug(f"result: {result}") def c2c_download_and_convert(wework, message, file_name):