From 5b38e3fd79973bb9d9019f916848b48dda5b1efa Mon Sep 17 00:00:00 2001 From: H Vs Date: Tue, 15 Apr 2025 10:38:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B6=88=E6=81=AF=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/gewe_service.py | 177 +++++++++++++++++++++++++++++++++++---- 1 file changed, 163 insertions(+), 14 deletions(-) diff --git a/services/gewe_service.py b/services/gewe_service.py index 43c0bcc..12a3b99 100644 --- a/services/gewe_service.py +++ b/services/gewe_service.py @@ -363,7 +363,116 @@ class GeWeService: async with session.post(api_url, headers=headers, json=data) as response: response_object = await response.json() return response_object.get('ret', None), response_object.get('msg', None), response_object.get('data', None) + + async def post_mini_app_aysnc(self, token_id, app_id,to_wxid, mini_app_id,display_name,page_path,cover_img_url,title,user_name): + ''' + 发送小程序消息 + ''' + api_url = f"{self.base_url}/v2/api/message/postMiniApp" + headers = { + 'X-GEWE-TOKEN': token_id, + 'Content-Type': 'application/json' + } + data = { + "appId": app_id, + "toWxid": to_wxid, + "miniAppId": mini_app_id, + "displayName": display_name, + "pagePath": page_path, + "coverImgUrl": cover_img_url, + "title": title, + "userName": user_name + } + + + 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('ret', None), response_object.get('msg', None), response_object.get('data', None) + + async def post_link_async(self,token_id, app_id,to_wxid, title,desc,link_url,thumb_url): + ''' + 发送链接消息 + ''' + api_url = f"{self.base_url}/v2/api/message/postLink" + headers = { + 'X-GEWE-TOKEN': token_id, + 'Content-Type': 'application/json' + } + data = { + "appId": app_id, + "toWxid": to_wxid, + "title": title, + "desc": desc, + "linkUrl": link_url, + "thumbUrl": thumb_url + } + 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('ret', None), response_object.get('msg', None), response_object.get('data', None) + async def post_name_card_async(self,token_id, app_id,to_wxid,nickName,nameCard_wxid): + ''' + 发送名片消息 + ''' + api_url = f"{self.base_url}/v2/api/message/postNameCard" + headers = { + 'X-GEWE-TOKEN': token_id, + 'Content-Type': 'application/json' + } + data = { + "appId": app_id, + "toWxid": to_wxid, + "nickName": nickName, + "nameCardWxid": nameCard_wxid + } + 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('ret', None), response_object.get('msg', None), response_object.get('data', None) + + # 发送emoji消息 + async def post_emoji_async(self,token_id, app_id,to_wxid,emoji_md5,emoji_size): + api_url = f"{self.base_url}/v2/api/message/postEmoji" + headers = { + 'X-GEWE-TOKEN': token_id, + 'Content-Type': 'application/json' + } + data = { + "appId": app_id, + "toWxid": to_wxid, + "emojiMd5": emoji_md5, + "emojiSize": emoji_size + } + 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('ret', None), response_object.get('msg', None), response_object.get('data', None) + + # 发送appmsg消息 + async def post_app_msg_async(self,token_id, app_id,to_wxid,appmsg): + ''' + 本接口可用于发送所有包含节点的消息,例如:音乐分享、视频号、引用消息等等 + ''' + api_url = f"{self.base_url}/v2/api/message/postAppMsg" + headers = { + 'X-GEWE-TOKEN': token_id, + 'Content-Type': 'application/json' + } + data = { + "appId": app_id, + "toWxid": to_wxid, + "appmsg": appmsg + } + + 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('ret', None), response_object.get('msg', None), response_object.get('data', None) + + + async def forward_image_async(self, token_id, app_id, to_wxid, aeskey, cdnthumburl, cdnthumblength, cdnthumbheight, cdnthumbwidth, length, md5): api_url = f"{self.base_url}/v2/api/message/forwardImage" @@ -397,6 +506,58 @@ class GeWeService: response_object = await response.json() return response_object.get('ret', None), response_object.get('msg', None), response_object.get('data', None) + # 转发文件 + async def forward_file_async(self, token_id, app_id, to_wxid, xml): + api_url = f"{self.base_url}/v2/api/message/forwardFile" + headers = { + 'X-GEWE-TOKEN': token_id, + 'Content-Type': 'application/json' + } + data = { + "appId": app_id, + "toWxid": to_wxid, + "xml": xml + } + 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('ret', None), response_object.get('msg', None), response_object.get('data', None) + + # 转发链接 + async def forward_link_async(self, token_id, app_id, to_wxid, xml): + api_url = f"{self.base_url}/v2/api/message/forwardLink" + headers = { + 'X-GEWE-TOKEN': token_id, + 'Content-Type': 'application/json' + } + data = { + "appId": app_id, + "toWxid": to_wxid, + "xml": xml + } + async with aiohttp.ClientSession() as session: + async with session.post(api_url, headers, json=data) as response: + response_object = await response.json() + return response_object.get('ret', None), response_object.get('msg', None), response_object.get('data', None) + + # 转发小程序 + async def forward_mini_app_async(self, token_id, app_id, to_wxid, xml,cover_img_url): + api_url = f"{self.base_url}/v2/api/message/forwardMiniApp" + headers = { + 'X-GEWE-TOKEN': token_id, + 'Content-Type': 'application/json' + } + data = { + "appId": app_id, + "toWxid": to_wxid, + "xml": xml, + "coverImgUrl":cover_img_url + } + 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('ret', None), response_object.get('msg', None), response_object.get('data', None) + async def add_contacts_async(self, token_id: str, app_id: str, scene: int, option: int, v3: str, v4: str, content: str): api_url = f"{self.base_url}/v2/api/contacts/addContacts" headers = { @@ -434,6 +595,8 @@ class GeWeService: response_object = await response.json() return response_object.get('ret', None), response_object.get('msg', None), response_object.get('data', None) + + ############################### 下载模块 ############################### async def download_audio_msg_async(self, token_id: str, app_id: str, msg_id: int, xml: str): data = { @@ -844,20 +1007,6 @@ class GeWeService: response_object = await response.json() return response_object.get('ret', None), response_object.get('msg', None), response_object.get('data', None) - # async def label_list_async(self, token_id, app_id): - # api_url = f"{self.base_url}/v2/api/label/list" - # headers = { - # 'X-GEWE-TOKEN': token_id, - # 'Content-Type': 'application/json' - # } - # data = { - # "appId": app_id, - # } - # 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('ret', None), response_object.get('msg', None), response_object.get('data', None) - async def label_list_async(self, token_id, app_id): api_url = f"{self.base_url}/v2/api/label/list" headers = {