- 按 864 router.go 修正联系人详情与群公告的真实接口路径 - 结合 CheckLoginStatus 返回结构补充 uuid 与 effective_time 同步,支持 Dashboard 倒计时与二维码自动刷新 - 更新多版本适配路线图,记录首轮 864 实服联调结论
89 lines
3.2 KiB
Python
89 lines
3.2 KiB
Python
from typing import Union
|
||
|
||
from wechat_ipad.providers.server_864.base import Server864APIClientBase
|
||
|
||
|
||
class FriendMixin(Server864APIClientBase):
|
||
"""864 联系人与通讯录相关接口。"""
|
||
|
||
async def get_contact(self, wxid: Union[str, list[str]]) -> Union[dict, list[dict]]:
|
||
"""获取联系人详情,兼容旧调用面。"""
|
||
detail_list = await self.get_contract_detail(wxid)
|
||
if isinstance(wxid, str):
|
||
return detail_list[0] if detail_list else {}
|
||
return detail_list
|
||
|
||
async def get_contract_detail(self, wxid: Union[str, list[str]], chatroom: str = "") -> list:
|
||
"""批量获取联系人详情。"""
|
||
user_names = [wxid] if isinstance(wxid, str) else list(wxid or [])
|
||
room_wxid_list = [chatroom] if chatroom else []
|
||
data = await self._request_data(
|
||
"post",
|
||
# 864 的联系人详情最终要以 router 注册路由为准:
|
||
# 1. controller 方法名虽然叫 `GetContactContactApi`;
|
||
# 2. 但真正暴露出来的 URL 是 `/friend/GetContactDetailsList`;
|
||
# 3. 因此这里按 router.go 的真实注册结果适配,避免继续命中 404。
|
||
"/friend/GetContactDetailsList",
|
||
json_body={"UserNames": user_names, "RoomWxIDList": room_wxid_list},
|
||
timeout=30,
|
||
)
|
||
|
||
if isinstance(data, list):
|
||
return data
|
||
if not isinstance(data, dict):
|
||
return []
|
||
|
||
contact_list = (
|
||
data.get("ContactList")
|
||
or data.get("contactList")
|
||
or data.get("MemberList")
|
||
or data.get("memberList")
|
||
or data.get("UserList")
|
||
or data.get("userList")
|
||
or []
|
||
)
|
||
return list(contact_list or [])
|
||
|
||
async def get_contract_list(self, wx_seq: int = 0, chatroom_seq: int = 0) -> list:
|
||
"""获取通讯录用户名列表。"""
|
||
data = await self._request_data(
|
||
"post",
|
||
"/friend/GetContactList",
|
||
json_body={
|
||
"CurrentWxcontactSeq": int(wx_seq),
|
||
"CurrentChatRoomContactSeq": int(chatroom_seq),
|
||
},
|
||
timeout=30,
|
||
)
|
||
if isinstance(data, list):
|
||
return data
|
||
if not isinstance(data, dict):
|
||
return []
|
||
return list(
|
||
data.get("ContactUsernameList")
|
||
or data.get("contactUsernameList")
|
||
or data.get("UserNames")
|
||
or data.get("userNames")
|
||
or []
|
||
)
|
||
|
||
async def get_nickname(self, wxid: Union[str, list[str]]) -> Union[str, list[str]]:
|
||
"""根据联系人详情返回昵称。"""
|
||
data = await self.get_contract_detail(wxid)
|
||
if isinstance(wxid, str):
|
||
if not data:
|
||
return ""
|
||
nickname = data[0].get("NickName")
|
||
if isinstance(nickname, dict):
|
||
return nickname.get("string", "")
|
||
return nickname or ""
|
||
|
||
result = []
|
||
for contact in data:
|
||
nickname = contact.get("NickName")
|
||
if isinstance(nickname, dict):
|
||
result.append(nickname.get("string", ""))
|
||
else:
|
||
result.append(nickname or "")
|
||
return result
|