虎牙网页Cookie来源驱动合并与WSS传输门禁

This commit is contained in:
yml2213
2026-09-01 19:17:32 +08:00
parent 8e3c0e69bc
commit 48c37bb8d7
16 changed files with 840 additions and 57 deletions
+4 -17
View File
@@ -8,8 +8,6 @@ from typing import TYPE_CHECKING, Any
from sqlalchemy.orm import Session
from core.huya import HuyaHttpClient
from ..models import HuyaAccount, HuyaRechargeGoodsSnapshot, HuyaTask
HUYA_RECHARGE_ACT_ID = 25135
@@ -43,6 +41,7 @@ class RechargeMixin:
def _mark_task(self, *args: Any, **kwargs: Any) -> None: ...
def _update_task_progress(self, *args: Any, **kwargs: Any) -> None: ...
def _open_wss_session(self, uid: int, cookie: str, kind: str): ...
def _shop_client(self, uid: int, cookie: str): ...
@staticmethod
def _format_local_time(timestamp: int) -> str: ...
@@ -205,9 +204,7 @@ class RechargeMixin:
self._mark_task(worker_db, task, "failed", "账号 Cookie 为空")
return
client: Any = HuyaHttpClient(
logger=lambda msg: self._push_log("info", f"[{uid}] {msg}")
)
client: Any = self._shop_client(uid, cookie)
task_resp = client.get_act_task_detail(
uid=uid, cookie=cookie, act_id=HUYA_RECHARGE_ACT_ID
)
@@ -403,14 +400,7 @@ class RechargeMixin:
)
unit_price = int(snapshot.price or 0) if snapshot else 0
try:
client: Any = self._open_wss_session(uid, cookie, "shop")
self._push_log("info", f"[{uid}] 商城链路使用 WSS 会话")
except Exception as exc: # noqa: BLE001 - HTTP fallback is explicit
self._push_log("warning", f"[{uid}] 商城 WSS 不可用,回退 HTTP: {type(exc).__name__}")
client = HuyaHttpClient(
logger=lambda msg: self._push_log("info", f"[{uid}] {msg}")
)
client: Any = self._shop_client(uid, cookie)
detail_resp = client.get_goods_info(
uid=uid,
guid="",
@@ -579,10 +569,7 @@ class RechargeMixin:
account.updated_at = datetime.now(UTC)
if payment_status == "paid":
account.status = "recharge_paid"
score_client = client if hasattr(client, "query_user_score") else HuyaHttpClient(
logger=lambda msg: self._push_log("info", f"[{uid}] {msg}")
)
post_score = score_client.query_user_score(
post_score = client.query_user_score(
uid=uid, cookie=cookie, sid=self._to_int(config_info.get("sid")) or 2203
)
if post_score is not None: