feat: wechatpadpro对接获取联系人信息接口

This commit is contained in:
Zhenyi Wang
2025-05-17 15:31:12 +08:00
parent d57b7222b2
commit f7458572ed
@@ -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