diff --git a/app/api/v1/device.py b/app/api/v1/device.py index cf53930..20fc4b7 100644 --- a/app/api/v1/device.py +++ b/app/api/v1/device.py @@ -29,8 +29,12 @@ from app.schemas.device import ( logger = logging.getLogger("shagua.device") -# PoC:源平台代号 → Android 包名(前端 launch 用)。当前只用美团。 -_SOURCE_PACKAGES = {"meituan": "com.sankuai.meituan"} +# PoC:源平台代号 → Android 包名(前端 launch 用)。poller 按分享的小程序卡区分平台。 +# 客户端只认 source_package:用它反查平台名(弹窗"原平台")+ launch 对应 App,故新增平台只需在此登记包名。 +_SOURCE_PACKAGES = { + "meituan": "com.sankuai.meituan", + "jd": "com.jingdong.app.mall", # 京东主 App(含京东秒送/外卖),后端 intent skill=jd_waimai +} router = APIRouter(prefix="/api/v1/device", tags=["device"]) diff --git a/scripts/wx_finance_poller.py b/scripts/wx_finance_poller.py index f3f7083..864d849 100644 --- a/scripts/wx_finance_poller.py +++ b/scripts/wx_finance_poller.py @@ -10,6 +10,7 @@ """ from __future__ import annotations +import json import logging import signal import time @@ -62,6 +63,25 @@ def _notify(client: httpx.Client, source: str, kind: str) -> None: logger.exception("notify app-server 失败") +def _resolve_source(msg: dict) -> str: + """从 weapp 小程序卡判源平台代号(= app-server _SOURCE_PACKAGES 的 key)。 + + 会话存档 weapp 结构里 username(gh_id)/appid/pagepath/title 任一含平台特征即判定: + 先按关键词启发式(覆盖大多数);认不出 → 默认 meituan(过渡期不阻断)+ WARNING, + 并把整个 weapp 结构打进日志,便于照真实 username/appid 精确补规则。 + """ + weapp = msg.get("weapp") or {} + blob = json.dumps(weapp, ensure_ascii=False).lower() + # 排障日志:打全 weapp 结构(顺带 msg 顶层 key,防结构不在 weapp 下),便于补/改判定规则 + logger.info("weapp 判源: msg_keys=%s weapp=%s", list(msg.keys()), blob[:1500]) + if any(k in blob for k in ("jingdong", "jd.com", "jddj", "京东")): + return "jd" + if any(k in blob for k in ("meituan", "sankuai", "美团")): + return "meituan" + logger.warning("weapp 源平台未识别, 暂默认 meituan;见上一行结构日志补 _resolve_source 规则") + return "meituan" + + def _handle(client: httpx.Client, msg: dict) -> None: """明文消息:外部用户(from≠接收成员)发来的 weapp/image → 通知 app-server 打信号。""" msgtype = msg.get("msgtype") or "" @@ -71,8 +91,10 @@ def _handle(client: httpx.Client, msg: dict) -> None: return # 成员自己发的, 跳过 if msgtype not in ("weapp", "image"): return - logger.info("命中触发 from=%s type=%s", frm, msgtype) - _notify(client, "meituan", msgtype) + # weapp 卡片按小程序判源平台;image(截图)判不出平台,沿用 meituan。 + source = _resolve_source(msg) if msgtype == "weapp" else "meituan" + logger.info("命中触发 from=%s type=%s source=%s", frm, msgtype, source) + _notify(client, source, msgtype) def main() -> None: