verify_token.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. """Verify the token in users table is REAL (calls 996box API to check)."""
  2. import sys
  3. from pathlib import Path
  4. _HERE = Path(__file__).resolve().parent
  5. sys.path.insert(0, str(_HERE.parent / "src"))
  6. from cq2_sdk.env_loader import load_env
  7. load_env(_HERE.parent / ".env")
  8. from cq2_sdk.login import Box996Login, ManualGeetestSolver
  9. from cq2_sdk.store import UserStore, connection
  10. ACCOUNT = "longwu988"
  11. def is_real_token(token: str):
  12. """调用 996box 一个无副作用的 API, 验 token 是否真。
  13. 真实验证端点 (从 手机号短信验证登录过程.saz session 309 逆向):
  14. GET api.996hezi.com/user/v1/phoneOptionInfo → code=200
  15. 旧的 getTodayOpen 已 404 (服务端路径变了), 不能再用。
  16. """
  17. import asyncio
  18. box = Box996Login(geetest=ManualGeetestSolver(), device_id="00:15:5d:0a:04:00")
  19. box.token = token
  20. try:
  21. r = asyncio.run(box._request(
  22. "GET", "https://api.996hezi.com", "/user/v1/phoneOptionInfo",
  23. ))
  24. if r.get("code") == 200:
  25. return True, f"OK, code=200, msg={r.get('msg', '')}"
  26. return False, f"code={r.get('code')}, msg={r.get('msg', '')[:80]}"
  27. except Exception as e:
  28. return False, f"{type(e).__name__}: {str(e)[:120]}"
  29. with connection() as conn:
  30. u = UserStore(conn).get_by_username(ACCOUNT)
  31. if u is None:
  32. print(f"[FAIL] {ACCOUNT} not in DB. Run scaffold first.")
  33. sys.exit(1)
  34. if not u.token:
  35. print(f"[FAIL] {ACCOUNT} has no token. Run A1 first.")
  36. sys.exit(1)
  37. print(f"--- {ACCOUNT} token check ---")
  38. print(f" token (24) = {u.token[:24]}...")
  39. print(f" password_hash = {u.password_hash}")
  40. print(f" phone = {u.phone}")
  41. print()
  42. # Quick fake-token smell test (no network)
  43. if "FAKE" in u.token.upper() or "SCAFFOLD" in u.token.upper():
  44. print("[SMELL] token contains 'FAKE' or 'SCAFFOLD' — definitely not real")
  45. print(" run A1 to overwrite with real token")
  46. sys.exit(0)
  47. # Real check via API call
  48. print("calling 996box get_today_open to verify token...")
  49. ok, msg = is_real_token(u.token)
  50. if ok:
  51. print(f"[OK] token is REAL — {msg}")
  52. else:
  53. print(f"[FAIL] token rejected by 996box — {msg}")
  54. print(" re-run A1 to get a fresh token")