|
@@ -27,7 +27,7 @@ class BizService(): |
|
|
def __init__(self,app:FastAPI): |
|
|
def __init__(self,app:FastAPI): |
|
|
if not hasattr(self, 'initialized'): |
|
|
if not hasattr(self, 'initialized'): |
|
|
#self.kafka_service =kafka_service # 获取 KafkaService 单例 |
|
|
#self.kafka_service =kafka_service # 获取 KafkaService 单例 |
|
|
self.kafka_service =app.state.kafka_service |
|
|
|
|
|
|
|
|
self.kafka_service:KafkaService =app.state.kafka_service |
|
|
self.wxchat:GeWeService=app.state.gewe_service |
|
|
self.wxchat:GeWeService=app.state.gewe_service |
|
|
self.redis_service:RedisService=app.state.redis_service |
|
|
self.redis_service:RedisService=app.state.redis_service |
|
|
self.initialized = True |
|
|
self.initialized = True |
|
@@ -145,6 +145,8 @@ class BizService(): |
|
|
self.wxchat.forward_video_length = 0 |
|
|
self.wxchat.forward_video_length = 0 |
|
|
self.wxchat.video_duration = 0 |
|
|
self.wxchat.video_duration = 0 |
|
|
|
|
|
|
|
|
|
|
|
self.wxchat.forward_file_aeskey = '' |
|
|
|
|
|
|
|
|
for intersection_wxid in intersection_wxids: |
|
|
for intersection_wxid in intersection_wxids: |
|
|
for wx_content in wx_content_list: |
|
|
for wx_content in wx_content_list: |
|
|
if wx_content["type"] == "text": |
|
|
if wx_content["type"] == "text": |
|
@@ -156,6 +158,8 @@ class BizService(): |
|
|
elif wx_content["type"] == "file": |
|
|
elif wx_content["type"] == "file": |
|
|
await self.send_file_message(token_id, app_id, agent_wxid, [intersection_wxid], wx_content.get("file_url", {}).get("url")) |
|
|
await self.send_file_message(token_id, app_id, agent_wxid, [intersection_wxid], wx_content.get("file_url", {}).get("url")) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def send_text_message_async(self, token_id, app_id, agent_wxid, intersection_wxids, text): |
|
|
async def send_text_message_async(self, token_id, app_id, agent_wxid, intersection_wxids, text): |
|
|
for t in intersection_wxids: |
|
|
for t in intersection_wxids: |
|
|
# 发送文本消息 |
|
|
# 发送文本消息 |
|
@@ -251,6 +255,8 @@ class BizService(): |
|
|
|
|
|
|
|
|
if ext == '.mp4': |
|
|
if ext == '.mp4': |
|
|
await self.send_video_message(token_id, app_id, agent_wxid, intersection_wxids, file_url) |
|
|
await self.send_video_message(token_id, app_id, agent_wxid, intersection_wxids, file_url) |
|
|
|
|
|
# if ext == '.pdf': |
|
|
|
|
|
# await self.send_pdf_message_async(token_id, app_id, agent_wxid, intersection_wxids, file_url) |
|
|
else: |
|
|
else: |
|
|
await self.send_other_file_message(token_id, app_id, agent_wxid, intersection_wxids, file_url) |
|
|
await self.send_other_file_message(token_id, app_id, agent_wxid, intersection_wxids, file_url) |
|
|
#time.sleep(random.uniform(1.5, 3)) |
|
|
#time.sleep(random.uniform(1.5, 3)) |
|
@@ -288,8 +294,27 @@ class BizService(): |
|
|
# 等待随机时间 |
|
|
# 等待随机时间 |
|
|
await asyncio.sleep(random.uniform(1.5, 3)) |
|
|
await asyncio.sleep(random.uniform(1.5, 3)) |
|
|
|
|
|
|
|
|
|
|
|
async def send_pdf_message_async(self, token_id, app_id, agent_wxid, intersection_wxids, file_url): |
|
|
|
|
|
print('send_pdf_message_async') |
|
|
|
|
|
|
|
|
async def send_other_file_message(self, token_id, app_id, agent_wxid, intersection_wxids, file_url): |
|
|
async def send_other_file_message(self, token_id, app_id, agent_wxid, intersection_wxids, file_url): |
|
|
print('send_otherfile_message') |
|
|
|
|
|
|
|
|
parsed_url = urlparse(file_url) |
|
|
|
|
|
filename = os.path.basename(parsed_url.path) |
|
|
|
|
|
for t in intersection_wxids: |
|
|
|
|
|
# 发送文件消息 |
|
|
|
|
|
ret,ret_msg,res = await self.wxchat.post_file_async(token_id, app_id, t, file_url,filename) |
|
|
|
|
|
if ret==200: |
|
|
|
|
|
logger.info(f'{agent_wxid} 向 {t} 发送文件【{file_url}】{ret_msg}') |
|
|
|
|
|
# 构造对话消息并发送到 Kafka |
|
|
|
|
|
input_wx_content_dialogue_message = [{"type": "file", "file_url": {"url": file_url}}] |
|
|
|
|
|
input_message = dialogue_message(agent_wxid, t, input_wx_content_dialogue_message) |
|
|
|
|
|
await self.kafka_service.send_message_async(input_message) |
|
|
|
|
|
logger.info("发送对话 %s", input_message) |
|
|
|
|
|
else: |
|
|
|
|
|
logger.warning((f'{agent_wxid} 向 {t} 发送文件【{file_url}】{ret_msg}')) |
|
|
|
|
|
|
|
|
|
|
|
# 等待随机时间 |
|
|
|
|
|
await asyncio.sleep(random.uniform(1.5, 3)) |
|
|
|
|
|
|
|
|
async def sns_sendtext_forward_handler_async(self,content_data): |
|
|
async def sns_sendtext_forward_handler_async(self,content_data): |
|
|
wxids=content_data.get('wxids',[]) |
|
|
wxids=content_data.get('wxids',[]) |
|
|