diff --git a/astrbot/core/platform/sources/gewechat/client.py b/astrbot/core/platform/sources/gewechat/client.py index fe0bc6bfb..1ed0ab110 100644 --- a/astrbot/core/platform/sources/gewechat/client.py +++ b/astrbot/core/platform/sources/gewechat/client.py @@ -302,8 +302,21 @@ class SimpleGewechatClient(): "uuid": qr_uuid, "appId": appid }) + verify_flag = False while retry_cnt > 0: retry_cnt -= 1 + + # 需要验证码 + if verify_flag: + with open("data/temp/gewe_code", "r") as f: + code = f.read().strip() + if not code: + logger.warning("未找到验证码,请在管理面板聊天页输入 /gewe_code 验证码 来验证,如 /gewe_code 123456") + await asyncio.sleep(5) + continue + payload['captchCode'] = code + logger.info(f"使用验证码: {code}") + async with aiohttp.ClientSession() as session: async with session.post( f"{self.base_url}/login/checkLogin", @@ -312,17 +325,26 @@ class SimpleGewechatClient(): ) as resp: json_blob = await resp.json() logger.info(f"检查登录状态: {json_blob}") - status = json_blob['data']['status'] - nickname = json_blob['data'].get('nickName', '') - if status == 1: - logger.info(f"等待确认...{nickname}") - elif status == 2: - logger.info(f"绿泡泡平台登录成功: {nickname}") - break - elif status == 0: - logger.info("等待扫码...") + + ret = json_blob['ret'] + msg = '' + if json_blob['data'] and 'msg' in json_blob['data']: + msg = json_blob['data']['msg'] + if ret == 500 and '安全验证码' in msg: + logger.warning("此次登录需要安全验证码,请在管理面板聊天页输入 /gewe_code 验证码 来验证,如 /gewe_code 123456") + verify_flag = True else: - logger.warning(f"未知状态: {status}") + status = json_blob['data']['status'] + nickname = json_blob['data'].get('nickName', '') + if status == 1: + logger.info(f"等待确认...{nickname}") + elif status == 2: + logger.info(f"绿泡泡平台登录成功: {nickname}") + break + elif status == 0: + logger.info("等待扫码...") + else: + logger.warning(f"未知状态: {status}") await asyncio.sleep(5) if appid: diff --git a/packages/astrbot/main.py b/packages/astrbot/main.py index cd4811654..70500c60f 100644 --- a/packages/astrbot/main.py +++ b/packages/astrbot/main.py @@ -788,6 +788,14 @@ UID: {user_id} 此 ID 可用于设置管理员。/op 授权管理员, /deo yield event.plain_result("已登出 gewechat,请重启 AstrBot") return + + @filter.command("gewe_code") + async def gewe_code(self, event: AstrMessageEvent, code: str): + '''保存 gewechat 验证码''' + with open("data/temp/gewe_code", "w", encoding='utf-8') as f: + f.write(code) + yield event.plain_result("验证码已保存。") + @filter.platform_adapter_type(filter.PlatformAdapterType.ALL) async def on_message(self, event: AstrMessageEvent): '''群聊记忆增强''' diff --git a/packages/reminder/main.py b/packages/reminder/main.py index fa675033c..2df153a00 100644 --- a/packages/reminder/main.py +++ b/packages/reminder/main.py @@ -17,9 +17,9 @@ class Main(star.Star): # set and load config if not os.path.exists("data/astrbot-reminder.json"): - with open("data/astrbot-reminder.json", "w") as f: + with open("data/astrbot-reminder.json", "w", encoding='utf-8') as f: f.write("{}") - with open("data/astrbot-reminder.json", "r") as f: + with open("data/astrbot-reminder.json", "r", encoding='utf-8') as f: self.reminder_data = json.load(f) self._init_scheduler() @@ -64,7 +64,7 @@ class Main(star.Star): async def _save_data(self): '''Save the reminder data.''' - with open("data/astrbot-reminder.json", "w") as f: + with open("data/astrbot-reminder.json", "w", encoding='utf-8') as f: json.dump(self.reminder_data, f, ensure_ascii=False) def _parse_cron_expr(self, cron_expr: str):