refactor(share): 太阳码生成传 app=pregnancy 替代硬编码 path

box_app /api/wxacode 新增 app=identifier 模式:
  - 自动查 box_app 后台 App 表,scene 编码 "app=<identifier>"
  - CRMEB web_view 容器页收到后查 /api/mp/apps 找 url
  - 4 个 H5 共享 box_app 一个接口,CRMEB 无需维护映射表

app_03 改动:
  - 硬编码 WXACODE_PATH = "pages/annex/web_view/index" 改为
    APP_IDENTIFIER = "pregnancy"(box_app 后台 App.identifier 值)
  - 调用 /api/wxacode?app=pregnancy&width=430
  - 关注点分离:app_03 不需要知道目标小程序路径

后续扩展:
  - atoll/voce/zeno H5 项目只需在自己代码里改 APP_IDENTIFIER 常量
  - box_app 后台同步加对应 App 记录即可
This commit is contained in:
2026-07-08 16:32:34 +08:00
parent 772700cd85
commit 501201e81d

View File

@@ -536,18 +536,22 @@ export async function generateShareData(
// ─── WXacode(外部服务,box_app 太阳码生成)─── // ─── WXacode(外部服务,box_app 太阳码生成)───
// //
// 调用 box_app /api/wxacode,生成可被微信扫码直接进入 CRMEB 小程序的太阳码。 // 调用 box_app /api/wxacode?app=<identifier>,生成可被微信扫码直接进入
// scene 留空——目标页是 CRMEB 通用 web-view 容器 pages/annex/web_view/index, // 对应 H5 的小程序太阳码。box_app 后台 App 表保存每个 H5 的 url。
// 扫码后收件人直接进入 app_03 H5 首页(与「分享 → 扫码进首页」流程一致)。 // 太阳码 scene 编码 "app=<identifier>",CRMEB 收到后查 /api/mp/apps 找 url。
//
// 模式 1(保留,兼容旧调用):?path=...&scene=...
// 模式 2(推荐):?app=<identifier>,box_app 自动查表 + 编码 scene
const WXACODE_API_HOST = "https://mp.yizhezhe.com"; const WXACODE_API_HOST = "https://mp.yizhezhe.com";
const WXACODE_PATH = "pages/annex/web_view/index"; // 当前 H5(孕育无忧)在 box_app 后台 App.identifier 值
const APP_IDENTIFIER = "pregnancy";
/** 调用 box_app 生成小程序太阳码,返回 blob URL(用于 <img> 展示) */ /** 调用 box_app 生成小程序太阳码,返回 blob URL(用于 <img> 展示) */
export async function generateWxacode( export async function generateWxacode(
options: { width?: number } = {} options: { width?: number } = {}
): Promise<string> { ): Promise<string> {
const params = new URLSearchParams({ const params = new URLSearchParams({
path: WXACODE_PATH, app: APP_IDENTIFIER,
width: String(options.width ?? 430), width: String(options.width ?? 430),
}); });
const res = await fetch(`${WXACODE_API_HOST}/api/wxacode?${params}`); const res = await fetch(`${WXACODE_API_HOST}/api/wxacode?${params}`);