完善虎牙自动注册改密
This commit is contained in:
@@ -34,12 +34,18 @@ class HuyaRegisterItemState:
|
||||
line: int
|
||||
phone: str
|
||||
provider: str
|
||||
sms_url: str = ""
|
||||
status: str = "pending"
|
||||
message: str = "等待开始"
|
||||
code: str = ""
|
||||
change_code: str = ""
|
||||
attempts: int = 0
|
||||
change_attempts: int = 0
|
||||
account_id: int | None = None
|
||||
username: str = ""
|
||||
uid: str = ""
|
||||
password: str = ""
|
||||
password_changed: bool = False
|
||||
cookie: str = ""
|
||||
cookie_preview: str = ""
|
||||
started_at: datetime | None = None
|
||||
@@ -50,12 +56,18 @@ class HuyaRegisterItemState:
|
||||
"line": self.line,
|
||||
"phone": self.phone,
|
||||
"provider": self.provider,
|
||||
"sms_url": self.sms_url,
|
||||
"status": self.status,
|
||||
"message": self.message,
|
||||
"code": self.code,
|
||||
"change_code": self.change_code,
|
||||
"attempts": self.attempts,
|
||||
"change_attempts": self.change_attempts,
|
||||
"account_id": self.account_id,
|
||||
"username": self.username,
|
||||
"uid": self.uid,
|
||||
"password": self.password,
|
||||
"password_changed": self.password_changed,
|
||||
"cookie": self.cookie,
|
||||
"cookie_preview": self.cookie_preview,
|
||||
"started_at": self.started_at,
|
||||
@@ -74,6 +86,8 @@ class HuyaRegisterBatch:
|
||||
wait_seconds: float
|
||||
poll_interval: float
|
||||
items: list[HuyaRegisterItemState]
|
||||
password_prefix: str = "hy"
|
||||
fixed_password: str = ""
|
||||
status: str = "pending"
|
||||
message: str = "等待开始"
|
||||
created_at: datetime = field(default_factory=_now)
|
||||
@@ -106,7 +120,7 @@ class HuyaRegisterRunner:
|
||||
success = sum(1 for item in self.batch.items if item.status == "success")
|
||||
failed = sum(1 for item in self.batch.items if item.status == "error")
|
||||
stopped = sum(1 for item in self.batch.items if item.status == "stopped")
|
||||
running = sum(1 for item in self.batch.items if item.status in {"sending", "waiting", "logging"})
|
||||
running = sum(1 for item in self.batch.items if item.status in {"sending", "waiting", "changing", "logging"})
|
||||
return {
|
||||
"batch_id": self.batch.batch_id,
|
||||
"status": self.batch.status,
|
||||
@@ -116,6 +130,7 @@ class HuyaRegisterRunner:
|
||||
"concurrency": self.batch.concurrency,
|
||||
"wait_seconds": self.batch.wait_seconds,
|
||||
"poll_interval": self.batch.poll_interval,
|
||||
"password_prefix": self.batch.password_prefix,
|
||||
"total": total,
|
||||
"success_count": success,
|
||||
"failed_count": failed,
|
||||
@@ -133,15 +148,21 @@ class HuyaRegisterRunner:
|
||||
for key, value in updates.items():
|
||||
setattr(item, key, value)
|
||||
|
||||
def _save_cookie(self, result: HuyaAutoRegisterResult) -> tuple[int | None, str]:
|
||||
def _save_cookie(self, result: HuyaAutoRegisterResult) -> tuple[int | None, str, str]:
|
||||
db = SessionLocal()
|
||||
try:
|
||||
account = upsert_huya_cookie(db, result.cookie, tag=self.batch.tag, username_hint="")
|
||||
account.game_phone = result.phone
|
||||
if result.username:
|
||||
account.username = result.username
|
||||
if result.password:
|
||||
account.account_password = result.password
|
||||
if result.password_changed:
|
||||
account.status = "password_changed"
|
||||
account.updated_at = _now()
|
||||
db.commit()
|
||||
db.refresh(account)
|
||||
return account.id, account.uid or account.yyuid or ""
|
||||
return account.id, account.username or "", account.uid or account.yyuid or ""
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
@@ -150,38 +171,60 @@ class HuyaRegisterRunner:
|
||||
self._set_item(index, status="stopped", message="已停止", finished_at=_now())
|
||||
return
|
||||
|
||||
self._set_item(index, status="sending", message="发送虎牙短信", started_at=_now(), finished_at=None)
|
||||
self._set_item(index, status="sending", message="注册并改密", started_at=_now(), finished_at=None)
|
||||
result = register_huya_with_sms_line(
|
||||
item,
|
||||
wait_seconds=self.batch.wait_seconds,
|
||||
poll_interval=self.batch.poll_interval,
|
||||
password_prefix=self.batch.password_prefix,
|
||||
fixed_password=self.batch.fixed_password,
|
||||
stop_event=self._stop,
|
||||
)
|
||||
|
||||
account_id = None
|
||||
uid = ""
|
||||
username = result.username
|
||||
uid = result.uid
|
||||
message = result.message
|
||||
status = result.status
|
||||
cookie = result.cookie if result.success else ""
|
||||
if result.success:
|
||||
self._set_item(index, status="logging", message="保存 Cookie", code=result.code, attempts=result.attempts)
|
||||
self._set_item(
|
||||
index,
|
||||
status="logging",
|
||||
message="保存账号密码",
|
||||
code=result.code,
|
||||
change_code=result.change_code,
|
||||
attempts=result.attempts,
|
||||
change_attempts=result.change_attempts,
|
||||
username=result.username,
|
||||
uid=result.uid,
|
||||
password=result.password,
|
||||
password_changed=result.password_changed,
|
||||
)
|
||||
try:
|
||||
account_id, uid = self._save_cookie(result)
|
||||
account_id, username, uid = self._save_cookie(result)
|
||||
except Exception as exc:
|
||||
status = "error"
|
||||
cookie = ""
|
||||
message = f"Cookie 保存失败: {exc}"
|
||||
message = f"账号保存失败: {exc}"
|
||||
|
||||
exposed_cookie = "" if result.password_changed else cookie
|
||||
|
||||
self._set_item(
|
||||
index,
|
||||
status=status,
|
||||
message=message,
|
||||
code=result.code,
|
||||
change_code=result.change_code,
|
||||
attempts=result.attempts,
|
||||
change_attempts=result.change_attempts,
|
||||
account_id=account_id,
|
||||
username=username,
|
||||
uid=uid,
|
||||
cookie=normalize_huya_cookie(cookie),
|
||||
cookie_preview=_cookie_preview(cookie),
|
||||
password=result.password,
|
||||
password_changed=result.password_changed,
|
||||
cookie=normalize_huya_cookie(exposed_cookie),
|
||||
cookie_preview=_cookie_preview(exposed_cookie),
|
||||
finished_at=_now(),
|
||||
)
|
||||
|
||||
@@ -235,6 +278,8 @@ class HuyaRegisterRegistry:
|
||||
concurrency: int,
|
||||
wait_seconds: float,
|
||||
poll_interval: float,
|
||||
password_prefix: str = "hy",
|
||||
fixed_password: str = "",
|
||||
) -> HuyaRegisterRunner:
|
||||
batch_id = uuid.uuid4().hex[:12]
|
||||
batch = HuyaRegisterBatch(
|
||||
@@ -244,8 +289,10 @@ class HuyaRegisterRegistry:
|
||||
concurrency=max(1, min(int(concurrency or 1), 5)),
|
||||
wait_seconds=max(15.0, float(wait_seconds or 180)),
|
||||
poll_interval=max(1.0, float(poll_interval or 5)),
|
||||
password_prefix=(password_prefix or "hy").strip()[:8] or "hy",
|
||||
fixed_password=(fixed_password or "").strip(),
|
||||
items=[
|
||||
HuyaRegisterItemState(line=index + 1, phone=item.phone, provider=item.provider)
|
||||
HuyaRegisterItemState(line=index + 1, phone=item.phone, provider=item.provider, sms_url=item.url)
|
||||
for index, item in enumerate(sms_lines)
|
||||
],
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user