#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ DuoPlus 云手机协议注册 - 主程序 完整的注册流程实现 """ import os import sys import json from dotenv import load_dotenv from colorama import init, Fore, Style from duoplus_register import DuoPlusRegister # 初始化 colorama init(autoreset=True) def print_banner(): """打印程序横幅""" banner = """ ╔══════════════════════════════════════════════════════════╗ ║ DuoPlus 云手机协议注册工具 v1.0 ║ ║ ║ ║ 功能特点: ║ ║ • 自动处理腾讯滑块验证码 ║ ║ • 支持批量注册 ║ ║ • 自动保存账号信息 ║ ║ • 完整的错误处理 ║ ╚══════════════════════════════════════════════════════════╝ """ print(f"{Fore.CYAN}{banner}") def check_environment(): """检查环境配置""" if not os.path.exists('.env'): print(f"{Fore.YELLOW}[WARNING] 未找到 .env 文件") if os.path.exists('.env.example'): print(f"{Fore.YELLOW}[INFO] 正在创建 .env 文件...") import shutil shutil.copy('.env.example', '.env') print(f"{Fore.GREEN}[SUCCESS] 已创建 .env 文件") print(f"{Fore.YELLOW}[ACTION] 请编辑 .env 文件,填入您的 2captcha API Key") return False else: print(f"{Fore.RED}[ERROR] 未找到 .env.example 文件") return False # 加载环境变量 load_dotenv() api_key = os.getenv('CAPTCHA_API_KEY') if not api_key or api_key == 'your_2captcha_api_key_here': print(f"{Fore.RED}[ERROR] 请在 .env 文件中设置有效的 CAPTCHA_API_KEY") return False return True def single_registration(): """单个账号注册""" print(f"\n{Fore.CYAN}=== 单个账号注册 ===") # 获取用户输入 email_input = input(f"{Fore.YELLOW}请输入邮箱地址 (直接回车使用自建邮箱): ").strip() # 创建注册器 api_key = os.getenv('CAPTCHA_API_KEY') registrar = DuoPlusRegister(api_key) if not email_input: # 空回车,使用自建邮箱全自动注册 print(f"{Fore.CYAN}[INFO] 使用自建邮箱进行全自动注册...") result = registrar.auto_register_with_temp_email() if result.get("success"): print(f"\n{Fore.GREEN}{'='*60}") print(f"{Fore.GREEN}✅ 全自动注册成功!") print(f"{Fore.GREEN}{'='*60}") data = result.get("data", {}) print(f"{Fore.GREEN}Access Token: {data.get('access_token', 'N/A')[:30]}...") print(f"{Fore.GREEN}Token 有效期: {data.get('expired_in', 0) // 3600} 小时") print(f"{Fore.GREEN}赠送余额: {data.get('gift_balance', '$0.00')}") # 显示邮箱密码(如果有) if data.get('email_password'): print(f"{Fore.GREEN}邮箱密码: {data.get('email_password')}") print(f"{Fore.GREEN}{'='*60}") else: print(f"\n{Fore.RED}❌ 注册失败: {result.get('message', 'Unknown error')}") else: # 手动输入邮箱 if '@' not in email_input: print(f"{Fore.RED}[ERROR] 请输入有效的邮箱地址") return email = email_input # 询问是否使用自定义密码 use_custom_password = input(f"{Fore.YELLOW}是否使用自定义密码? (y/n, 默认n): ").strip().lower() == 'y' password = None if use_custom_password: password = input(f"{Fore.YELLOW}请输入密码: ").strip() if len(password) < 8: print(f"{Fore.RED}[ERROR] 密码长度至少8位") return # 执行注册 result = registrar.auto_register(email, password) if result.get("success"): print(f"\n{Fore.GREEN}{'='*60}") print(f"{Fore.GREEN}✅ 注册成功!") print(f"{Fore.GREEN}{'='*60}") data = result.get("data", {}) print(f"{Fore.GREEN}Access Token: {data.get('access_token', 'N/A')[:30]}...") print(f"{Fore.GREEN}Token 有效期: {data.get('expired_in', 0) // 3600} 小时") print(f"{Fore.GREEN}赠送余额: {data.get('gift_balance', '$0.00')}") print(f"{Fore.GREEN}{'='*60}") else: print(f"\n{Fore.RED}❌ 注册失败: {result.get('message', 'Unknown error')}") def batch_registration(): """批量注册""" print(f"\n{Fore.CYAN}=== 批量注册 ===") # 获取邮箱前缀和域名 email_prefix = input(f"{Fore.YELLOW}请输入邮箱前缀 (例如: test): ").strip() email_domain = input(f"{Fore.YELLOW}请输入邮箱域名 (例如: example.com): ").strip() if not email_prefix or not email_domain: print(f"{Fore.RED}[ERROR] 邮箱前缀和域名不能为空") return count = input(f"{Fore.YELLOW}请输入注册数量 (默认3): ").strip() count = int(count) if count.isdigit() else 3 if count > 10: print(f"{Fore.YELLOW}[WARNING] 一次注册超过10个账号可能会被限制") confirm = input(f"{Fore.YELLOW}是否继续? (y/n): ").strip().lower() if confirm != 'y': return # 创建注册器 api_key = os.getenv('CAPTCHA_API_KEY') registrar = DuoPlusRegister(api_key) success_count = 0 failed_count = 0 print(f"\n{Fore.CYAN}开始批量注册 {count} 个账号...") for i in range(1, count + 1): email = f"{email_prefix}{i}@{email_domain}" print(f"\n{Fore.CYAN}[{i}/{count}] 正在注册: {email}") try: result = registrar.auto_register(email) if result.get("success"): success_count += 1 print(f"{Fore.GREEN}✅ {email} 注册成功") else: failed_count += 1 print(f"{Fore.RED}❌ {email} 注册失败: {result.get('message')}") except Exception as e: failed_count += 1 print(f"{Fore.RED}❌ {email} 注册异常: {str(e)}") # 避免请求过快 if i < count: import time print(f"{Fore.YELLOW}等待3秒后继续...") time.sleep(3) # 显示统计结果 print(f"\n{Fore.CYAN}{'='*60}") print(f"{Fore.CYAN}批量注册完成!") print(f"{Fore.GREEN}成功: {success_count} 个") print(f"{Fore.RED}失败: {failed_count} 个") print(f"{Fore.CYAN}{'='*60}") def test_captcha(): """测试验证码识别""" print(f"\n{Fore.CYAN}=== 测试 2captcha 连接 ===") api_key = os.getenv('CAPTCHA_API_KEY') try: import requests response = requests.get(f"http://2captcha.com/res.php?key={api_key}&action=getbalance") if response.status_code == 200: balance = response.text try: balance_float = float(balance) print(f"{Fore.GREEN}✅ 2captcha 连接成功") print(f"{Fore.GREEN}账户余额: ${balance}") if balance_float < 1: print(f"{Fore.YELLOW}[WARNING] 余额较低,请及时充值") except ValueError: print(f"{Fore.RED}❌ API Key 无效: {response.text}") else: print(f"{Fore.RED}❌ 连接失败: HTTP {response.status_code}") except Exception as e: print(f"{Fore.RED}❌ 测试失败: {str(e)}") def main(): """主函数""" # 打印横幅 print_banner() # 检查环境 if not check_environment(): print(f"\n{Fore.RED}请配置好环境后重新运行程序") sys.exit(1) while True: print(f"\n{Fore.CYAN}请选择操作:") print("1. 单个账号注册") print("2. 批量注册") print("3. 测试 2captcha 连接") print("4. 查看注册记录") print("0. 退出") choice = input(f"\n{Fore.YELLOW}请输入选项 (0-4): ").strip() if choice == '1': single_registration() elif choice == '2': batch_registration() elif choice == '3': test_captcha() elif choice == '4': if os.path.exists('registered_accounts.txt'): print(f"\n{Fore.CYAN}=== 注册记录 ===") with open('registered_accounts.txt', 'r', encoding='utf-8') as f: print(f.read()) else: print(f"{Fore.YELLOW}暂无注册记录") elif choice == '0': print(f"{Fore.GREEN}感谢使用,再见!") break else: print(f"{Fore.RED}无效的选项,请重新选择") if __name__ == "__main__": try: main() except KeyboardInterrupt: print(f"\n{Fore.YELLOW}程序已中断") sys.exit(0) except Exception as e: print(f"\n{Fore.RED}程序异常: {str(e)}") sys.exit(1)