diff --git a/app/endpoints/pipeline_endpoint.py b/app/endpoints/pipeline_endpoint.py index 943732e..1edff10 100644 --- a/app/endpoints/pipeline_endpoint.py +++ b/app/endpoints/pipeline_endpoint.py @@ -189,6 +189,7 @@ async def handle_add_messages_async(request: Request,token_id,msg,wxid): 3: handle_image_async, 34: handle_voice_async, 42: handle_name_card_async, + 43: handle_video_async, 49: handle_xml_async, 37: handle_add_friend_notice_async, 10002: handle_10002_msg_async, @@ -1015,6 +1016,25 @@ async def handle_name_card_async(request: Request,token_id,app_id, wxid,msg_data except Exception as e: logger.error(f"未知错误: {e}") +async def handle_video_async(request: Request,token_id,app_id, wxid,msg_data,from_wxid, to_wxid): + logger.info('视频消息') + try: + msg_content_xml=msg_data["Content"]["string"] + video_url=await request.app.state.gewe_service.download_video_msg_async(token_id,app_id,msg_content_xml) + if not video_url: + logger.warning(f'处理视频消息异常') + return + callback_to_user=from_wxid + print(video_url) + wx_content_dialogue_message = [{"type": "file", "file_url": {"url":video_url}}] + k_message = dialogue_message(callback_to_user,wxid, wx_content_dialogue_message) + await request.app.state.kafka_service.send_message_async(k_message) + logger.info("发送对话 %s",k_message) + except Exception as e: + logger.error(f"出现错误: {e}") + + + async def handle_xml_async(request: Request,token_id,app_id, wxid,msg_data,from_wxid, to_wxid): ''' 处理xml diff --git a/services/gewe_service.py b/services/gewe_service.py index a4e7ba4..e5f24c4 100644 --- a/services/gewe_service.py +++ b/services/gewe_service.py @@ -685,6 +685,29 @@ class GeWeService: else: return None + async def download_video_msg_async(self, token_id: str, app_id: str, xml: str): + data = { + "appId": app_id, + "xml": xml + } + headers = { + 'X-GEWE-TOKEN': token_id, + 'Content-Type': 'application/json' + } + url = f'{self.base_url}/v2/api/message/downloadVideo' + async with aiohttp.ClientSession() as session: + async with session.post(url, json=data, headers=headers) as response: + if response.ok: + data = await response.json() + if data['ret'] == 200: + return data['data']['fileUrl'] + else: + logger.warning(f'下载视频失败 {data.get("ret", None),data.get("msg", None), data.get("data", None)}') + return False + else: + logger.warning(f'下载视频失败 {response.status} {response.reason}') + return False + ############################### 群模块 ############################### async def get_chatroom_info_async(self, token_id, app_id, chatroom_id): '''