feat: filter cookies to only store required 10 based on HAR analysis

- Define REQUIRED_COOKIE_NAMES in login_helper.py (10 cookies from HAR)
- login_helper.py: import-time filtering + strict all-or-nothing validation
- pickup_api.py: save_session() filters to whitelist only (prevents accumulation)
- engine.py: unified strict check, all 10 cookies required

Based on portal-to-pickup-full-flow.har analysis:
  - All /pickup-web/a/* APIs use exactly 9 cookies
  - JSESSIONID additionally needed for portal page fetch (Referer)
  - enable_HFZrs6pXKulz is portal UI only, excluded
This commit is contained in:
2026-06-12 11:22:32 +08:00
parent 683e5b46de
commit 2fbb7fc8a5
3 changed files with 74 additions and 12 deletions
+5 -3
View File
@@ -11,6 +11,7 @@ from typing import Any, Callable
from log import debug as _ld, trace as _lt, user as _lu
from pickup_api import PickupAPI, PickupSession, TokenBridge
from field_mapping import get_fixed_value_str, translate_value
from login_helper import REQUIRED_COOKIE_NAMES
# ─── Submit 表单构建器 ─────────────────────────────────────────────────
@@ -368,11 +369,12 @@ class PickupEngine:
session_path = self._get_session_path()
if self._sess.load_session(session_path):
cookie_names = {c.name for c in self._sess._http.cookies}
missing = [n for n in ("JSESSIONID", "jdpt.session.id") if n not in cookie_names]
missing = [n for n in REQUIRED_COOKIE_NAMES if n not in cookie_names]
if missing:
self._ulog(f"缺少关键 cookie: {', '.join(missing)},请重新登录并手动填写")
self._ulog(f"缺少必需 cookie ({len(missing)}/{len(REQUIRED_COOKIE_NAMES)}): "
f"{', '.join(missing)},请重新登录并导入 cookies")
else:
self._dlog("已加载登录会话")
self._dlog(f"已加载登录会话 ({len(REQUIRED_COOKIE_NAMES)} 个 cookie 齐全)")
else:
self._ulog("未找到登录会话,请先登录")