保存现有功能 增加域名和添加时间关联
This commit is contained in:
@@ -130,6 +130,55 @@ class HostRegisterWorker:
|
||||
delay = random.uniform(*self.config.register_config.delay_range)
|
||||
await asyncio.sleep(delay)
|
||||
|
||||
@staticmethod
|
||||
async def _extract_auth_token(response_text: str) -> str | None:
|
||||
"""从响应文本中提取pending_authentication_token"""
|
||||
res = response_text.split('\n')
|
||||
logger.debug(f"开始提取 auth_token,响应行数: {len(res)}")
|
||||
|
||||
# 检查邮箱是否可用
|
||||
for line in res:
|
||||
if '"code":"email_not_available"' in line:
|
||||
logger.error("不受支持的邮箱")
|
||||
raise RegisterError("Email is not available")
|
||||
|
||||
# 像register_worker.py中一样使用简单的路径
|
||||
try:
|
||||
for i, r in enumerate(res):
|
||||
if r.startswith('0:'):
|
||||
logger.debug(f"在第 {i+1} 行找到匹配")
|
||||
data = json.loads(r.split('0:')[1])
|
||||
# 使用完全相同的路径
|
||||
auth_data = data[1][0][0][1]["children"][1]["children"][1]["children"][1]["children"][0]
|
||||
params_str = auth_data.split('?')[1]
|
||||
params_dict = json.loads(params_str)
|
||||
token = params_dict['pending_authentication_token']
|
||||
logger.debug(f"提取成功: {token[:10]}...")
|
||||
return token
|
||||
except Exception as e:
|
||||
logger.error(f"提取token失败: {str(e)}")
|
||||
logger.debug(f"响应内容预览: {response_text[:200]}...")
|
||||
# 保存完整响应到文件以便调试
|
||||
try:
|
||||
with open('debug_response.txt', 'w', encoding='utf-8') as f:
|
||||
f.write(response_text)
|
||||
logger.debug("完整响应已保存到debug_response.txt")
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 尝试备选方法 - 在整个响应文本中查找token
|
||||
try:
|
||||
import re
|
||||
match = re.search(r'pending_authentication_token["\']?\s*[:=]\s*["\']?([^"\'&,\s]+)["\']?', response_text)
|
||||
if match:
|
||||
token = match.group(1)
|
||||
logger.debug(f"使用正则表达式提取成功: {token[:10]}...")
|
||||
return token
|
||||
except Exception as e:
|
||||
logger.error(f"正则表达式提取失败: {str(e)}")
|
||||
|
||||
return None
|
||||
|
||||
async def register(self, proxy: str, token_pair: Tuple[str, str]) -> Optional[Dict]:
|
||||
"""使用自建邮箱完成注册流程"""
|
||||
if not self.self_hosted_email:
|
||||
@@ -218,12 +267,13 @@ class HostRegisterWorker:
|
||||
boundary = "----WebKitFormBoundary2rKlvTagBEhneWi3"
|
||||
headers = {
|
||||
"accept": "text/x-component",
|
||||
"next-action": "a67eb6646e43eddcbd0d038cbee664aac59f5a53",
|
||||
"next-action": "770926d8148e29539286d20e1c1548d2aff6c0b9",
|
||||
"content-type": f"multipart/form-data; boundary={boundary}",
|
||||
"origin": "https://authenticator.cursor.sh",
|
||||
"sec-fetch-dest": "empty",
|
||||
"sec-fetch-mode": "cors",
|
||||
"sec-fetch-site": "same-origin"
|
||||
"sec-fetch-site": "same-origin",
|
||||
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36"
|
||||
}
|
||||
|
||||
params = {
|
||||
@@ -251,30 +301,8 @@ class HostRegisterWorker:
|
||||
|
||||
text = response['body'].decode()
|
||||
|
||||
# 检查邮箱是否可用
|
||||
if '"code":"email_not_available"' in text:
|
||||
logger.error(f"邮箱 {email} 不受支持")
|
||||
raise RegisterError("Email is not available")
|
||||
|
||||
# 提取pending_token
|
||||
pending_token = None
|
||||
res = text.split('\n')
|
||||
|
||||
try:
|
||||
for i, r in enumerate(res):
|
||||
if r.startswith('0:'):
|
||||
logger.debug(f"在第 {i+1} 行找到匹配")
|
||||
data = json.loads(r.split('0:')[1])
|
||||
auth_data = data[1][0][0][1]["children"][1]["children"][1]["children"][1]["children"][0]
|
||||
params_str = auth_data.split('?')[1]
|
||||
params_dict = json.loads(params_str)
|
||||
pending_token = params_dict['pending_authentication_token']
|
||||
logger.debug(f"提取成功: {pending_token[:10]}...")
|
||||
break
|
||||
except Exception as e:
|
||||
logger.error(f"提取token失败: {str(e)}")
|
||||
raise RegisterError("Failed to extract auth token")
|
||||
|
||||
# 使用更简单的方法提取token,与register_worker.py相同的方式
|
||||
pending_token = await self._extract_auth_token(text)
|
||||
if not pending_token:
|
||||
raise RegisterError("Failed to extract auth token")
|
||||
|
||||
@@ -332,7 +360,19 @@ class HostRegisterWorker:
|
||||
|
||||
redirect_url = response.get('headers', {}).get('x-action-redirect')
|
||||
if not redirect_url:
|
||||
raise RegisterError("未找到重定向URL,响应头: %s" % json.dumps(response.get('headers')))
|
||||
logger.error(f"未找到重定向URL,响应头: {json.dumps(response.get('headers', {}))}")
|
||||
# 尝试从响应体中提取
|
||||
body = response.get('body', b'').decode()
|
||||
if 'redirect' in body.lower():
|
||||
logger.debug("尝试从响应体中提取重定向URL")
|
||||
import re
|
||||
match = re.search(r'redirect[^"\']*["\']([^"\']+)["\']', body)
|
||||
if match:
|
||||
redirect_url = match.group(1)
|
||||
logger.debug(f"从响应体提取到重定向URL: {redirect_url}")
|
||||
|
||||
if not redirect_url:
|
||||
raise RegisterError("未找到重定向URL,响应头: %s" % json.dumps(response.get('headers')))
|
||||
|
||||
return redirect_url
|
||||
|
||||
|
||||
Reference in New Issue
Block a user