打开绑卡任务对应的 checkout 链接
(task_id: int)
| 2473 | |
| 2474 | @router.post("/bind-card/tasks/{task_id}/open") |
| 2475 | def open_bind_card_task(task_id: int): |
| 2476 | """打开绑卡任务对应的 checkout 链接""" |
| 2477 | with get_db() as db: |
| 2478 | task = db.query(BindCardTask).options(joinedload(BindCardTask.account)).filter(BindCardTask.id == task_id).first() |
| 2479 | if not task: |
| 2480 | raise HTTPException(status_code=404, detail="绑卡任务不存在") |
| 2481 | if not task.checkout_url: |
| 2482 | raise HTTPException(status_code=400, detail="任务缺少 checkout 链接") |
| 2483 | |
| 2484 | cookies_str = task.account.cookies if task.account else None |
| 2485 | logger.info("打开绑卡任务: task_id=%s account_id=%s", task.id, task.account_id) |
| 2486 | opened = open_url_incognito(task.checkout_url, cookies_str) |
| 2487 | if opened: |
| 2488 | if str(task.status or "") not in ("paid_pending_sync", "completed"): |
| 2489 | task.status = "opened" |
| 2490 | task.opened_at = utcnow_naive() |
| 2491 | task.last_error = None |
| 2492 | db.commit() |
| 2493 | db.refresh(task) |
| 2494 | logger.info("绑卡任务打开成功: task_id=%s", task.id) |
| 2495 | return {"success": True, "task": _serialize_bind_card_task(task)} |
| 2496 | |
| 2497 | task.last_error = "未找到可用的浏览器" |
| 2498 | db.commit() |
| 2499 | logger.warning("绑卡任务打开失败: task_id=%s reason=%s", task.id, task.last_error) |
| 2500 | raise HTTPException(status_code=500, detail="未找到可用的浏览器,请手动复制链接") |
| 2501 | |
| 2502 | |
| 2503 | @router.post("/bind-card/tasks/{task_id}/auto-bind-third-party") |
nothing calls this directly
no test coverage detected