From 9d6f61b49e39ce0aa7f7e2f6bdccf6c09d449b1d Mon Sep 17 00:00:00 2001 From: beat4ocean Date: Tue, 11 Mar 2025 08:48:37 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E9=9D=9E=E7=AC=AC?= =?UTF-8?q?=E4=B8=80=E6=AC=A1=E7=99=BB=E9=99=86=E6=83=85=E5=86=B5=EF=BC=8C?= =?UTF-8?q?=E5=B7=B2=E8=AE=B0=E5=BD=95=E7=9A=84gewechat=E7=9A=84appid?= =?UTF-8?q?=E5=A4=B1=E6=95=88=E8=AE=BE=E5=A4=87=E4=B8=8D=E5=AD=98=E5=9C=A8?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E6=97=A0=E6=B3=95=E9=87=8D=E6=96=B0=E7=99=BB?= =?UTF-8?q?=E9=99=86=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/platform/sources/gewechat/client.py | 55 ++++++++++++------- 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/astrbot/core/platform/sources/gewechat/client.py b/astrbot/core/platform/sources/gewechat/client.py index 1c3b8bd0b..a9b9ebe3d 100644 --- a/astrbot/core/platform/sources/gewechat/client.py +++ b/astrbot/core/platform/sources/gewechat/client.py @@ -309,32 +309,47 @@ class SimpleGewechatClient: ) if self.appid: - online = await self.check_online(self.appid) - if online: - logger.info(f"APPID: {self.appid} 已在线") - return + try: + online = await self.check_online(self.appid) + if online: + logger.info(f"APPID: {self.appid} 已在线") + return + except Exception as e: + logger.error(f"检查在线状态失败: {e}") + sp.put(f"gewechat-appid-{self.nickname}", "") + self.appid = None payload = {"appId": self.appid} if self.appid: logger.info(f"使用 APPID: {self.appid}, {self.nickname}") - async with aiohttp.ClientSession() as session: - async with session.post( - f"{self.base_url}/login/getLoginQrCode", - headers=self.headers, - json=payload, - ) as resp: - json_blob = await resp.json() - if json_blob["ret"] != 200: - raise Exception(f"获取二维码失败: {json_blob}") - qr_data = json_blob["data"]["qrData"] - qr_uuid = json_blob["data"]["uuid"] - appid = json_blob["data"]["appId"] - logger.info(f"APPID: {appid}") - logger.warning( - f"请打开该网址,然后使用微信扫描二维码登录: https://api.cl2wm.cn/api/qrcode/code?text={qr_data}" - ) + try: + async with aiohttp.ClientSession() as session: + async with session.post( + f"{self.base_url}/login/getLoginQrCode", + headers=self.headers, + json=payload, + ) as resp: + json_blob = await resp.json() + if json_blob["ret"] != 200: + error_msg = json_blob.get("data", {}).get("msg", "") + if "设备不存在" in error_msg: + logger.error(f"检测到无效的appid: {self.appid},将清除并重新登录。") + sp.put(f"gewechat-appid-{self.nickname}", "") + self.appid = None + return await self.login() + else: + raise Exception(f"获取二维码失败: {json_blob}") + qr_data = json_blob["data"]["qrData"] + qr_uuid = json_blob["data"]["uuid"] + appid = json_blob["data"]["appId"] + logger.info(f"APPID: {appid}") + logger.warning( + f"请打开该网址,然后使用微信扫描二维码登录: https://api.cl2wm.cn/api/qrcode/code?text={qr_data}" + ) + except Exception as e: + raise e # 执行登录 retry_cnt = 64