# 丰享订单监控 —— 项目上下文(给 AI 协作用) ## 一句话 监控丰享商家端(fs.szfx.com)新订单 → 推企业微信。本机负责登录(过腾讯验证码), 服务器 Docker 负责 7×24 轮询与推送。 ## 运行形态 - 本机 Windows:`run.bat` 跑 `order_monitor.py`;`login.bat` 跑 `fengxiang_scraper.py` 登录并上传 Cookie - 服务器:`/data/docker/fengxiang-monitor`,容器 `fengxiang-monitor`,宿主机 `52100` → 容器 `8089` - 生产只启用企业微信通道;飞书配置位保留但默认关闭(原 token 已失效,`code=19001`) ## 代码约定 - 包 `fengxiang/`,配置三级覆盖:**环境变量 > config.yaml > config.py 的 DEFAULTS** - 密钥(webhook、admin token)只能出现在 `config.yaml` / `.env`,绝不写进源码 - 异常分三类:`SessionExpired`(要登录)/ `ApiError`(业务错误码)/ `NetworkError`(可重试) - 状态用 `store.State`:`last_order_id` + `pushed_ids` 双保险去重,写入必须原子(tmp + os.replace) - 推送失败不能抛到主循环;告警必须经过 `Dispatcher.alert` 的冷却 - 主循环任何异常都要兜住(`except Exception` 记日志后继续),进程不能死 - TTS 只在 `sys.platform == "win32"` 且 `tts.enabled` 时启用 ## 关键业务规则 1. 首次启动只建基线,**不推历史订单** 2. 积压 > `bulk_summary_threshold`(默认 5)时发一条汇总,不逐条推 3. 夜间 21:00–07:40 分片休眠(每 60s 醒一次),期间仍响应 Cookie 更新与停止信号 4. Cookie 文件变化自动热重载,无需重启容器 5. 会话失效 → 告警(30min 冷却)→ 阻塞等待新 Cookie → 自动恢复并回推恢复通知 ## 常用命令 ```bash python -m unittest discover -s tests -v # 22 项测试,不联网 python fetch_orders.py 1 5 # 调试取单 python push_latest_order.py --dry # 调试推送 docker compose up -d --build && docker compose logs -f curl -s localhost:52100/healthz ``` ## 已知坑 - 丰享接口是逆向的,`errno` 含义可能变;会话失效码目前 `{110003, 10009}` - 未配置 `admin.token` 时写接口只允许 127.0.0.1(避免裸奔) - 单实例:状态文件无锁,同店铺不要起两个容器 - `amountPayable` 单位是**分**,展示要 /100 - 原仓库历史里有明文 webhook,已迁到配置;改动提交时不要再写回源码