补齐864登录态本地状态文件落盘

This commit is contained in:
liuwei
2026-05-07 14:20:55 +08:00
parent 97019f3c43
commit 9a149aa064

View File

@@ -107,6 +107,17 @@ class Server864RuntimeMixin:
"""确保 864 已完成登录。"""
if await self.is_logged_in():
await self._refresh_identity_from_profile(logger=logger)
# 864 在“服务端已经在线、ABOT 只是后启动”的场景下会直接走这里:
# 1. 之前这条分支只清理二维码态,没有补写本地 runtime_state
# 2. 这会让用户误以为“明明已经登录成功,却没有生成 provider 状态文件”;
# 3. 因此这里也统一补一次落盘,让首次接管现有登录态与扫码新登录的结果保持一致。
ipad_config["wxid"] = self.wxid
ipad_config["login_time"] = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
self._save_runtime_state(
state_path=state_path,
state_payload={"wxid": self.wxid, "login_time": ipad_config["login_time"]},
logger=logger,
)
await self._safe_callback(
on_login_qr_cleared,
{
@@ -384,6 +395,11 @@ class Server864RuntimeMixin:
os.makedirs(state_dir, exist_ok=True)
with open(normalized_path, "w", encoding="utf-8") as f:
toml.dump(state_payload, f)
# 这里显式打印最终落盘路径,方便线上排查“文件写到哪里去了”:
# 1. runtime_state 当前使用相对路径,最终位置会受启动工作目录影响;
# 2. 用户在切到 Docker / Windows 服务 / 脚本托管时,最容易在这里产生认知偏差;
# 3. 直接记录绝对路径后,出现“文件没找到”时就能立刻定位到真实写入位置。
logger.info(f"server_864 本地状态已写入: {os.path.abspath(normalized_path)}")
except Exception as e:
logger.warning(f"写入 server_864 本地状态失败: path={state_path}, error={e}")