完善虎牙自动注册改密

This commit is contained in:
yml2213
2026-07-06 01:20:22 +08:00
parent af98ea8416
commit db4ca78280
8 changed files with 777 additions and 29 deletions
+2
View File
@@ -359,6 +359,8 @@ def create_auto_register_batch(
concurrency=req.concurrency,
wait_seconds=req.wait_seconds,
poll_interval=req.poll_interval,
password_prefix=req.password_prefix,
fixed_password=req.fixed_password,
)
thread = threading.Thread(target=runner.run, daemon=True)
thread.start()
+9
View File
@@ -204,18 +204,26 @@ class HuyaAutoRegisterRequest(BaseModel):
concurrency: int = Field(1, ge=1, le=5)
wait_seconds: float = Field(180, ge=15, le=600)
poll_interval: float = Field(5, ge=1, le=30)
password_prefix: str = Field("hy", max_length=8)
fixed_password: str = Field("", max_length=64)
class HuyaAutoRegisterItemOut(BaseModel):
line: int
phone: str
provider: str
sms_url: str = ""
status: str
message: str
code: str = ""
change_code: str = ""
attempts: int = 0
change_attempts: int = 0
account_id: Optional[int] = None
username: str = ""
uid: str = ""
password: str = ""
password_changed: bool = False
cookie: str = ""
cookie_preview: str = ""
started_at: Optional[datetime] = None
@@ -231,6 +239,7 @@ class HuyaAutoRegisterBatchOut(BaseModel):
concurrency: int
wait_seconds: float
poll_interval: float
password_prefix: str = "hy"
total: int
success_count: int
failed_count: int
+58 -11
View File
@@ -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)
],
)
+9
View File
@@ -179,18 +179,26 @@ export interface HuyaAutoRegisterRequest {
concurrency?: number;
wait_seconds?: number;
poll_interval?: number;
password_prefix?: string;
fixed_password?: string;
}
export interface HuyaAutoRegisterItem {
line: number;
phone: string;
provider: string;
sms_url: string;
status: string;
message: string;
code: string;
change_code: string;
attempts: number;
change_attempts: number;
account_id: number | null;
username: string;
uid: string;
password: string;
password_changed: boolean;
cookie: string;
cookie_preview: string;
started_at: string | null;
@@ -206,6 +214,7 @@ export interface HuyaAutoRegisterBatch {
concurrency: number;
wait_seconds: number;
poll_interval: number;
password_prefix: string;
total: number;
success_count: number;
failed_count: number;
@@ -22,6 +22,7 @@ const STATUS_LABELS: Record<string, string> = {
updated: '已更新',
password_imported: '待登录',
login_success: '登录成功',
password_changed: '已改密',
login_failed: '登录失败',
active: '正常',
invalid: '失效',
@@ -32,6 +33,7 @@ const STATUS_COLORS: Record<string, string> = {
updated: 'cyan',
password_imported: 'warning',
login_success: 'success',
password_changed: 'success',
login_failed: 'error',
active: 'success',
invalid: 'error',
+67 -16
View File
@@ -1,6 +1,6 @@
import { useCallback, useEffect, useMemo, useState } from 'react';
import {
Button, Card, Col, Input, InputNumber, message, Row, Space, Statistic, Table, Tag, Typography,
Button, Card, Col, Input, InputNumber, message, Row, Segmented, Space, Statistic, Table, Tag, Typography,
} from 'antd';
import type { TableProps } from 'antd';
import { DownloadOutlined, PlayCircleOutlined, ReloadOutlined, StopOutlined } from '@ant-design/icons';
@@ -16,6 +16,7 @@ const STATUS_LABELS: Record<string, string> = {
sending: '发码',
waiting: '等待验证码',
logging: '保存',
changing: '改密',
success: '成功',
error: '失败',
stopped: '已停止',
@@ -26,6 +27,7 @@ const STATUS_COLORS: Record<string, string> = {
sending: 'processing',
waiting: 'processing',
logging: 'processing',
changing: 'processing',
success: 'success',
error: 'error',
stopped: 'warning',
@@ -39,6 +41,9 @@ export default function HuyaRegisterPage() {
const [concurrency, setConcurrency] = useState(1);
const [waitSeconds, setWaitSeconds] = useState(180);
const [pollInterval, setPollInterval] = useState(5);
const [passwordMode, setPasswordMode] = useState<'random' | 'fixed'>('random');
const [passwordPrefix, setPasswordPrefix] = useState('hy');
const [fixedPassword, setFixedPassword] = useState('');
const [batch, setBatch] = useState<HuyaAutoRegisterBatch | null>(null);
const [starting, setStarting] = useState(false);
const [refreshing, setRefreshing] = useState(false);
@@ -69,7 +74,7 @@ export default function HuyaRegisterPage() {
}, [batchId, isRunning, refreshBatch]);
const successRows = useMemo(
() => (batch?.items || []).filter((item) => item.status === 'success' && item.cookie),
() => (batch?.items || []).filter((item) => item.status === 'success' && item.password && (item.username || item.uid)),
[batch],
);
@@ -78,6 +83,10 @@ export default function HuyaRegisterPage() {
message.warning('请先粘贴手机号池');
return;
}
if (passwordMode === 'fixed' && !fixedPassword.trim()) {
message.warning('请先填写固定密码');
return;
}
setStarting(true);
try {
const data = await huyaApi.startAutoRegister({
@@ -86,6 +95,8 @@ export default function HuyaRegisterPage() {
concurrency,
wait_seconds: waitSeconds,
poll_interval: pollInterval,
password_prefix: passwordMode === 'random' ? (passwordPrefix.trim() || 'hy') : 'hy',
fixed_password: passwordMode === 'fixed' ? fixedPassword.trim() : '',
});
setBatch(data);
message.success('自动注册批次已启动');
@@ -112,15 +123,17 @@ export default function HuyaRegisterPage() {
const handleExportSuccess = () => {
if (successRows.length === 0) {
message.warning('当前批次没有可导出的成功 CK');
message.warning('当前批次没有可导出的成功账号');
return;
}
const body = successRows.map((item) => `${item.phone}----${item.cookie}`).join('\n');
const body = successRows
.map((item) => `${item.username || item.uid}----${item.password}----${item.phone}----${item.sms_url}`)
.join('\n');
const blob = new Blob([body], { type: 'text/plain;charset=utf-8' });
const url = URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.download = `huya-register-${batchId || 'success'}.txt`;
link.download = `huya-register-accounts-${batchId || 'success'}.txt`;
link.click();
URL.revokeObjectURL(url);
};
@@ -128,6 +141,17 @@ export default function HuyaRegisterPage() {
const columns: TableProps<HuyaAutoRegisterItem>['columns'] = [
{ title: '行', dataIndex: 'line', width: 64 },
{ title: '手机号', dataIndex: 'phone', width: 150 },
{
title: '虎牙号',
width: 150,
render: (_, item) => item.username || item.uid || '-',
},
{
title: '密码',
dataIndex: 'password',
width: 130,
render: (value: string) => value || '-',
},
{ title: '平台', dataIndex: 'provider', width: 90 },
{
title: '状态',
@@ -139,20 +163,18 @@ export default function HuyaRegisterPage() {
</Tag>
),
},
{ title: '验证码', dataIndex: 'code', width: 100 },
{ title: '轮询', dataIndex: 'attempts', width: 80 },
{ title: '注册码', dataIndex: 'code', width: 100 },
{ title: '改密码', dataIndex: 'change_code', width: 100 },
{
title: '轮询',
width: 90,
render: (_, item) => `${item.attempts}/${item.change_attempts}`,
},
{
title: '账号',
width: 160,
render: (_, item) => item.uid || (item.account_id ? `#${item.account_id}` : '-'),
},
{
title: 'Cookie',
dataIndex: 'cookie_preview',
width: 220,
ellipsis: true,
render: (value: string) => value || '-',
},
{
title: '消息',
dataIndex: 'message',
@@ -223,6 +245,35 @@ export default function HuyaRegisterPage() {
style={{ width: '100%' }}
/>
</Col>
<Col xs={24} md={8}>
<Text type="secondary"></Text>
<Space.Compact style={{ width: '100%' }}>
<Segmented
value={passwordMode}
options={[
{ label: '随机', value: 'random' },
{ label: '固定', value: 'fixed' },
]}
onChange={(value) => setPasswordMode(value as 'random' | 'fixed')}
disabled={isRunning}
/>
{passwordMode === 'random' ? (
<Input
value={passwordPrefix}
maxLength={8}
onChange={(event) => setPasswordPrefix(event.target.value)}
disabled={isRunning}
/>
) : (
<Input.Password
value={fixedPassword}
maxLength={64}
onChange={(event) => setFixedPassword(event.target.value)}
disabled={isRunning}
/>
)}
</Space.Compact>
</Col>
<Col xs={24} md={4}>
<Space style={{ width: '100%', paddingTop: 22 }}>
<Button
@@ -257,7 +308,7 @@ export default function HuyaRegisterPage() {
</Button>
<Button icon={<DownloadOutlined />} disabled={successRows.length === 0} onClick={handleExportSuccess}>
CK
</Button>
</Space>
)}
@@ -276,7 +327,7 @@ export default function HuyaRegisterPage() {
dataSource={batch?.items || []}
loading={refreshing && !isRunning}
pagination={{ pageSize: 20, showSizeChanger: true }}
scroll={{ x: 1280 }}
scroll={{ x: 1320 }}
/>
</Card>
</Space>