修复
This commit is contained in:
@@ -91,7 +91,7 @@ def register_account(client, domain, username=None):
|
|||||||
'message': '未收到验证邮件'
|
'message': '未收到验证邮件'
|
||||||
}
|
}
|
||||||
|
|
||||||
def batch_register(domain, count, concurrent=2):
|
def batch_register(domain, count, concurrent=2, api_url=None):
|
||||||
"""
|
"""
|
||||||
批量注册账号
|
批量注册账号
|
||||||
|
|
||||||
@@ -99,6 +99,7 @@ def batch_register(domain, count, concurrent=2):
|
|||||||
domain: 邮箱域名
|
domain: 邮箱域名
|
||||||
count: 注册数量
|
count: 注册数量
|
||||||
concurrent: 并发数
|
concurrent: 并发数
|
||||||
|
api_url: API基础URL,默认为None使用客户端默认值
|
||||||
|
|
||||||
返回:
|
返回:
|
||||||
注册结果列表
|
注册结果列表
|
||||||
@@ -106,7 +107,7 @@ def batch_register(domain, count, concurrent=2):
|
|||||||
logger.info(f"开始批量注册 {count} 个账号,域名: {domain},并发数: {concurrent}")
|
logger.info(f"开始批量注册 {count} 个账号,域名: {domain},并发数: {concurrent}")
|
||||||
|
|
||||||
# 创建API客户端
|
# 创建API客户端
|
||||||
client = EmailApiClient()
|
client = EmailApiClient(api_base_url=api_url) if api_url else EmailApiClient()
|
||||||
|
|
||||||
# 检查系统状态
|
# 检查系统状态
|
||||||
status = client.check_system_status()
|
status = client.check_system_status()
|
||||||
@@ -178,11 +179,12 @@ def main():
|
|||||||
parser.add_argument('--count', type=int, default=5, help='注册数量')
|
parser.add_argument('--count', type=int, default=5, help='注册数量')
|
||||||
parser.add_argument('--concurrent', type=int, default=2, help='并发数')
|
parser.add_argument('--concurrent', type=int, default=2, help='并发数')
|
||||||
parser.add_argument('--output', type=str, default='registration_results.json', help='结果输出文件')
|
parser.add_argument('--output', type=str, default='registration_results.json', help='结果输出文件')
|
||||||
|
parser.add_argument('--api-url', type=str, help='邮件系统API基础URL,默认为http://74.48.75.19:5000/api')
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
# 执行批量注册
|
# 执行批量注册
|
||||||
results = batch_register(args.domain, args.count, args.concurrent)
|
results = batch_register(args.domain, args.count, args.concurrent, args.api_url)
|
||||||
|
|
||||||
# 保存结果
|
# 保存结果
|
||||||
if results:
|
if results:
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import requests
|
|||||||
import json
|
import json
|
||||||
import time
|
import time
|
||||||
import logging
|
import logging
|
||||||
|
import re
|
||||||
|
|
||||||
class EmailApiClient:
|
class EmailApiClient:
|
||||||
"""
|
"""
|
||||||
@@ -12,7 +13,7 @@ class EmailApiClient:
|
|||||||
用于在批量注册场景中与邮件系统API交互
|
用于在批量注册场景中与邮件系统API交互
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, api_base_url="http://localhost:5000/api", timeout=10):
|
def __init__(self, api_base_url="http://74.48.75.19:5000/api", timeout=10):
|
||||||
"""
|
"""
|
||||||
初始化API客户端
|
初始化API客户端
|
||||||
|
|
||||||
@@ -22,15 +23,17 @@ class EmailApiClient:
|
|||||||
"""
|
"""
|
||||||
self.api_base_url = api_base_url
|
self.api_base_url = api_base_url
|
||||||
self.timeout = timeout
|
self.timeout = timeout
|
||||||
self.logger = logging.getLogger("EmailApiClient")
|
|
||||||
|
|
||||||
# 设置日志
|
# 设置日志
|
||||||
|
self.logger = logging.getLogger("EmailApiClient")
|
||||||
if not self.logger.handlers:
|
if not self.logger.handlers:
|
||||||
handler = logging.StreamHandler()
|
handler = logging.StreamHandler()
|
||||||
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
||||||
handler.setFormatter(formatter)
|
handler.setFormatter(formatter)
|
||||||
self.logger.addHandler(handler)
|
self.logger.addHandler(handler)
|
||||||
self.logger.setLevel(logging.INFO)
|
self.logger.setLevel(logging.INFO)
|
||||||
|
|
||||||
|
self.logger.info(f"初始化API客户端: {api_base_url}")
|
||||||
|
|
||||||
def get_emails_by_address(self, email_address, limit=10, unread_only=False, since=None):
|
def get_emails_by_address(self, email_address, limit=10, unread_only=False, since=None):
|
||||||
"""
|
"""
|
||||||
@@ -151,8 +154,6 @@ class EmailApiClient:
|
|||||||
if email.get('verification_code'):
|
if email.get('verification_code'):
|
||||||
return email.get('verification_code')
|
return email.get('verification_code')
|
||||||
|
|
||||||
import re
|
|
||||||
|
|
||||||
# 默认验证码模式
|
# 默认验证码模式
|
||||||
default_patterns = [
|
default_patterns = [
|
||||||
r'验证码[::\s]+(\d{4,8})',
|
r'验证码[::\s]+(\d{4,8})',
|
||||||
|
|||||||
@@ -19,37 +19,47 @@ def get_emails_by_address(email_address, limit=10, unread_only=False, since=None
|
|||||||
返回:
|
返回:
|
||||||
API响应的JSON数据
|
API响应的JSON数据
|
||||||
"""
|
"""
|
||||||
base_url = "http://localhost:5000/api/emails/by-address"
|
# 构建API URL
|
||||||
|
api_url = f"http://74.48.75.19:5000/api/emails/by-address"
|
||||||
|
|
||||||
# 构建参数
|
# 构建查询参数
|
||||||
params = {
|
params = {
|
||||||
'email_address': email_address,
|
"email_address": email_address,
|
||||||
'limit': limit
|
"limit": limit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# 添加可选参数
|
||||||
if unread_only:
|
if unread_only:
|
||||||
params['unread_only'] = 'true'
|
params["unread_only"] = "true"
|
||||||
|
|
||||||
if since:
|
if since:
|
||||||
params['since'] = since
|
params["since"] = since
|
||||||
|
|
||||||
|
# 打印请求信息
|
||||||
|
print(f"请求URL: {api_url}")
|
||||||
|
print(f"参数: {params}")
|
||||||
|
|
||||||
# 发送请求
|
|
||||||
try:
|
try:
|
||||||
print(f"请求 URL: {base_url}?{'&'.join([f'{k}={v}' for k, v in params.items()])}")
|
# 发送API请求
|
||||||
response = requests.get(base_url, params=params)
|
response = requests.get(api_url, params=params, timeout=15)
|
||||||
|
|
||||||
# 打印响应信息
|
# 打印响应状态
|
||||||
print(f"状态码: {response.status_code}")
|
print(f"响应状态码: {response.status_code}")
|
||||||
|
|
||||||
|
# 返回JSON数据
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
data = response.json()
|
return response.json()
|
||||||
return data
|
|
||||||
else:
|
else:
|
||||||
print(f"请求失败: {response.text}")
|
print(f"API请求失败: {response.text}")
|
||||||
return None
|
return {
|
||||||
|
"success": False,
|
||||||
|
"error": f"请求失败: HTTP {response.status_code}"
|
||||||
|
}
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"请求出错: {str(e)}")
|
print(f"发生错误: {str(e)}")
|
||||||
return None
|
return {
|
||||||
|
"success": False,
|
||||||
|
"error": f"发生异常: {str(e)}"
|
||||||
|
}
|
||||||
|
|
||||||
def format_email_info(email):
|
def format_email_info(email):
|
||||||
"""格式化邮件信息显示"""
|
"""格式化邮件信息显示"""
|
||||||
|
|||||||
Reference in New Issue
Block a user