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