From f7458572edce0d0672a0ef630ed418805d424f70 Mon Sep 17 00:00:00 2001 From: Zhenyi Wang Date: Sat, 17 May 2025 15:31:12 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20wechatpadpro=E5=AF=B9=E6=8E=A5=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E8=81=94=E7=B3=BB=E4=BA=BA=E4=BF=A1=E6=81=AF=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wechatpadpro/wechatpadpro_adapter.py | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/astrbot/core/platform/sources/wechatpadpro/wechatpadpro_adapter.py b/astrbot/core/platform/sources/wechatpadpro/wechatpadpro_adapter.py index 47d4fa9d..1295db5a 100644 --- a/astrbot/core/platform/sources/wechatpadpro/wechatpadpro_adapter.py +++ b/astrbot/core/platform/sources/wechatpadpro/wechatpadpro_adapter.py @@ -627,3 +627,68 @@ class WeChatPadProAdapter(Platform): ) # 调用实例方法 send await sending_event.send(message_chain) + + + async def get_contact_list(self): + """ + 获取联系人列表。 + """ + url = f"{self.base_url}/friend/GetContactList" + params = {"key": self.auth_key} + payload = { + "CurrentChatRoomContactSeq": 0, + "CurrentWxcontactSeq": 0 + } + async with aiohttp.ClientSession() as session: + try: + async with session.post(url, params=params, json=payload) as response: + if response.status == 200: + result = await response.json() + if result.get("Code") == 200 and result.get("Data"): + contact_list = result.get("Data", {}).get("ContactList", {}).get("contactUsernameList", []) + return contact_list + else: + logger.error(f"获取联系人列表失败: {result}") + return None + else: + logger.error(f"获取联系人列表失败: {response.status}") + return None + except aiohttp.ClientConnectorError as e: + logger.error(f"连接到 WeChatPadPro 服务失败: {e}") + return None + except Exception as e: + logger.error(f"获取联系人列表时发生错误: {e}") + return None + + async def get_contact_details_list(self, room_wx_id_list: [str] = [], user_names : [str] = []) -> Optional[dict]: + """ + 获取联系人详情列表。 + """ + url = f"{self.base_url}/friend/GetContactDetailsList" + params = {"key": self.auth_key} + payload = { + "RoomWxIDList": room_wx_id_list, + "UserNames": user_names + } + async with aiohttp.ClientSession() as session: + try: + async with session.post(url, params=params, json=payload) as response: + if response.status == 200: + result = await response.json() + if result.get("Code") == 200 and result.get("Data"): + contact_list = result.get("Data", {}).get("contactList", {}) + return contact_list + else: + logger.error(f"获取联系人详情列表失败: {result}") + return None + else: + logger.error(f"获取联系人详情列表失败: {response.status}") + return None + except aiohttp.ClientConnectorError as e: + logger.error(f"连接到 WeChatPadPro 服务失败: {e}") + return None + except Exception as e: + logger.error(f"获取联系人详情列表时发生错误: {e}") + return None + + \ No newline at end of file