接入GetLoginStatus增强864登录态判定

This commit is contained in:
liuwei
2026-05-07 15:28:36 +08:00
parent 1d8bf58014
commit 537a3d49e1
3 changed files with 100 additions and 1 deletions

View File

@@ -534,6 +534,31 @@ class Server864RuntimeMixin:
profile = await self.get_profile()
except Exception as e:
error_message = str(e).strip()
# `GetProfile` 失败时,再用 `GetLoginStatus` 补做一次登录态与身份判定:
# 1. 用户当前联调里已经确认 `GetLoginStatus` 可用,而 `GetProfile` / `GetInItStatus` 在部分阶段会直接报“该链接不存在”;
# 2. 若此时登录状态接口其实还能返回在线和账号字段,就没必要仅因资料接口异常而误判整轮登录失败;
# 3. 因此这里把它作为资料接口失败后的第一优先补偿探针,尽量保住已经完成的登录链路。
try:
login_status = await self.get_login_status(auto_login=False)
except Exception as status_error:
logger.warning(
f"server_864 登录状态补偿探针也失败,无法确认当前账号身份: {error_message}; "
f"GetLoginStatus={status_error}"
)
else:
if self._is_online_from_login_status_payload(login_status):
identity = self._extract_login_identity_from_status(login_status)
self.wxid = identity.get("wxid", self.wxid)
self.nickname = identity.get("nickname", self.nickname)
self.alias = identity.get("alias", self.alias)
self.phone = identity.get("phone", self.phone)
self.signature = identity.get("signature", self.signature)
if self.wxid or self.nickname:
logger.info(
"server_864 资料接口失败,但已通过 GetLoginStatus 补确认当前账号身份: "
f"wxid={self.wxid} nickname={self.nickname}"
)
return True
# 864 有些版本在消息链路可用后,资料接口仍可能短时间不可用:
# 1. 此时若直接抛异常,会让“已经登录成功”的启动流程被资料查询反向拖垮;
# 2. 但如果当前连 `wxid/nickname` 都没有,就不能再假装“已经有可用身份”;