Parcourir la source

调整图片转发

1257
H Vs il y a 1 semaine
Parent
révision
27699d5727
1 fichiers modifiés avec 74 ajouts et 18 suppressions
  1. +74
    -18
      services/biz_service.py

+ 74
- 18
services/biz_service.py Voir le fichier

@@ -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)


Chargement…
Annuler
Enregistrer