From d34711062db8d456eb2ab0c6fbf52409a1d5c3fe Mon Sep 17 00:00:00 2001 From: Qiufeng Date: Fri, 21 Aug 2026 16:42:38 +0800 Subject: [PATCH] =?UTF-8?q?fix(tencent):=20=E4=BF=AE=E5=A4=8D=E6=89=AB?= =?UTF-8?q?=E7=A0=81=E6=88=90=E5=8A=9F=E5=88=A4=E5=AE=9A=E2=80=94=E2=80=94?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E5=90=8E=E5=81=9C=E5=9C=A8=20/platform=20?= =?UTF-8?q?=E9=A6=96=E9=A1=B5=E4=B9=9F=E8=A7=86=E4=B8=BA=E6=88=90=E5=8A=9F?= =?UTF-8?q?=EF=BC=9B=E6=89=AB=E7=A0=81/=E8=BF=87=E6=9C=9F=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E5=AE=9E=E6=97=B6=E6=8E=A8=E7=BB=99=E5=89=8D=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sau_backend.py | 3 ++ uploader/tencent_uploader/main.py | 52 +++++++++++++++++++++---------- 2 files changed, 38 insertions(+), 17 deletions(-) diff --git a/sau_backend.py b/sau_backend.py index 54ee393..e540efd 100644 --- a/sau_backend.py +++ b/sau_backend.py @@ -764,6 +764,9 @@ def _qrcode_to_queue(status_queue): if isinstance(payload, dict): data_url = payload.get("image_data_url") or "" image_path = payload.get("image_path") or "" + status_text = payload.get("status_text") or "" + if status_text: + status_queue.put(status_text) if data_url: status_queue.put(data_url) elif image_path and os.path.exists(image_path): diff --git a/uploader/tencent_uploader/main.py b/uploader/tencent_uploader/main.py index 03de41e..9fc04d9 100644 --- a/uploader/tencent_uploader/main.py +++ b/uploader/tencent_uploader/main.py @@ -236,6 +236,38 @@ async def _save_tencent_qrcode(page: Page, account_file: str, previous_qrcode_pa async def _is_tencent_login_completed(page: Page) -> bool: + # 仍在登录页(含扫码 iframe)=> 未登录 + current_url = page.url or "" + if "login.html" in current_url: + return False + + # 页面内还存在微信扫码登录 iframe => 未登录 + try: + for fr in page.frames: + if "open.weixin.qq.com/connect/qrconnect" in (fr.url or ""): + return False + except Exception: + pass + + # 页面内还存在登录二维码容器 => 未登录 + login_markers = [ + page.locator("div.login-qrcode-wrap").first, + page.locator("div.qrcode-wrap").first, + page.locator('span:has-text("微信扫码登录 视频号助手")').first, + ] + for marker in login_markers: + try: + if await marker.count() and await marker.is_visible(): + return False + except Exception: + continue + + # 已离开登录页且登录框/二维码均消失 => 视为登录成功 + # (视频号登录后通常停在 /platform 首页,不一定跳到 post/create 或 post/list) + if current_url.startswith(TENCENT_HOME_URL) or current_url.startswith(TENCENT_UPLOAD_URL) or current_url.startswith(TENCENT_MANAGE_URL): + return True + + # 兜底:出现发布相关按钮也视为成功 publish_markers = [ page.locator('div:has-text("发表视频")').first, page.locator('button:has-text("发表")').first, @@ -248,23 +280,7 @@ async def _is_tencent_login_completed(page: Page) -> bool: except Exception: continue - if not (page.url.startswith(TENCENT_UPLOAD_URL) or page.url.startswith(TENCENT_MANAGE_URL)): - return False - - login_markers = [ - page.locator("div.login-qrcode-wrap").first, - page.locator("div.qrcode-wrap").first, - page.locator("img.qrcode").first, - page.locator('span:has-text("微信扫码登录 视频号助手")').first, - ] - for marker in login_markers: - try: - if await marker.count() and await marker.is_visible(): - return False - except Exception: - continue - - return True + return False async def _is_tencent_qrcode_expired(page: Page) -> bool: @@ -360,9 +376,11 @@ async def _wait_for_tencent_login( if not scanned_logged and await _is_tencent_qrcode_scanned(page): tencent_logger.info(_msg("📱", "已经扫码啦,还差手机端确认一下")) scanned_logged = True + await _emit_qrcode_callback(qrcode_callback, {"status_text": "已扫码,请在手机上确认登录"}) if await _is_tencent_qrcode_expired(page): tencent_logger.warning(_msg("😵", "二维码失效了,小人马上去刷新")) + await _emit_qrcode_callback(qrcode_callback, {"status_text": "二维码已过期,正在刷新..."}) await _refresh_tencent_qrcode(page) await asyncio.sleep(1) try: