如果长连接心跳失败,则尝试二次登录。

This commit is contained in:
liuwei
2025-05-07 10:37:17 +08:00
parent a04e99c9c1
commit 9a2d9f3f12
2 changed files with 26 additions and 0 deletions

View File

@@ -321,6 +321,11 @@ class Robot(Job):
self.LOG.warning("长连接心跳失败")
except Exception as e:
self.LOG.error(f"wechat_ipad heartbeat long: {e}")
success = await self.ipad_bot.twice_auto_auth()
if success:
self.LOG.debug("尝试二次登录成功")
else:
self.LOG.warning("尝试二次登录失败")
await asyncio.sleep(10)
async def _process_ipad_message(self, message: WxMessage):

View File

@@ -207,6 +207,27 @@ class LoginMixin(WechatAPIClientBase):
else:
self.error_handler(json_resp)
async def twice_auto_auth(self) -> bool:
"""二次登录。
Returns:
bool: 成功返回True否则返回False
Raises:
UserLoggedOut: 如果未登录时调用
根据error_handler处理错误
"""
if not self.wxid:
raise UserLoggedOut("请先登录")
async with aiohttp.ClientSession() as session:
response = await session.post(f'http://{self.ip}:{self.port}/api/Login/TwiceAutoAuth?wxid={self.wxid}')
json_resp = await response.json()
if json_resp.get("Success"):
return True
else:
self.error_handler(json_resp)
@staticmethod
def create_device_name() -> str:
"""生成一个随机的设备名。