diff --git a/backend/app/api/http.py b/backend/app/api/http.py index be98aa9..b7ad85f 100644 --- a/backend/app/api/http.py +++ b/backend/app/api/http.py @@ -259,6 +259,7 @@ async def nqi_finish(body: dict) -> dict: pass return {**_captcha_body(session_id, challenge), "status": "need_captcha", "message": message} challenge.password = "" + await client.renew_ticket() cookies = client.export_cookies() await client.aclose() drop(session_id) @@ -679,6 +680,7 @@ async def _resume(cookies: list): try: client.import_cookies(cookies) user = await client.current_user() + await client.renew_ticket() return user, client.export_cookies() except NqiAuthError: return None diff --git a/backend/app/nqi/client.py b/backend/app/nqi/client.py index 9af9171..63ebe92 100644 --- a/backend/app/nqi/client.py +++ b/backend/app/nqi/client.py @@ -315,6 +315,16 @@ class NqiClient: async def current_user(self) -> dict: return _public_user(await self._cas_user_payload()) + async def renew_ticket(self) -> bool: + """用单点票据进入即席查询。票据还有效时,这一步会把它续上。""" + from app.nqi.adhoc import ensure_session + + try: + await ensure_session(self) + except NqiAuthError: + return False + return True + async def touch_session(self) -> dict: data = await self._cas_user_payload() await self._touch_password() diff --git a/backend/app/tasks/runner.py b/backend/app/tasks/runner.py index ec54d53..0db1719 100644 --- a/backend/app/tasks/runner.py +++ b/backend/app/tasks/runner.py @@ -313,6 +313,8 @@ async def _touch(cookies: list): try: client.import_cookies(cookies) user = await client.touch_session() + if not await client.renew_ticket(): + logger.info("门户登录仍有效,单点票据没有续上") return True, user, client.export_cookies() except NqiAuthError: return False, None, cookies