H Vs пре 12 часа
родитељ
комит
bf79f7cbd3
2 измењених фајлова са 47 додато и 88 уклоњено
  1. +46
    -87
      services/biz_service.py
  2. +1
    -1
      services/gewe_service.py

+ 46
- 87
services/biz_service.py Прегледај датотеку

@@ -155,6 +155,15 @@ class BizService():
self.wxchat.forward_image_length=0
self.wxchat.forward_image_md5=''


self.wxchat.wxid_forward_image_aeskey = {agent_wxid:''}
self.wxchat.wxid_forward_image_cdnthumburl = {agent_wxid:''}
self.wxchat.wxid_forward_image_cdnthumblength={agent_wxid:0}
self.wxchat.wxid_forward_image_cdnthumbheigth={agent_wxid:0}
self.wxchat.wxid_forward_image_cdnthumbwidth={agent_wxid:0}
self.wxchat.wxid_forward_image_length={agent_wxid:0}
self.wxchat.wxid_forward_image_md5={agent_wxid:''}

self.wxchat.forward_file_aeskey = ''

for intersection_wxid in intersection_wxids:
@@ -162,7 +171,7 @@ class BizService():
if wx_content["type"] == "text":
await self.send_text_message_async(token_id, app_id, agent_wxid, [intersection_wxid], wx_content["text"])
elif wx_content["type"] == "image_url":
await self.send_image_messagae_sync(token_id, app_id, agent_wxid, [intersection_wxid], wx_content.get("image_url", {}).get("url"))
await self.send_image_message_sync(token_id, app_id, agent_wxid, intersection_wxid, wx_content.get("image_url", {}).get("url"))
elif wx_content["type"] == "tts":
await self.send_tts_message(token_id, app_id, agent_wxid, [intersection_wxid], wx_content["text"])
elif wx_content["type"] == "file":
@@ -183,44 +192,41 @@ 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:
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 self.wxchat.forward_image_aeskey !="":
# 转发图片
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:
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}')
async def send_image_message_sync(self,token_id, app_id, agent_wxid, t, image_url):
if self.wxchat.wxid_forward_image_aeskey[agent_wxid] !="":
# 转发图片
ret,ret_msg,res = await self.wxchat.forward_image_async(token_id, app_id, t,
self.wxchat.wxid_forward_image_aeskey[agent_wxid],
self.wxchat.wxid_forward_image_cdnthumburl[agent_wxid],
self.wxchat.wxid_forward_image_cdnthumblength[agent_wxid],
self.wxchat.wxid_forward_image_cdnthumbheigth[agent_wxid],
self.wxchat.wxid_forward_image_cdnthumbwidth[agent_wxid],
self.wxchat.wxid_forward_image_length[agent_wxid],
self.wxchat.wxid_forward_image_md5[agent_wxid])
logger.info(f'{agent_wxid} 向 {t} 转发图片【{image_url}】{ret_msg}')
if ret!=200:
logger.warning(f'{agent_wxid} 向 {t} 转发图片【{image_url}】{ret_msg}')
return
else:

# 发送图片
ret,ret_msg,res = await self.wxchat.post_image_async(token_id, app_id, t, image_url)
if ret==200:
self.wxchat.wxid_forward_image_aeskey[agent_wxid] = res["aesKey"]
self.wxchat.wxid_forward_image_cdnthumburl[agent_wxid] = res["fileId"]
self.wxchat.wxid_forward_image_cdnthumblength[agent_wxid] = res["cdnThumbLength"]
self.wxchat.wxid_forward_image_cdnthumbheigth[agent_wxid] = res["height"]
self.wxchat.wxid_forward_image_cdnthumbwidth[agent_wxid] = res["width"]
self.wxchat.wxid_forward_image_length[agent_wxid] = res["length"]
self.wxchat.wxid_forward_image_md5[agent_wxid] = res["md5"]
logger.info(f'{agent_wxid} 向 {t} 发送图片【{image_url}】{ret_msg}')
else:
logger.warning(f'{agent_wxid} 向 {t} 发送图片【{image_url}】{ret_msg}')
return

# 构造对话消息并发送到 Kafka
wx_content_dialogue_message = [{"type": "image_url", "image_url": {"url": image_url}}]
input_message = dialogue_message(agent_wxid, t, wx_content_dialogue_message)
@@ -228,55 +234,8 @@ class BizService():
logger.info("发送对话 %s", input_message)
# 等待随机时间
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))
await asyncio.sleep(random.uniform(1.5, 3))

async def send_tts_message(self, token_id, app_id, agent_wxid, intersection_wxids, text):
@@ -574,7 +533,7 @@ class BizService():
if wx_content["type"] == "text":
await self.send_text_message_async(token_id, app_id, biz_assistant_wxid, [wxid], wx_content["text"])
elif wx_content["type"] == "image_url":
await self.send_image_messagae_sync(token_id, app_id, biz_assistant_wxid, [wxid], wx_content.get("image_url", {}).get("url"))
await self.send_image_message_sync(token_id, app_id, biz_assistant_wxid, wxid, wx_content.get("image_url", {}).get("url"))
elif wx_content["type"] == "tts":
await self.send_tts_message(token_id, app_id, biz_assistant_wxid, [wxid], wx_content["text"])
elif wx_content["type"] == "file":


+ 1
- 1
services/gewe_service.py Прегледај датотеку

@@ -496,7 +496,7 @@ class GeWeService:
async with aiohttp.ClientSession() as session:
async with session.post(api_url, headers=headers, json=data) as response:
response_object = await response.json()
return response_object.get('data', None), response_object.get('ret', None), response_object.get('msg', None)
return response_object.get('ret', None), response_object.get('msg', None), response_object.get('data', None)
async def forward_video_async(self, token_id, app_id, to_wxid, aeskey, cdnvideourl, length,video_duration):
api_url = f"{self.base_url}/v2/api/message/forwardVideo"


Loading…
Откажи
Сачувај