feat: add 新增验证码登录
This commit is contained in:
@@ -387,6 +387,14 @@ class WakeUpRequest(BaseModel):
|
||||
Proxy: Optional[str] = ""
|
||||
|
||||
|
||||
class VerifyCodeRequest(BaseModel):
|
||||
"""手机验证码验证:默认只需要 key + code,data62/ticket 优先从缓存补全。"""
|
||||
key: str
|
||||
code: str
|
||||
data62: Optional[str] = ""
|
||||
ticket: Optional[str] = ""
|
||||
|
||||
|
||||
@app.middleware("http")
|
||||
async def log_requests(request: Request, call_next):
|
||||
logger.info("HTTP %s %s from %s", request.method, request.url.path, request.client.host if request.client else "-")
|
||||
@@ -942,6 +950,12 @@ async def check_scan_status(
|
||||
data62 = (stored.get("data62") or "").strip()
|
||||
if not data62:
|
||||
data62 = (data.get("Data62") or (data.get("Data") or {}).get("Data62") or (data.get("Data") or {}).get("data62") or "").strip()
|
||||
# 缓存 ticket 与 data62,供 /auth/verify-code 直接使用(前端只填验证码即可)
|
||||
qrcode_store[key] = {
|
||||
**stored,
|
||||
"ticket": ticket,
|
||||
"data62": data62,
|
||||
}
|
||||
params = {"key": SLIDER_VERIFY_KEY, "ticket": ticket}
|
||||
if data62:
|
||||
params["data62"] = data62
|
||||
@@ -955,6 +969,62 @@ async def check_scan_status(
|
||||
return data
|
||||
|
||||
|
||||
@app.post("/auth/verify-code")
|
||||
async def verify_login_code(body: VerifyCodeRequest):
|
||||
"""
|
||||
手机验证码验证(本地入口):
|
||||
- 前端只传 key + code;
|
||||
- data62/ticket 优先从缓存补全;
|
||||
- 转发到 7006: POST /login/VerifyCode?key=...
|
||||
"""
|
||||
key = (body.key or "").strip()
|
||||
code = (body.code or "").strip()
|
||||
if not key:
|
||||
raise HTTPException(status_code=400, detail="key is required")
|
||||
if not code:
|
||||
raise HTTPException(status_code=400, detail="code is required")
|
||||
|
||||
stored = qrcode_store.get(key) or {}
|
||||
data62 = (body.data62 or "").strip() or (stored.get("data62") or "").strip()
|
||||
ticket = (body.ticket or "").strip() or (stored.get("ticket") or "").strip()
|
||||
if not data62 or not ticket:
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail="missing data62 or ticket; please get qrcode and check scan status first",
|
||||
)
|
||||
|
||||
payload = {
|
||||
"code": code,
|
||||
"data62": data62,
|
||||
"ticket": ticket,
|
||||
}
|
||||
url = f"{CHECK_STATUS_BASE_URL.rstrip('/')}/login/VerifyCode"
|
||||
logger.info("VerifyCode: key=%s, url=%s, code_len=%s, data62_len=%s, ticket_len=%s",
|
||||
key, url, len(code), len(data62), len(ticket))
|
||||
try:
|
||||
async with httpx.AsyncClient(trust_env=False, timeout=20.0) as client:
|
||||
resp = await client.post(url, params={"key": key}, json=payload)
|
||||
except Exception as exc:
|
||||
logger.exception("Error calling upstream VerifyCode: %s", exc)
|
||||
raise HTTPException(status_code=502, detail=f"upstream_error: {exc}") from exc
|
||||
|
||||
body_text = resp.text[:500]
|
||||
logger.info("Upstream VerifyCode response: status=%s, body=%s", resp.status_code, body_text)
|
||||
if resp.status_code >= 400:
|
||||
raise HTTPException(
|
||||
status_code=502,
|
||||
detail={
|
||||
"error": "upstream_bad_response",
|
||||
"status_code": resp.status_code,
|
||||
"body": body_text,
|
||||
},
|
||||
)
|
||||
try:
|
||||
return resp.json()
|
||||
except Exception:
|
||||
return {"ok": True, "text": body_text}
|
||||
|
||||
|
||||
def _slider_form_html(key_val: str, data62_val: str, ticket_val: str) -> str:
|
||||
"""本地滑块验证页:与 7765 相同 DOM 结构(#app、keyInput、data62Input、originalTicketInput),加载 7765 的 module 脚本,不用 iframe。"""
|
||||
k = html.escape(key_val, quote=True)
|
||||
|
||||
Reference in New Issue
Block a user