From 152cf92df9ad84f57483549e4270a99119c12565 Mon Sep 17 00:00:00 2001 From: Nixevol Date: Mon, 9 Nov 2026 17:36:19 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=9D=E6=B4=BB=E6=97=B6=E7=BB=AD?= =?UTF-8?q?=E4=B8=8A=E5=8D=B3=E5=B8=AD=E6=9F=A5=E8=AF=A2=E7=9A=84=E5=8D=95?= =?UTF-8?q?=E7=82=B9=E7=A5=A8=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/api/http.py | 2 ++ backend/app/nqi/client.py | 10 ++++++++++ backend/app/tasks/runner.py | 2 ++ 3 files changed, 14 insertions(+) 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