fix(douyu): 和平小店绑定二维码自动弹出 + 扫码后自动更新角色

- 后端: get_xpd_bind_qr 生成二维码后保持 running, 每 5s 轮询
  bindInfo(最长 300s), 检测到绑定即回写角色并自动结束
- 前端: hasBindQrcode 纳入 get_xpd_bind_qr → 新二维码自动弹出;
  弹窗显示等待扫码/绑定成功状态与角色; 对 xpd 任务隐藏
  不适用的"查询角色/确认绑定"按钮
This commit is contained in:
yml2213
2026-08-06 17:42:17 +08:00
parent 5f63d77dc3
commit ee097e1fda
2 changed files with 117 additions and 29 deletions
+81 -2
View File
@@ -29,6 +29,8 @@ from .douyu_service import (
DOUYU_LEGACY_BIND_ACT_ALIAS = "20250213NQCYX"
DOUYU_BIND_ROLE_POLL_SECONDS = 65
DOUYU_BIND_ROLE_POLL_INTERVAL = 5
DOUYU_XPD_BIND_POLL_SECONDS = 300
DOUYU_XPD_BIND_POLL_INTERVAL = 5
DOUYU_PAYMENT_POLL_SECONDS = 600
DOUYU_PAYMENT_POLL_INTERVAL = 5
DOUYU_GIFT_POINTS_REFRESH_TIMES = 3
@@ -1084,7 +1086,7 @@ class DouyuBatchRunner:
cookie: str,
config: dict,
):
"""生成和平小店绑定二维码(微信扫码在小程序内绑定角色)"""
"""生成和平小店绑定二维码并轮询等待微信扫码绑定完成"""
client = self._client(cookie)
act_alias = str(config.get("xpd_act_alias") or "").strip()
if not act_alias:
@@ -1094,7 +1096,84 @@ class DouyuBatchRunner:
account.xpd_bind_status = "xpd_bind_qr_ready"
account.updated_at = datetime.now(timezone.utc)
db.commit()
self._mark_task(db, task, "success", "小店绑定二维码已生成", result)
result["bind_polling"] = True
self._update_task_progress(
db,
task,
"running",
"二维码已生成,请微信扫码在小程序中绑定角色",
result,
)
bound = self._wait_xpd_bind(db, task, account, client, act_alias, result)
if self._stop.is_set():
result["bind_polling"] = False
self._mark_task(db, task, "stopped", "任务已停止", result)
return
if bound:
account.xpd_bind_status = "xpd_bound"
account.updated_at = datetime.now(timezone.utc)
db.commit()
role_text = str(result.get("role_name") or account.xpd_game_name or "-")
self._mark_task(db, task, "success", f"小店绑定成功: {role_text}", result)
return
result["bind_polling"] = False
self._mark_task(
db,
task,
"failed",
"未检测到小店绑定(二维码仍有效,可再次生成后扫码)",
result,
)
def _wait_xpd_bind(
self,
db: Session,
task: DouyuTask,
account: Account,
client: DouyuActivityClient,
act_alias: str,
result: dict,
) -> bool:
"""轮询 bindInfo,检测到绑定角色即回写账号并返回 True。"""
deadline = time.monotonic() + DOUYU_XPD_BIND_POLL_SECONDS
poll_count = 0
while not self._stop.is_set() and time.monotonic() <= deadline:
try:
info = client.xpd_bind_info(act_alias=act_alias)
poll_count += 1
result["bind_poll_count"] = poll_count
result["bind_polling"] = True
role_name = str(info.get("role_name") or "")
if info.get("bind_role") and role_name:
result.update({key: value for key, value in info.items() if key != "raw"})
result["bind_polling"] = False
result["xpd_bound"] = True
account.xpd_game_name = role_name
account.updated_at = datetime.now(timezone.utc)
db.commit()
return True
self._update_task_progress(
db,
task,
"running",
f"等待扫码绑定(第 {poll_count} 次)",
result,
)
except Exception as exc:
poll_count += 1
result["bind_poll_count"] = poll_count
result["bind_poll_error"] = str(exc)
self._update_task_progress(
db,
task,
"running",
f"等待扫码绑定: {exc}",
result,
)
if self._stop.wait(DOUYU_XPD_BIND_POLL_INTERVAL):
break
result["bind_polling"] = False
return False
def _execute_query_xpd_bind_info(
self,