增加另一个登录接口

This commit is contained in:
yml2213
2026-06-26 17:22:51 +08:00
parent f736ef4f4c
commit d7d7c0cbb0
12 changed files with 1739 additions and 73 deletions
+1
View File
@@ -60,6 +60,7 @@ async def create_batch(
log_queue=log_queue,
loop=loop,
concurrency=req.concurrency,
api_strategy=req.api_strategy,
)
batch_id = runner.batch_id
+1
View File
@@ -127,6 +127,7 @@ class LoginBatchRequest(BaseModel):
max_login_retries: int = 0 # 登录整体重试次数,0=无限重试直到成功(后端兜底 20 次)
max_total_time: float = 300 # 单账号登录总时长上限(秒),0=不限制
concurrency: int = 3 # 并发数,1-10
api_strategy: str = "wgapi" # 接口策略: wgapi(新版)或 iframe(旧版备选)
class LoginTaskOut(BaseModel):
+11 -1
View File
@@ -11,11 +11,18 @@ from typing import Optional
from sqlalchemy.orm import Session
from core.douyu import DouyuLogin
from core.douyu import DouyuLogin, WgapiLoginAPI, IframeLoginAPI
from core.douyu.proxy_fetcher import ProxyFetcher
from ..models import Account as AccountModel, LoginTask, ProxyConfig as ProxyConfigModel
def _create_api_strategy(strategy_name: str):
"""根据名称创建登录接口策略实例。"""
if strategy_name == "iframe":
return IframeLoginAPI()
return WgapiLoginAPI()
class LoginBatchRunner:
"""批量登录执行器,在线程中运行,通过 ThreadPoolExecutor 并发登录多个账号。"""
@@ -31,6 +38,7 @@ class LoginBatchRunner:
log_queue: Optional[asyncio.Queue] = None,
loop: Optional[asyncio.AbstractEventLoop] = None,
concurrency: int = 3,
api_strategy: str = "wgapi",
):
self.db = db
self.account_ids = account_ids
@@ -45,6 +53,7 @@ class LoginBatchRunner:
self.loop = loop
self.batch_id = uuid.uuid4().hex[:12]
self.concurrency = max(1, min(concurrency, 10)) # 限制 1-10
self.api_strategy = _create_api_strategy(api_strategy)
self._stop = threading.Event()
self._counter_lock = threading.Lock()
self._completed = 0
@@ -154,6 +163,7 @@ class LoginBatchRunner:
max_total_time=self.max_total_time,
proxy_fetcher=self._shared_proxy_fetcher,
stop_event=self._stop,
api_strategy=self.api_strategy,
)
result = loginer.login()