完善虎牙自动注册改密
This commit is contained in:
+100
-2
@@ -9,6 +9,8 @@ from datetime import datetime
|
||||
|
||||
from core.sms_provider import SmsLine, SmsProviderClient
|
||||
|
||||
from .change_password import change_huya_password_with_sms_line, generate_huya_password
|
||||
from .cookie_utils import cookie_value
|
||||
from .login import HuyaLoginError
|
||||
from .sms_login import login_huya_sms, normalize_huya_phone, send_huya_sms_code
|
||||
|
||||
@@ -24,9 +26,16 @@ class HuyaAutoRegisterResult:
|
||||
message: str
|
||||
cookie: str = ""
|
||||
code: str = ""
|
||||
change_code: str = ""
|
||||
sdid: str = ""
|
||||
normalized_phone: str = ""
|
||||
username: str = ""
|
||||
uid: str = ""
|
||||
password: str = ""
|
||||
sms_url: str = ""
|
||||
attempts: int = 0
|
||||
change_attempts: int = 0
|
||||
password_changed: bool = False
|
||||
|
||||
|
||||
def _sleep_or_stop(stop_event: threading.Event | None, seconds: float) -> bool:
|
||||
@@ -43,6 +52,9 @@ def register_huya_with_sms_line(
|
||||
item: SmsLine,
|
||||
wait_seconds: float = 180,
|
||||
poll_interval: float = 5,
|
||||
change_password: bool = True,
|
||||
password_prefix: str = "hy",
|
||||
fixed_password: str = "",
|
||||
stop_event: threading.Event | None = None,
|
||||
) -> HuyaAutoRegisterResult:
|
||||
"""使用固定手机号和接码地址完成虎牙短信注册/登录。"""
|
||||
@@ -59,6 +71,7 @@ def register_huya_with_sms_line(
|
||||
status="stopped",
|
||||
message="已停止",
|
||||
normalized_phone=normalized_phone,
|
||||
sms_url=item.url,
|
||||
)
|
||||
|
||||
sent_at = datetime.now()
|
||||
@@ -72,6 +85,7 @@ def register_huya_with_sms_line(
|
||||
status="error",
|
||||
message=str(exc),
|
||||
normalized_phone=normalized_phone,
|
||||
sms_url=item.url,
|
||||
)
|
||||
except Exception as exc:
|
||||
return HuyaAutoRegisterResult(
|
||||
@@ -81,6 +95,7 @@ def register_huya_with_sms_line(
|
||||
status="error",
|
||||
message=f"发送虎牙短信失败: {exc}",
|
||||
normalized_phone=normalized_phone,
|
||||
sms_url=item.url,
|
||||
)
|
||||
|
||||
if not code_result.success or not code_result.state:
|
||||
@@ -92,6 +107,7 @@ def register_huya_with_sms_line(
|
||||
message=code_result.message or "发送虎牙短信失败",
|
||||
sdid=code_result.sdid,
|
||||
normalized_phone=normalized_phone,
|
||||
sms_url=item.url,
|
||||
)
|
||||
|
||||
client = SmsProviderClient()
|
||||
@@ -109,6 +125,7 @@ def register_huya_with_sms_line(
|
||||
message="已停止",
|
||||
sdid=code_result.sdid,
|
||||
normalized_phone=normalized_phone,
|
||||
sms_url=item.url,
|
||||
attempts=attempts,
|
||||
)
|
||||
|
||||
@@ -132,6 +149,7 @@ def register_huya_with_sms_line(
|
||||
code=poll_result.code,
|
||||
sdid=code_result.sdid,
|
||||
normalized_phone=normalized_phone,
|
||||
sms_url=item.url,
|
||||
attempts=attempts,
|
||||
)
|
||||
except Exception as exc:
|
||||
@@ -144,21 +162,98 @@ def register_huya_with_sms_line(
|
||||
code=poll_result.code,
|
||||
sdid=code_result.sdid,
|
||||
normalized_phone=normalized_phone,
|
||||
sms_url=item.url,
|
||||
attempts=attempts,
|
||||
)
|
||||
|
||||
if login_result.success and login_result.cookie:
|
||||
cookie = login_result.cookie
|
||||
uid = cookie_value(cookie, "udb_uid") or cookie_value(cookie, "yyuid")
|
||||
username = cookie_value(cookie, "udb_passport") or cookie_value(cookie, "username") or uid
|
||||
if not change_password:
|
||||
return HuyaAutoRegisterResult(
|
||||
phone=phone,
|
||||
provider=item.provider,
|
||||
success=True,
|
||||
status="success",
|
||||
message="注册/登录成功",
|
||||
cookie=cookie,
|
||||
code=poll_result.code,
|
||||
sdid=login_result.sdid or code_result.sdid,
|
||||
normalized_phone=normalized_phone,
|
||||
username=username,
|
||||
uid=uid,
|
||||
sms_url=item.url,
|
||||
attempts=attempts,
|
||||
)
|
||||
|
||||
if not uid:
|
||||
return HuyaAutoRegisterResult(
|
||||
phone=phone,
|
||||
provider=item.provider,
|
||||
success=False,
|
||||
status="error",
|
||||
message="注册成功但 Cookie 中没有识别到虎牙 uid,无法改密",
|
||||
cookie=cookie,
|
||||
code=poll_result.code,
|
||||
sdid=login_result.sdid or code_result.sdid,
|
||||
normalized_phone=normalized_phone,
|
||||
username=username,
|
||||
uid=uid,
|
||||
sms_url=item.url,
|
||||
attempts=attempts,
|
||||
)
|
||||
|
||||
password = fixed_password.strip() or generate_huya_password(password_prefix)
|
||||
change_result = change_huya_password_with_sms_line(
|
||||
uid=uid,
|
||||
cookie=cookie,
|
||||
password=password,
|
||||
item=item,
|
||||
wait_seconds=wait_seconds,
|
||||
poll_interval=poll_interval,
|
||||
ignore_codes={poll_result.code},
|
||||
stop_event=stop_event,
|
||||
)
|
||||
if not change_result.success:
|
||||
failed_status = "stopped" if change_result.message == "已停止" else "error"
|
||||
return HuyaAutoRegisterResult(
|
||||
phone=phone,
|
||||
provider=item.provider,
|
||||
success=False,
|
||||
status=failed_status,
|
||||
message=f"注册成功但改密失败: {change_result.message}",
|
||||
cookie=cookie,
|
||||
code=poll_result.code,
|
||||
change_code=change_result.code,
|
||||
sdid=change_result.sdid or login_result.sdid or code_result.sdid,
|
||||
normalized_phone=normalized_phone,
|
||||
username=username,
|
||||
uid=uid,
|
||||
password=password,
|
||||
sms_url=item.url,
|
||||
attempts=attempts,
|
||||
change_attempts=change_result.attempts,
|
||||
)
|
||||
|
||||
return HuyaAutoRegisterResult(
|
||||
phone=phone,
|
||||
provider=item.provider,
|
||||
success=True,
|
||||
status="success",
|
||||
message="注册/登录成功",
|
||||
cookie=login_result.cookie,
|
||||
message="注册并改密成功",
|
||||
cookie=cookie,
|
||||
code=poll_result.code,
|
||||
change_code=change_result.code,
|
||||
sdid=login_result.sdid or code_result.sdid,
|
||||
normalized_phone=normalized_phone,
|
||||
username=username,
|
||||
uid=uid,
|
||||
password=password,
|
||||
sms_url=item.url,
|
||||
attempts=attempts,
|
||||
change_attempts=change_result.attempts,
|
||||
password_changed=True,
|
||||
)
|
||||
return HuyaAutoRegisterResult(
|
||||
phone=phone,
|
||||
@@ -169,6 +264,7 @@ def register_huya_with_sms_line(
|
||||
code=poll_result.code,
|
||||
sdid=login_result.sdid or code_result.sdid,
|
||||
normalized_phone=normalized_phone,
|
||||
sms_url=item.url,
|
||||
attempts=attempts,
|
||||
)
|
||||
|
||||
@@ -184,6 +280,7 @@ def register_huya_with_sms_line(
|
||||
message="已停止",
|
||||
sdid=code_result.sdid,
|
||||
normalized_phone=normalized_phone,
|
||||
sms_url=item.url,
|
||||
attempts=attempts,
|
||||
)
|
||||
|
||||
@@ -195,5 +292,6 @@ def register_huya_with_sms_line(
|
||||
message=f"等待验证码超时: {last_message}",
|
||||
sdid=code_result.sdid,
|
||||
normalized_phone=normalized_phone,
|
||||
sms_url=item.url,
|
||||
attempts=attempts,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user