From 27699d5727dfcfe914975bae5d27c011b3310445 Mon Sep 17 00:00:00 2001 From: H Vs Date: Tue, 15 Apr 2025 16:07:48 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=9B=BE=E7=89=87=E8=BD=AC?= =?UTF-8?q?=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/biz_service.py | 92 +++++++++++++++++++++++++++++++++-------- 1 file changed, 74 insertions(+), 18 deletions(-) diff --git a/services/biz_service.py b/services/biz_service.py index 61c096f..5129ad6 100644 --- a/services/biz_service.py +++ b/services/biz_service.py @@ -145,8 +145,16 @@ class BizService(): self.wxchat.forward_video_length = 0 self.wxchat.video_duration = 0 + self.wxchat.forward_image_aeskey = '' + self.wxchat.forward_image_cdnthumburl = '' + self.wxchat.forward_image_cdnthumblength=0 + self.wxchat.forward_image_cdnthumbheight=0 + self.wxchat.forward_image_cdnthumbwidth=0 + self.wxchat.forward_image_length=0 + self.wxchat.forward_image_md5='' + self.wxchat.forward_file_aeskey = '' - + for intersection_wxid in intersection_wxids: for wx_content in wx_content_list: if wx_content["type"] == "text": @@ -176,39 +184,39 @@ class BizService(): await asyncio.sleep(random.uniform(1.5, 3)) async def send_image_messagae_sync(self,token_id, app_id, agent_wxid, intersection_wxids, image_url): - aeskey, cdnthumburl, cdnthumblength, cdnthumbheight, cdnthumbwidth, length, md5 = "", "", 0, 0, 0, 0, "" + #aeskey, cdnthumburl, cdnthumblength, cdnthumbheight, cdnthumbwidth, length, md5 = "", "", 0, 0, 0, 0, "" for t in intersection_wxids: if t == intersection_wxids[0]: # 发送图片 ret,ret_msg,res = await self.wxchat.post_image_async(token_id, app_id, t, image_url) if ret==200: - aeskey = res["aesKey"] - cdnthumburl = res["fileId"] - cdnthumblength = res["cdnThumbLength"] - cdnthumbheight = res["height"] - cdnthumbwidth = res["width"] - length = res["length"] - md5 = res["md5"] + self.wxchat.forward_image_aeskey = res["aesKey"] + self.wxchat.forward_image_cdnthumburl = res["fileId"] + self.wxchat.forward_image_cdnthumblength = res["cdnThumbLength"] + self.wxchat.forward_image_cdnthumbheight = res["height"] + self.wxchat.forward_image_cdnthumbwidth = res["width"] + self.wxchat.forward_image_length = res["length"] + self.wxchat.forward_image_md5 = res["md5"] logger.info(f'{agent_wxid} 向 {t} 发送图片【{image_url}】{ret_msg}') else: logger.warning(f'{agent_wxid} 向 {t} 发送图片【{image_url}】{ret_msg}') else: - if aeskey !="": + if self.wxchat.forward_image_aeskey !="": # 转发图片 - ret,ret_msg,res = await self.wxchat.forward_image_async(token_id, app_id, t, aeskey, cdnthumburl, cdnthumblength, cdnthumbheight, cdnthumbwidth, length, md5) + ret,ret_msg,res = await self.wxchat.forward_image_async(token_id, app_id, t, self.wxchat.forward_image_aeskey, self.wxchat.forward_image_cdnthumburl, self.wxchat.forward_image_cdnthumblengt, self.wxchat.forward_image_cdnthumbheight, self.wxchat.forward_image_cdnthumbwidth, self.wxchat.forward_image_length, self.wxchat.forward_image_md5) logger.info(f'{agent_wxid} 向 {t} 转发图片【{image_url}】{ret_msg}') else: # 发送图片 ret,ret_msg,res = await self.wxchat.post_image_async(token_id, app_id, t, image_url) if ret==200: - aeskey = res["aesKey"] - cdnthumburl = res["fileId"] - cdnthumblength = res["cdnThumbLength"] - cdnthumbheight = res["height"] - cdnthumbwidth = res["width"] - length = res["length"] - md5 = res["md5"] + self.wxchat.forward_image_aeskey = res["aesKey"] + self.wxchat.forward_image_cdnthumburl = res["fileId"] + self.wxchat.forward_image_cdnthumblength = res["cdnThumbLength"] + self.wxchat.forward_image_cdnthumbheight = res["height"] + self.wxchat.forward_image_cdnthumbwidth = res["width"] + self.wxchat.forward_image_length = res["length"] + self.wxchat.forward_image_md5 = res["md5"] logger.info(f'{agent_wxid} 向 {t} 发送图片【{image_url}】{ret_msg}') else: logger.warning(f'{agent_wxid} 向 {t} 发送图片【{image_url}】{ret_msg}') @@ -222,6 +230,54 @@ class BizService(): # 等待随机时间 await asyncio.sleep(random.uniform(1.5, 3)) + + # async def send_image_messagae_sync(self,token_id, app_id, agent_wxid, intersection_wxids, image_url): + # aeskey, cdnthumburl, cdnthumblength, cdnthumbheight, cdnthumbwidth, length, md5 = "", "", 0, 0, 0, 0, "" + # for t in intersection_wxids: + # if t == intersection_wxids[0]: + # # 发送图片 + # ret,ret_msg,res = await self.wxchat.post_image_async(token_id, app_id, t, image_url) + # if ret==200: + # aeskey = res["aesKey"] + # cdnthumburl = res["fileId"] + # cdnthumblength = res["cdnThumbLength"] + # cdnthumbheight = res["height"] + # cdnthumbwidth = res["width"] + # length = res["length"] + # md5 = res["md5"] + # logger.info(f'{agent_wxid} 向 {t} 发送图片【{image_url}】{ret_msg}') + # else: + # logger.warning(f'{agent_wxid} 向 {t} 发送图片【{image_url}】{ret_msg}') + + # else: + # if aeskey !="": + # # 转发图片 + # ret,ret_msg,res = await self.wxchat.forward_image_async(token_id, app_id, t, aeskey, cdnthumburl, cdnthumblength, cdnthumbheight, cdnthumbwidth, length, md5) + # logger.info(f'{agent_wxid} 向 {t} 转发图片【{image_url}】{ret_msg}') + # else: + # # 发送图片 + # ret,ret_msg,res = await self.wxchat.post_image_async(token_id, app_id, t, image_url) + # if ret==200: + # aeskey = res["aesKey"] + # cdnthumburl = res["fileId"] + # cdnthumblength = res["cdnThumbLength"] + # cdnthumbheight = res["height"] + # cdnthumbwidth = res["width"] + # length = res["length"] + # md5 = res["md5"] + # logger.info(f'{agent_wxid} 向 {t} 发送图片【{image_url}】{ret_msg}') + # else: + # logger.warning(f'{agent_wxid} 向 {t} 发送图片【{image_url}】{ret_msg}') + + # # 构造对话消息并发送到 Kafka + # wx_content_dialogue_message = [{"type": "image_url", "image_url": {"url": image_url}}] + # input_message = dialogue_message(agent_wxid, t, wx_content_dialogue_message) + # await self.kafka_service.send_message_async(input_message) + # logger.info("发送对话 %s", input_message) + + # # 等待随机时间 + # await asyncio.sleep(random.uniform(1.5, 3)) + async def send_tts_message(self, token_id, app_id, agent_wxid, intersection_wxids, text): voice_during,voice_url=wx_voice(text)