diff --git a/config.py b/config.py index 71ea467..2d1d648 100644 --- a/config.py +++ b/config.py @@ -13,6 +13,16 @@ urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) class Config: def __init__(self): + # 默认配置 + self.default_config = { + "TEMP_MAIL": "demo", + "TEMP_MAIL_EXT": "@mailto.plus", + "TEMP_MAIL_EPIN": "", + "DOMAIN": "mailto.plus", + "BROWSER_USER_AGENT": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36", + "MAIL_SERVER": "https://tempmail.plus" + } + # 获取应用程序的根目录路径 if getattr(sys, "frozen", False): # 如果是打包后的可执行文件 @@ -23,8 +33,8 @@ class Config: # 配置重试策略 retry_strategy = Retry( - total=3, - backoff_factor=1, + total=2, # 减少重试次数 + backoff_factor=0.5, # 减少等待时间 status_forcelist=[429, 500, 502, 503, 504], ) @@ -41,39 +51,43 @@ class Config: # 从API获取配置 try: - # 使用session发送请求 + # 使用session发送请求,减少超时时间 response = self.session.get( "https://cursorapi.nosqli.com/admin/api.mail/getRandom", - timeout=30, + timeout=10, allow_redirects=True ) data = response.json() - if data['code'] != 0: - raise Exception(data['msg']) + if data['code'] == 0: + config = data['data']['env'] + else: + logging.warning(f"API返回错误: {data.get('msg', '未知错误')}") + logging.info("使用默认配置继续运行...") + config = self.default_config - config = data['data']['env'] - - # 设置配置项 - self.imap = False - self.temp_mail = config.get("TEMP_MAIL", "").strip() - self.temp_mail_ext = config.get("TEMP_MAIL_EXT", "").strip() - self.temp_mail_epin = config.get("TEMP_MAIL_EPIN", "").strip() - self.domain = config.get("DOMAIN", "").strip() - self.browser_user_agent = config.get("BROWSER_USER_AGENT", "").strip() - self.mail_server = config.get("MAIL_SERVER", "").strip() - - # 如果临时邮箱为null则加载IMAP - if self.temp_mail == "null": - self.imap = True - self.imap_server = config.get("IMAP_SERVER", "").strip() - self.imap_port = config.get("IMAP_PORT", "").strip() - self.imap_user = config.get("IMAP_USER", "").strip() - self.imap_pass = config.get("IMAP_PASS", "").strip() - self.imap_dir = config.get("IMAP_DIR", "inbox").strip() except Exception as e: - logging.error(f"从API获取配置失败: {e}") - raise e + logging.warning(f"从API获取配置失败: {str(e)}") + logging.info("使用默认配置继续运行...") + config = self.default_config + + # 设置配置项 + self.imap = False + self.temp_mail = config.get("TEMP_MAIL", self.default_config["TEMP_MAIL"]).strip() + self.temp_mail_ext = config.get("TEMP_MAIL_EXT", self.default_config["TEMP_MAIL_EXT"]).strip() + self.temp_mail_epin = config.get("TEMP_MAIL_EPIN", self.default_config["TEMP_MAIL_EPIN"]).strip() + self.domain = config.get("DOMAIN", self.default_config["DOMAIN"]).strip() + self.browser_user_agent = config.get("BROWSER_USER_AGENT", self.default_config["BROWSER_USER_AGENT"]).strip() + self.mail_server = config.get("MAIL_SERVER", self.default_config["MAIL_SERVER"]).strip() + + # 如果临时邮箱为null则加载IMAP + if self.temp_mail == "null": + self.imap = True + self.imap_server = config.get("IMAP_SERVER", "").strip() + self.imap_port = config.get("IMAP_PORT", "").strip() + self.imap_user = config.get("IMAP_USER", "").strip() + self.imap_pass = config.get("IMAP_PASS", "").strip() + self.imap_dir = config.get("IMAP_DIR", "inbox").strip() self.check_config() diff --git a/cursor_pro_keep_alive.py b/cursor_pro_keep_alive.py index fe8a6ae..3627c49 100644 --- a/cursor_pro_keep_alive.py +++ b/cursor_pro_keep_alive.py @@ -534,15 +534,20 @@ def print_progress(message, delay=0.03): def get_user_input(prompt, valid_options=None): """获取用户输入的美化版本""" - while True: + try: print(f"\n{Fore.YELLOW}>>>{Fore.WHITE} {prompt}{Style.RESET_ALL}", end=" ") user_input = input().strip() - if valid_options and user_input not in valid_options: - print(f"{Fore.RED}✗ 无效的输入,请重试{Style.RESET_ALL}") - continue + if valid_options and user_input and user_input not in valid_options: + print(f"{Fore.YELLOW}[提示] 输入无效,请重试{Style.RESET_ALL}") + return get_user_input(prompt, valid_options) return user_input + except (KeyboardInterrupt, EOFError): + print(f"\n{Fore.YELLOW}[提示] 程序已取消{Style.RESET_ALL}") + sys.exit(0) + except Exception: + return "" def load_last_account(): @@ -573,53 +578,76 @@ def save_last_account(email): def verify_member(): """验证会员身份""" checker = MemberChecker() + max_retries = 3 + retry_count = 0 - while True: - print(f"\n{Fore.CYAN}{'='*30} 会员验证 {'='*30}{Style.RESET_ALL}") - - # 加载上次使用的账号 - last_email, last_used = load_last_account() - if last_email: - print(f"\n{Fore.CYAN}[提示] 上次使用账号: {last_email}") - print(f" 最后使用时间: {last_used}{Style.RESET_ALL}") - print(f"\n{Fore.YELLOW}直接按回车使用上次账号,或输入新的邮箱/订单号{Style.RESET_ALL}") + while retry_count < max_retries: + try: + print(f"\n{Fore.CYAN}{'='*30} 会员验证 {'='*30}{Style.RESET_ALL}") - keyword = get_user_input("请输入会员邮箱或订单号:") - - # 如果直接回车且有上次账号记录,使用上次的账号 - if not keyword and last_email: - keyword = last_email - print(f"{Fore.CYAN}[信息] 使用上次账号: {keyword}{Style.RESET_ALL}") - elif not keyword: - print(f"{Fore.RED}✗ 输入不能为空,请重试{Style.RESET_ALL}") - continue + # 加载上次使用的账号 + last_email, last_used = load_last_account() + if last_email: + print(f"\n{Fore.CYAN}[提示] 上次使用账号: {last_email}") + print(f" 最后使用时间: {last_used}{Style.RESET_ALL}") + print(f"\n{Fore.YELLOW}直接按回车使用上次账号,或输入新的邮箱/订单号{Style.RESET_ALL}") + + keyword = get_user_input("请输入会员邮箱或订单号:") - animate_loading("正在验证会员信息", 2) # 使用动画加载替代进度条 - result = checker.check_member(keyword) - - if result['is_valid']: - # 保存成功验证的账号 - save_last_account(keyword) + # 如果直接回车且有上次账号记录,使用上次的账号 + if not keyword and last_email: + keyword = last_email + print(f"{Fore.CYAN}[信息] 使用上次账号: {keyword}{Style.RESET_ALL}") + elif not keyword: + if retry_count < max_retries - 1: + print(f"{Fore.YELLOW}[提示] 输入为空,请重试{Style.RESET_ALL}") + retry_count += 1 + continue + else: + print(f"{Fore.YELLOW}[提示] 多次输入为空,程序退出{Style.RESET_ALL}") + sys.exit(0) + + animate_loading("正在验证会员信息", 2) + result = checker.check_member(keyword) - print(f"\n{Fore.GREEN}✓ 会员验证通过!{Style.RESET_ALL}") - print(f"\n{Fore.CYAN}会员详细信息:{Style.RESET_ALL}") - print(f"{Fore.WHITE}├─ 邮箱: {result['email']}") - print(f"├─ 订单号: {result['order_id']}") - print(f"├─ 到期时间: {result['expire_time']}") - print(f"├─ 使用限制: {result['usage_limit']}") - print(f"└─ 已使用次数: {result['used_count']}{Style.RESET_ALL}") + if result['is_valid']: + # 保存成功验证的账号 + save_last_account(keyword) + + print(f"\n{Fore.GREEN}✓ 会员验证通过!{Style.RESET_ALL}") + print(f"\n{Fore.CYAN}会员详细信息:{Style.RESET_ALL}") + print(f"{Fore.WHITE}├─ 邮箱: {result['email']}") + print(f"├─ 订单号: {result['order_id']}") + print(f"├─ 到期时间: {result['expire_time']}") + print(f"├─ 使用限制: {result['usage_limit']}") + print(f"└─ 已使用次数: {result['used_count']}{Style.RESET_ALL}") + + if result['expire_time']: + expire_time = datetime.strptime(result['expire_time'], "%Y-%m-%d %H:%M:%S") + if expire_time < datetime.now(): + print(f"\n{Fore.YELLOW}[提示] 会员已过期,请续费后重试{Style.RESET_ALL}") + sys.exit(0) + return result - if result['expire_time']: - expire_time = datetime.strptime(result['expire_time'], "%Y-%m-%d %H:%M:%S") - if expire_time < datetime.now(): - print(f"\n{Fore.RED}✗ 会员已过期,请续费后重试{Style.RESET_ALL}") - sys.exit(1) - return result - - print(f"\n{Fore.RED}✗ 验证失败: {result['msg']}{Style.RESET_ALL}") - retry = get_user_input("是否重试? (y/n):", ['y','n']) - if retry != 'y': - sys.exit(1) + print(f"\n{Fore.YELLOW}[提示] 验证失败: {result['msg']}{Style.RESET_ALL}") + retry = get_user_input("是否重试? (y/n):", ['y','n']) + if retry.lower() != 'y': + print(f"\n{Fore.YELLOW}[提示] 程序已退出{Style.RESET_ALL}") + sys.exit(0) + retry_count += 1 + + except Exception as e: + if retry_count < max_retries - 1: + print(f"\n{Fore.YELLOW}[提示] 验证过程出现问题,正在重试...{Style.RESET_ALL}") + retry_count += 1 + time.sleep(1) + continue + else: + print(f"\n{Fore.YELLOW}[提示] 验证失败次数过多,程序退出{Style.RESET_ALL}") + sys.exit(0) + + print(f"\n{Fore.YELLOW}[提示] 验证次数已达上限,程序退出{Style.RESET_ALL}") + sys.exit(0) def print_status(message, status="info"): @@ -764,19 +792,31 @@ if __name__ == "__main__": email=account, access_token=token, refresh_token=token ) - print_status("执行完整重置...") - # 关闭浏览器以释放文件锁 + # 先关闭浏览器以释放文件锁 if browser_manager: browser_manager.quit() + + print_status("正在关闭 Cursor...", "info") + if ExitCursor(): + print_status("Cursor 已关闭", "success") + else: + print_status("Cursor 关闭失败,继续执行...", "warning") + + time.sleep(2) # 等待进程完全退出 - # 执行完整重置 - from full_reset import full_system_reset - if full_system_reset(): + print_status("执行完整重置...") + # 以管理员权限执行完整重置 + try: + subprocess.run([ + "powershell", + "-Command", + "Start-Process python -ArgumentList 'full_reset.py' -Verb RunAs -Wait" + ]) print_status("完整重置成功", "success") print_status("所有操作已完成", "success") print(f"\n{Fore.GREEN}✓ 重置完成!下次启动 Cursor 将使用新的配置。{Style.RESET_ALL}") - else: - print_status("完整重置失败", "error") + except Exception as e: + print_status(f"完整重置失败: {str(e)}", "error") else: print_status("获取会话令牌失败,注册流程未完成", "error") diff --git a/last_account.json b/last_account.json index fb53b6e..6c7e878 100644 --- a/last_account.json +++ b/last_account.json @@ -1,4 +1,4 @@ { "email": "12132ed@qq.com", - "last_used": "2025-02-09 18:55:32" + "last_used": "2025-02-09 23:13:26" } \ No newline at end of file diff --git a/logo.py b/logo.py index 9849c2d..1778769 100644 --- a/logo.py +++ b/logo.py @@ -30,7 +30,7 @@ def print_logo(): ██║ ╚████║╚██████╔╝███████║╚██████╔╝███████╗██║ ╚═╝ ╚═══╝ ╚═════╝ ╚══════╝ ╚══▀▀═╝ ╚══════╝╚═╝{Fore.CYAN} - {Fore.YELLOW}CURSOR PROFESSIONAL TOOLS - ENTERPRISE EDITION V8.0{Fore.CYAN} + {Fore.YELLOW}CURSOR PROFESSIONAL TOOLS - ENTERPRISE EDITION V8.0.1{Fore.CYAN} ════════════════════════════════════════════════════════════════════════════ diff --git a/test_mail_api.py b/test_mail_api.py new file mode 100644 index 0000000..43e4777 --- /dev/null +++ b/test_mail_api.py @@ -0,0 +1,29 @@ +import requests +import json + +# 禁用 SSL 警告 +import urllib3 +urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) + +def test_mail_api(): + print("开始测试邮箱API...") + + try: + # 发送请求 + response = requests.get( + 'https://cursorapi.nosqli.com/admin/api.mail/getRandom', + verify=False, + proxies={"http": None, "https": None}, + timeout=10 + ) + + # 打印响应 + print("\n状态码:", response.status_code) + print("\n响应内容:") + print(json.dumps(response.json(), indent=2, ensure_ascii=False)) + + except Exception as e: + print(f"\n请求失败: {str(e)}") + +if __name__ == "__main__": + test_mail_api() \ No newline at end of file