From 4b8ec7c53950a9d2225ecc6261124c825d32a7be Mon Sep 17 00:00:00 2001 From: zzhyyyyy <2685922758@qq.com> Date: Sat, 18 Jul 2026 16:38:34 +0800 Subject: [PATCH] =?UTF-8?q?feat(wx-poc):=20=E4=BC=9A=E8=AF=9D=E5=AD=98?= =?UTF-8?q?=E6=A1=A3=E6=8C=89=E5=B0=8F=E7=A8=8B=E5=BA=8F=E5=8D=A1=E5=8C=BA?= =?UTF-8?q?=E5=88=86=E6=BA=90=E5=B9=B3=E5=8F=B0,=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E4=BA=AC=E4=B8=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 原 poller 把所有 weapp 卡片写死成 source="meituan",分享京东也会让手机弹/开 美团。现按 weapp 结构判源: - poller 新增 _resolve_source(): 按 weapp username/appid/title 关键词判平台 (jingdong/京东 → jd, meituan/美团 → meituan);认不出默认 meituan + 打 WARNING 并日志全量 weapp 结构,便于照真实 username/appid 精确补规则。 - app-server _SOURCE_PACKAGES 加 jd → com.jingdong.app.mall。 客户端无需改动(只认 source_package 反查平台名 + launch),纯服务端可热部署。 Co-Authored-By: Claude Opus 4.8 --- app/api/v1/device.py | 8 ++++++-- scripts/wx_finance_poller.py | 26 ++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 4 deletions(-) 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: