diff --git a/apps/admin/deploy/_upload_new_props_82.py b/apps/admin/deploy/_upload_new_props_82.py new file mode 100644 index 0000000..accd755 --- /dev/null +++ b/apps/admin/deploy/_upload_new_props_82.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +"""Upload ops prop PNGs to admin.nomadro.cn/props/ (CORS for WeChat batch).""" +from __future__ import annotations + +from pathlib import Path + +import paramiko + +HOST, USER, PASS = "82.157.112.245", "ubuntu", "Xiao4669805" +LOCAL = Path(__file__).resolve().parents[1] / "public" / "props" +FILES = ( + "nomad_lite.png", + "nomad_plus.png", + "nomad_pro.png", + "pay_test.png", + "29.png", + "298.png", + "588.png", + "test.png", + "nomad.png", + "tiktok.png", + "youtube.png", + "ebook.png", + "svip.png", +) + +c = paramiko.SSHClient() +c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) +c.connect(HOST, username=USER, password=PASS, timeout=40, allow_agent=False, look_for_keys=False) +sftp = c.open_sftp() +c.exec_command("mkdir -p /tmp/wx_props_new", timeout=10) +for name in FILES: + path = LOCAL / name + if not path.is_file(): + print("skip missing", name) + continue + sftp.put(str(path), f"/tmp/wx_props_new/{name}") + print("up", name, path.stat().st_size) +sftp.close() +_, o, e = c.exec_command( + "sudo cp -a /tmp/wx_props_new/. /www/wwwroot/admin.nomadro.cn/props/ && " + "sudo chown -R www:www /www/wwwroot/admin.nomadro.cn/props && " + "ls -lah /www/wwwroot/admin.nomadro.cn/props/ && " + "curl -sI https://admin.nomadro.cn/props/nomad_lite.png -H 'Origin: https://mp.weixin.qq.com' | tr -d '\\r' | head -15" +) +print(o.read().decode()) +err = e.read().decode() +if err: + print("stderr", err) +c.close() diff --git a/apps/admin/public/props/29.png b/apps/admin/public/props/29.png index ae50fd8..9a0a26f 100644 Binary files a/apps/admin/public/props/29.png and b/apps/admin/public/props/29.png differ diff --git a/apps/admin/public/props/298.png b/apps/admin/public/props/298.png index 0f9d296..0023f3f 100644 Binary files a/apps/admin/public/props/298.png and b/apps/admin/public/props/298.png differ diff --git a/apps/admin/public/props/588.png b/apps/admin/public/props/588.png index 0098038..068eeaa 100644 Binary files a/apps/admin/public/props/588.png and b/apps/admin/public/props/588.png differ diff --git a/apps/admin/public/props/nomad_lite.png b/apps/admin/public/props/nomad_lite.png new file mode 100644 index 0000000..9a0a26f Binary files /dev/null and b/apps/admin/public/props/nomad_lite.png differ diff --git a/apps/admin/public/props/nomad_plus.png b/apps/admin/public/props/nomad_plus.png new file mode 100644 index 0000000..0023f3f Binary files /dev/null and b/apps/admin/public/props/nomad_plus.png differ diff --git a/apps/admin/public/props/nomad_pro.png b/apps/admin/public/props/nomad_pro.png new file mode 100644 index 0000000..068eeaa Binary files /dev/null and b/apps/admin/public/props/nomad_pro.png differ diff --git a/apps/admin/public/props/pay_test.png b/apps/admin/public/props/pay_test.png new file mode 100644 index 0000000..918e6b7 Binary files /dev/null and b/apps/admin/public/props/pay_test.png differ diff --git a/apps/admin/public/props/test.png b/apps/admin/public/props/test.png index 6268cf9..918e6b7 100644 Binary files a/apps/admin/public/props/test.png and b/apps/admin/public/props/test.png differ diff --git a/apps/api/services/ebook_svc/domains/books/products.py b/apps/api/services/ebook_svc/domains/books/products.py index bc5781e..83c5599 100644 --- a/apps/api/services/ebook_svc/domains/books/products.py +++ b/apps/api/services/ebook_svc/domains/books/products.py @@ -1,8 +1,7 @@ -"""虚拟支付道具目录:免费 + 微信已发布道具。 +"""虚拟支付道具目录(运营 SoT)。 -已发布(MP): - tiktok / youtube / nomad / svip / ebook_unlock_default / 29 / 298 / 588 -价格单位:分;道具 ID 与名称字段一致(ebook 道具 ID 为 ebook_unlock_default)。 +档位面向付费用户:名称是货架文案,product_id 是微信侧支付 SKU。 +价格单位:分。微信 MP「道具名称」≤10 字、「备注」≤50 字不对外。 """ from __future__ import annotations @@ -19,111 +18,115 @@ PRODUCT_OFFERS: list[dict[str, Any]] = [ "unlock_percent": 100, "free": True, "image": "", - "remark": "免费加入,不拉起支付", + "remark": "全书可读,不拉起支付", }, { - "key": "tiktok", - "label": "tiktok", - "name": "tiktok", - "product_id": "tiktok", - "price_fen": 8800, + "key": "yen29", + "label": "轻享", + "name": "轻享全书", + "product_id": "nomad_lite", + "price_fen": 2900, "unlock_percent": 30, "free": False, - "image": "props/tiktok.png", - "remark": "已发布 · ¥88", - }, - { - "key": "youtube", - "label": "youtube", - "name": "youtube", - "product_id": "youtube", - "price_fen": 18800, - "unlock_percent": 30, - "free": False, - "image": "props/youtube.png", - "remark": "已发布 · ¥188", + "image": "props/nomad_lite.png", + "remark": "入门价·首次解锁单本推荐", }, { "key": "nomad", - "label": "nomad", - "name": "nomad", + "label": "漫游", + "name": "漫游全书", "product_id": "nomad", "price_fen": 4900, "unlock_percent": 30, "free": False, "image": "props/nomad.png", - "remark": "已发布 · ¥49", + "remark": "标准漫游档·性价比主推", }, { - "key": "svip", - "label": "svip", - "name": "svip", - "product_id": "svip", - "price_fen": 99800, + "key": "tiktok", + "label": "短视频", + "name": "短视频全书", + "product_id": "tiktok", + "price_fen": 8800, "unlock_percent": 30, "free": False, - "image": "props/svip.png", - "remark": "已发布 · ¥998", + "image": "props/tiktok.png", + "remark": "短视频向专题全书", }, { - "key": "yen29", - "label": "29", - "name": "29", - "product_id": "29", - "price_fen": 2900, + "key": "youtube", + "label": "长视频", + "name": "长视频全书", + "product_id": "youtube", + "price_fen": 18800, "unlock_percent": 30, "free": False, - "image": "props/29.png", - "remark": "已发布 · ¥29", - }, - { - "key": "yen298", - "label": "298", - "name": "298", - "product_id": "298", - "price_fen": 29800, - "unlock_percent": 30, - "free": False, - "image": "props/298.png", - "remark": "已发布 · ¥298", - }, - { - "key": "yen588", - "label": "588", - "name": "588", - "product_id": "588", - "price_fen": 58800, - "unlock_percent": 30, - "free": False, - "image": "props/588.png", - "remark": "已发布 · ¥588", + "image": "props/youtube.png", + "remark": "长视频向·默认推荐档", }, { "key": "ebook", - "label": "ebook", - "name": "ebook", + "label": "经典", + "name": "经典全书", "product_id": "ebook_unlock_default", "price_fen": 18800, "unlock_percent": 30, "free": False, "image": "props/ebook.png", - "remark": "已发布 · ¥188 · 旧默认道具", + "remark": "历史默认档·兼容旧订单", + }, + { + "key": "yen298", + "label": "进阶", + "name": "进阶全书", + "product_id": "nomad_plus", + "price_fen": 29800, + "unlock_percent": 30, + "free": False, + "image": "props/nomad_plus.png", + "remark": "进阶价·高价值小册", + }, + { + "key": "yen588", + "label": "精英", + "name": "精英全书", + "product_id": "nomad_pro", + "price_fen": 58800, + "unlock_percent": 30, + "free": False, + "image": "props/nomad_pro.png", + "remark": "精英价·深度专题册", + }, + { + "key": "svip", + "label": "超级会员", + "name": "超级会员", + "product_id": "svip", + "price_fen": 99800, + "unlock_percent": 30, + "free": False, + "image": "props/svip.png", + "remark": "旗舰会员·最高权益档", }, { "key": "test", - "label": "test", - "name": "test", - "product_id": "test", - "price_fen": 100, # ¥1.00 测试 + "label": "联调", + "name": "联调占位", + "product_id": "pay_test", + "price_fen": 100, "unlock_percent": 30, "free": False, - "image": "props/test.png", - "remark": "测试道具 · ¥1 · 需在微信 MP 发布", + "image": "props/pay_test.png", + "remark": "仅内部联调·禁止对用户上架", }, ] -# 旧书把「价格数字」当 product_id;仅当目录中没有同名道具时才映射 +# 旧书 / 旧微信草稿 id → 现网 key _LEGACY_PRODUCT_IDS = { + "29": "yen29", + "298": "yen298", + "588": "yen588", + "test": "test", "188": "youtube", "49": "nomad", "998": "svip", @@ -140,7 +143,6 @@ def match_offer(book: dict[str, Any] | None) -> dict[str, Any]: if is_book_free(book): return PRODUCT_OFFERS[0] pid = str((book or {}).get("product_id") or "") - # 先精确匹配现网道具 id(含 29/298/588),再走遗留价格数字映射 for offer in PRODUCT_OFFERS: if offer["free"]: continue @@ -173,7 +175,7 @@ def apply_offer_key(key: str, current_unlock_percent: int | None = None) -> dict ( o for o in PRODUCT_OFFERS - if o["key"] == key or o["product_id"] == key or o["name"] == key + if o["key"] == key or o["product_id"] == key or o["name"] == key or o["label"] == key ), None, ) diff --git a/apps/hackrobot/nomadmini/backend/app/domains/books/products.py b/apps/hackrobot/nomadmini/backend/app/domains/books/products.py index 2496d5c..5aaf045 100644 --- a/apps/hackrobot/nomadmini/backend/app/domains/books/products.py +++ b/apps/hackrobot/nomadmini/backend/app/domains/books/products.py @@ -1,8 +1,7 @@ -"""虚拟支付道具目录:免费 + 微信已发布道具。 +"""虚拟支付道具目录(运营 SoT,与 apps/api ebook_svc 对齐)。 -已发布(MP): - tiktok / youtube / nomad / svip / ebook_unlock_default -价格单位:分;道具 ID 与名称字段一致(ebook 道具 ID 为 ebook_unlock_default)。 +档位面向付费用户:名称是货架文案,product_id 是微信侧支付 SKU。 +价格单位:分。微信 MP「道具名称」≤10 字、「备注」≤50 字不对外。 """ from __future__ import annotations @@ -19,110 +18,114 @@ PRODUCT_OFFERS: list[dict[str, Any]] = [ "unlock_percent": 100, "free": True, "image": "", - "remark": "unlock_percent=100,全书可读,不拉起支付", + "remark": "全书可读,不拉起支付", }, { - "key": "tiktok", - "label": "tiktok", - "name": "tiktok", - "product_id": "tiktok", - "price_fen": 29800, + "key": "yen29", + "label": "轻享", + "name": "轻享全书", + "product_id": "nomad_lite", + "price_fen": 2900, "unlock_percent": 30, "free": False, - "image": "props/tiktok.png", - "remark": "已发布 · ¥298", - }, - { - "key": "youtube", - "label": "youtube", - "name": "youtube", - "product_id": "youtube", - "price_fen": 18800, - "unlock_percent": 30, - "free": False, - "image": "props/youtube.png", - "remark": "已发布 · ¥188", + "image": "props/nomad_lite.png", + "remark": "入门价·首次解锁单本推荐", }, { "key": "nomad", - "label": "nomad", - "name": "nomad", + "label": "漫游", + "name": "漫游全书", "product_id": "nomad", "price_fen": 4900, "unlock_percent": 30, "free": False, "image": "props/nomad.png", - "remark": "已发布 · ¥49", + "remark": "标准漫游档·性价比主推", }, { - "key": "svip", - "label": "svip", - "name": "svip", - "product_id": "svip", - "price_fen": 99800, + "key": "tiktok", + "label": "短视频", + "name": "短视频全书", + "product_id": "tiktok", + "price_fen": 8800, "unlock_percent": 30, "free": False, - "image": "props/svip.png", - "remark": "已发布 · ¥998", + "image": "props/tiktok.png", + "remark": "短视频向专题全书", }, { - "key": "yen29", - "label": "29", - "name": "29", - "product_id": "29", - "price_fen": 2900, + "key": "youtube", + "label": "长视频", + "name": "长视频全书", + "product_id": "youtube", + "price_fen": 18800, "unlock_percent": 30, "free": False, - "image": "props/29.png", - "remark": "已发布 · ¥29", - }, - { - "key": "yen298", - "label": "298", - "name": "298", - "product_id": "298", - "price_fen": 29800, - "unlock_percent": 30, - "free": False, - "image": "props/298.png", - "remark": "已发布 · ¥298", - }, - { - "key": "yen588", - "label": "588", - "name": "588", - "product_id": "588", - "price_fen": 58800, - "unlock_percent": 30, - "free": False, - "image": "props/588.png", - "remark": "已发布 · ¥588", + "image": "props/youtube.png", + "remark": "长视频向·默认推荐档", }, { "key": "ebook", - "label": "ebook", - "name": "ebook", + "label": "经典", + "name": "经典全书", "product_id": "ebook_unlock_default", "price_fen": 18800, "unlock_percent": 30, "free": False, "image": "props/ebook.png", - "remark": "已发布 · ¥188 · 旧默认道具", + "remark": "历史默认档·兼容旧订单", + }, + { + "key": "yen298", + "label": "进阶", + "name": "进阶全书", + "product_id": "nomad_plus", + "price_fen": 29800, + "unlock_percent": 30, + "free": False, + "image": "props/nomad_plus.png", + "remark": "进阶价·高价值小册", + }, + { + "key": "yen588", + "label": "精英", + "name": "精英全书", + "product_id": "nomad_pro", + "price_fen": 58800, + "unlock_percent": 30, + "free": False, + "image": "props/nomad_pro.png", + "remark": "精英价·深度专题册", + }, + { + "key": "svip", + "label": "超级会员", + "name": "超级会员", + "product_id": "svip", + "price_fen": 99800, + "unlock_percent": 30, + "free": False, + "image": "props/svip.png", + "remark": "旗舰会员·最高权益档", }, { "key": "test", - "label": "test", - "name": "test", - "product_id": "test", - "price_fen": 100, # ¥1.00 测试 + "label": "联调", + "name": "联调占位", + "product_id": "pay_test", + "price_fen": 100, "unlock_percent": 30, "free": False, - "image": "props/test.png", - "remark": "测试道具 · ¥1 · 需在微信 MP 发布", + "image": "props/pay_test.png", + "remark": "仅内部联调·禁止对用户上架", }, ] _LEGACY_PRODUCT_IDS = { + "29": "yen29", + "298": "yen298", + "588": "yen588", + "test": "test", "188": "youtube", "49": "nomad", "998": "svip", @@ -171,7 +174,7 @@ def apply_offer_key(key: str, current_unlock_percent: int | None = None) -> dict ( o for o in PRODUCT_OFFERS - if o["key"] == key or o["product_id"] == key or o["name"] == key + if o["key"] == key or o["product_id"] == key or o["name"] == key or o["label"] == key ), None, ) diff --git a/apps/miniprogram/README.md b/apps/miniprogram/README.md index dd6041c..12e2af8 100644 --- a/apps/miniprogram/README.md +++ b/apps/miniprogram/README.md @@ -9,8 +9,8 @@ 业务 API:`apps/api`。管理后台:`apps/admin`。 -微信虚拟支付 / 道具目录:[`docs/wechat-virtual-pay-props.md`](docs/wechat-virtual-pay-props.md)。 -批量上传 xlsx(下次直接用):[`docs/wx-props-batch/`](docs/wx-props-batch/)。 +微信虚拟支付 / 运营货架:[`docs/wechat-virtual-pay-props.md`](docs/wechat-virtual-pay-props.md)。 +批量上传 xlsx(轻享/漫游/进阶…):[`docs/wx-props-batch/`](docs/wx-props-batch/)。 **全端禁止 web-view 承载业务内容**(VIP / 电子书 / 视频课等须原生页)。微信 VIP 说明见 `weapp/README.md`。 diff --git a/apps/miniprogram/docs/nomadro_wx_props_batch_upload.xlsx b/apps/miniprogram/docs/nomadro_wx_props_batch_upload.xlsx index 3498cee..b0062b5 100644 Binary files a/apps/miniprogram/docs/nomadro_wx_props_batch_upload.xlsx and b/apps/miniprogram/docs/nomadro_wx_props_batch_upload.xlsx differ diff --git a/apps/miniprogram/docs/wechat-virtual-pay-props.md b/apps/miniprogram/docs/wechat-virtual-pay-props.md index 1653b43..8040e5a 100644 --- a/apps/miniprogram/docs/wechat-virtual-pay-props.md +++ b/apps/miniprogram/docs/wechat-virtual-pay-props.md @@ -12,8 +12,6 @@ SoT 代码:`apps/api/services/ebook_svc/domains/books/products.py` | 现网 AppKey | `JUN15h8sl5sNQt0awMSrd4Jpv1aSGOYY` | | 沙箱 AppKey | `BQ1DlPjq3PIEzV4UwXQrKxLtqAqlmAEi` | -环境变量(`apps/api` / `.env`): - ```env WX_APPID=wx11f6afc44ea1532f WX_SECRET=… @@ -23,59 +21,47 @@ WX_SANDBOX_APP_KEY=BQ1DlPjq3PIEzV4UwXQrKxLtqAqlmAEi WX_PAY_ENV=0 ``` -微信后台路径:**支付与交易 → 虚拟支付 → 道具管理**(须与下表 `product_id` / 价格一致后再发版)。 +微信后台:**支付与交易 → 虚拟支付 → 道具管理**(`productId` / 价格须与下表一致后再发版)。 -## 道具目录(Nomadro 小程序) +## 运营货架(给用户付费看的) -| key | 道具 ID (`productId`) | 价格 | 试读% | 图 | 说明 | +| key | 道具 ID | 名称(≤10) | 价格 | 图 | 备注 / 上架 | |---|---|---|---|---|---| -| `free` | (空) | 免费 | 100 | — | 不拉起支付 | -| `tiktok` | `tiktok` | ¥88(8800 分) | 30 | `props/tiktok.png` | 已发布 | -| `youtube` | `youtube` | ¥188(18800 分) | 30 | `props/youtube.png` | 默认付费方案 | -| `nomad` | `nomad` | ¥49(4900 分) | 30 | `props/nomad.png` | 已发布 | -| `svip` | `svip` | ¥998(99800 分) | 30 | `props/svip.png` | 已发布 | -| `yen29` | `29` | ¥29(2900 分) | 30 | `props/29.png` | 新方案 | -| `yen298` | `298` | ¥298(29800 分) | 30 | `props/298.png` | 新方案 | -| `yen588` | `588` | ¥588(58800 分) | 30 | `props/588.png` | 新方案 | -| `ebook` | `ebook_unlock_default` | ¥188(18800 分) | 30 | `props/ebook.png` | 旧默认道具 | -| `test` | `test` | ¥1(100 分) | 30 | `props/test.png` | 联调;须在 MP 发布 | +| `free` | — | 免费全书 | 免费 | — | 不拉起支付 | +| `yen29` | `nomad_lite` | 轻享全书 | ¥29 | `nomad_lite.png` | 入门 · 可上架 | +| `nomad` | `nomad` | 漫游全书 | ¥49 | `nomad.png` | **主推** | +| `tiktok` | `tiktok` | 短视频全书 | ¥88 | `tiktok.png` | 可上架 | +| `youtube` | `youtube` | 长视频全书 | ¥188 | `youtube.png` | **默认推荐** | +| `ebook` | `ebook_unlock_default` | 经典全书 | ¥188 | `ebook.png` | 兼容旧单 | +| `yen298` | `nomad_plus` | 进阶全书 | ¥298 | `nomad_plus.png` | 可上架 | +| `yen588` | `nomad_pro` | 精英全书 | ¥588 | `nomad_pro.png` | 可上架 | +| `svip` | `svip` | 超级会员 | ¥998 | `svip.png` | 旗舰 | +| `test` | `pay_test` | 联调占位 | ¥1 | `pay_test.png` | **勿对用户发布** | -后台图标目录:`apps/admin/public/props/`。 +图标目录:`apps/admin/public/props/`。 +遗留草稿 id:`29`/`298`/`588`/`test` → 映射到上表;勿再发布旧草稿。 -遗留数字 ID 映射(旧订单兼容):`298→tiktok`、`188→youtube`、`49→nomad`、`998→svip`。 +## 微信批量上传 -## 调用链 +固定目录:[`wx-props-batch/`](wx-props-batch/) -1. 小程序下单 → `POST /pay/...`(`apps/api` ebook_svc) -2. 服务端用 OfferID + `productId` + 价格生成 `signData` / `paySig` -3. 端上 `wx.requestVirtualPayment` -4. 发货 / 查单走 `/xpay/*`,签名用当前环境 AppKey - -## 微信后台批量上传 - -**项目内固定目录(下次直接用):** [`wx-props-batch/`](wx-props-batch/) -- 现用表:`wx-props-batch/nomadro_wx_props_batch_upload.xlsx` -- 微信示例:`wx-props-batch/example_batch_add_product.xlsx` - -生成脚本:`apps/miniprogram/scripts/gen_wx_props_batch_xlsx.py` +```bash +python apps/miniprogram/scripts/gen_wx_prop_icons.py +python apps/miniprogram/scripts/gen_wx_props_batch_xlsx.py +``` | 列 | 要求 | |---|---| -| 道具id | 必填,≤32 位英文 | -| 道具名称 | 必填,≤10 字 | -| 道具图片 | 必填,HTTPS 链接;PNG/JPG;200×200;≤200KB;**须允许 CORS** | -| 道具价格 | 必填,整数元,≤10000 | -| 备注 | 选填,≤50 字、不对外展示 | +| 道具id | ≤32 英文;语义化 SKU | +| 道具名称 | ≤10 字;**用户可见货架名** | +| 道具图片 | HTTPS;PNG/JPG;200×200;≤200KB;CORS | +| 道具价格 | 整数元 | +| 备注 | ≤50;运营内部说明,不对外 | -单次最多 200 条;xlsx ≤3MB。 - -当前图片 CDN:`https://admin.nomadro.cn/props/{id}.png` -已对 `https://mp.weixin.qq.com` 放开 CORS(`Access-Control-Allow-Origin`)。 - -本仓库已填 9 个付费道具:`tiktok` / `youtube` / `nomad` / `svip` / `29` / `298` / `588` / `ebook_unlock_default` / `test`。 +图片 CDN:`https://admin.nomadro.cn/props/{file}.png`(已对 `mp.weixin.qq.com` 放 CORS)。 ## 验收 -- 开发者工具:`WX_PAY_ENV=1` 用沙箱 AppKey -- 真机现网:`WX_PAY_ENV=0`,道具已在 MP「发布」且价格与上表一致 +- 沙箱:`WX_PAY_ENV=1` +- 现网:道具已「发布」、价格与上表一致;`pay_test` 保持未发布 - 路径:登录 → 下单 → `requestVirtualPayment` → 发货回调 diff --git a/apps/miniprogram/docs/wx-props-batch/README.md b/apps/miniprogram/docs/wx-props-batch/README.md index 00e71db..bae3f29 100644 --- a/apps/miniprogram/docs/wx-props-batch/README.md +++ b/apps/miniprogram/docs/wx-props-batch/README.md @@ -1,23 +1,34 @@ -# 微信虚拟支付 · 批量上传道具 +# 微信虚拟支付 · 批量上传道具(运营货架) -下次在微信后台「批量创建道具」直接用本目录文件。 +面向**付费用户**的货架文案,不是开发草稿。微信后台「批量创建道具」直接用本目录文件。 | 文件 | 用途 | |---|---| -| `nomadro_wx_props_batch_upload.xlsx` | **现用上传表**(含 29/298/588 等) | -| `example_batch_add_product.xlsx` | 微信官方示例格式参考 | +| `nomadro_wx_props_batch_upload.xlsx` | **现用上传表** | +| `example_batch_add_product.xlsx` | 微信官方示例格式 | + +## 货架(按价位) + +| 道具id | 道具名称 | 价格 | 备注说明 | 上架建议 | +|---|---|---|---|---| +| `nomad_lite` | 轻享全书 | ¥29 | 入门价·首次解锁单本推荐 | 可上架 | +| `nomad` | 漫游全书 | ¥49 | 标准漫游档·性价比主推 | **主推** | +| `tiktok` | 短视频全书 | ¥88 | 短视频向专题全书 | 可上架 | +| `youtube` | 长视频全书 | ¥188 | 长视频向·默认推荐档 | **默认档** | +| `ebook_unlock_default` | 经典全书 | ¥188 | 历史默认档·兼容旧订单 | 兼容保留 | +| `nomad_plus` | 进阶全书 | ¥298 | 进阶价·高价值小册 | 可上架 | +| `nomad_pro` | 精英全书 | ¥588 | 精英价·深度专题册 | 可上架 | +| `svip` | 超级会员 | ¥998 | 旗舰会员·最高权益档 | 旗舰 | +| `pay_test` | 联调占位 | ¥1 | 仅内部联调·禁止对用户上架 | **勿发布** | + +旧草稿 id(`29` / `298` / `588` / `test`)勿再发布;后端已映射到新 id。 ## 重新生成 ```bash +python apps/miniprogram/scripts/gen_wx_prop_icons.py python apps/miniprogram/scripts/gen_wx_props_batch_xlsx.py ``` -会写入: - -- `apps/miniprogram/docs/wx-props-batch/nomadro_wx_props_batch_upload.xlsx` -- `apps/miniprogram/docs/nomadro_wx_props_batch_upload.xlsx`(短路径副本) -- 桌面同名文件(可选方便) - -道具图 SoT:`apps/admin/public/props/` → 线上 `https://admin.nomadro.cn/props/`(已 CORS)。 -目录与账号说明:[`../wechat-virtual-pay-props.md`](../wechat-virtual-pay-props.md)。 +道具图 SoT:`apps/admin/public/props/` → `https://admin.nomadro.cn/props/`(CORS 已开)。 +账号与验收:[`../wechat-virtual-pay-props.md`](../wechat-virtual-pay-props.md)。 diff --git a/apps/miniprogram/docs/wx-props-batch/nomadro_wx_props_batch_upload.xlsx b/apps/miniprogram/docs/wx-props-batch/nomadro_wx_props_batch_upload.xlsx index a852ee8..dfdb64b 100644 Binary files a/apps/miniprogram/docs/wx-props-batch/nomadro_wx_props_batch_upload.xlsx and b/apps/miniprogram/docs/wx-props-batch/nomadro_wx_props_batch_upload.xlsx differ diff --git a/apps/miniprogram/scripts/gen_wx_prop_icons.py b/apps/miniprogram/scripts/gen_wx_prop_icons.py new file mode 100644 index 0000000..dbb2a80 --- /dev/null +++ b/apps/miniprogram/scripts/gen_wx_prop_icons.py @@ -0,0 +1,243 @@ +# -*- coding: utf-8 -*- +"""运营向微信道具图标:200×200 PNG,深色精品档,价签清晰。""" +from __future__ import annotations + +import math +from pathlib import Path + +from PIL import Image, ImageDraw, ImageFilter, ImageFont + +OUT = Path(__file__).resolve().parents[2] / "admin" / "public" / "props" +SIZE = 512 # 先画高清再缩到 200 +FINAL = 200 + + +def font(size: int, bold: bool = True) -> ImageFont.FreeTypeFont: + path = r"C:\Windows\Fonts\msyhbd.ttc" if bold else r"C:\Windows\Fonts\msyh.ttc" + try: + return ImageFont.truetype(path, size, index=0) + except OSError: + return ImageFont.truetype(r"C:\Windows\Fonts\arialbd.ttf", size) + + +def round_rect(draw: ImageDraw.ImageDraw, box, radius: int, fill) -> None: + draw.rounded_rectangle(box, radius=radius, fill=fill) + + +def radial_glow(base: Image.Image, color: tuple[int, int, int], cx: int, cy: int, r: int, alpha: int = 120) -> None: + overlay = Image.new("RGBA", base.size, (0, 0, 0, 0)) + px = overlay.load() + w, h = base.size + for y in range(h): + for x in range(w): + d = math.hypot(x - cx, y - cy) / r + if d >= 1: + continue + a = int(alpha * (1 - d) ** 2) + px[x, y] = (*color, a) + base.alpha_composite(overlay) + + +def draw_open_book(draw: ImageDraw.ImageDraw, cx: int, cy: int, scale: float, cover, page, glow) -> None: + w = int(150 * scale) + h = int(110 * scale) + # glow blob + draw.ellipse([cx - w // 2 - 20, cy - h // 2 - 10, cx + w // 2 + 20, cy + h // 2 + 30], fill=glow) + # left cover + draw.polygon( + [ + (cx - w // 2, cy - h // 2 + 8), + (cx - 6, cy - h // 2), + (cx - 6, cy + h // 2), + (cx - w // 2, cy + h // 2 - 8), + ], + fill=cover, + ) + # right cover + draw.polygon( + [ + (cx + 6, cy - h // 2), + (cx + w // 2, cy - h // 2 + 8), + (cx + w // 2, cy + h // 2 - 8), + (cx + 6, cy + h // 2), + ], + fill=cover, + ) + # pages + draw.polygon( + [ + (cx - w // 2 + 10, cy - h // 2 + 14), + (cx - 8, cy - h // 2 + 6), + (cx - 8, cy + h // 2 - 10), + (cx - w // 2 + 10, cy + h // 2 - 16), + ], + fill=page, + ) + draw.polygon( + [ + (cx + 8, cy - h // 2 + 6), + (cx + w // 2 - 10, cy - h // 2 + 14), + (cx + w // 2 - 10, cy + h // 2 - 16), + (cx + 8, cy + h // 2 - 10), + ], + fill=page, + ) + # spine light + draw.line([(cx, cy - h // 2 + 4), (cx, cy + h // 2 - 4)], fill=(255, 255, 255, 90), width=3) + + +def price_badge(img: Image.Image, text: str, accent: tuple[int, int, int]) -> None: + draw = ImageDraw.Draw(img) + f = font(56, bold=True) + tw, th = draw.textbbox((0, 0), text, font=f)[2:] + bw, bh = tw + 72, th + 28 + bx = (SIZE - bw) // 2 + by = SIZE - 118 + # soft shadow + shadow = Image.new("RGBA", img.size, (0, 0, 0, 0)) + sd = ImageDraw.Draw(shadow) + round_rect(sd, [bx + 4, by + 6, bx + bw + 4, by + bh + 6], 28, (0, 0, 0, 110)) + img.alpha_composite(shadow.filter(ImageFilter.GaussianBlur(6))) + draw = ImageDraw.Draw(img) + # plaque + round_rect(draw, [bx, by, bx + bw, by + bh], 28, (245, 236, 214, 255)) + # accent tips + draw.ellipse([bx - 6, by + bh // 2 - 8, bx + 10, by + bh // 2 + 8], fill=accent) + draw.ellipse([bx + bw - 10, by + bh // 2 - 8, bx + bw + 6, by + bh // 2 + 8], fill=accent) + draw.text((bx + (bw - tw) // 2, by + (bh - th) // 2 - 4), text, font=f, fill=(28, 24, 20, 255)) + + +def frame(img: Image.Image, color: tuple[int, int, int, int], width: int = 10) -> None: + draw = ImageDraw.Draw(img) + draw.rounded_rectangle([6, 6, SIZE - 7, SIZE - 7], radius=96, outline=color, width=width) + + +def make_icon( + filename: str, + price: str, + bg_top: tuple[int, int, int], + bg_bot: tuple[int, int, int], + glow: tuple[int, int, int], + cover: tuple[int, int, int], + accent: tuple[int, int, int], + motif: str = "book", +) -> Path: + img = Image.new("RGBA", (SIZE, SIZE), (0, 0, 0, 0)) + # rounded background gradient + canvas = Image.new("RGBA", (SIZE, SIZE), (0, 0, 0, 0)) + for y in range(SIZE): + t = y / (SIZE - 1) + r = int(bg_top[0] * (1 - t) + bg_bot[0] * t) + g = int(bg_top[1] * (1 - t) + bg_bot[1] * t) + b = int(bg_top[2] * (1 - t) + bg_bot[2] * t) + ImageDraw.Draw(canvas).line([(0, y), (SIZE, y)], fill=(r, g, b, 255)) + mask = Image.new("L", (SIZE, SIZE), 0) + ImageDraw.Draw(mask).rounded_rectangle([0, 0, SIZE - 1, SIZE - 1], radius=108, fill=255) + bg = Image.new("RGBA", (SIZE, SIZE), (0, 0, 0, 0)) + bg.paste(canvas, mask=mask) + img.alpha_composite(bg) + + radial_glow(img, glow, SIZE // 2, SIZE // 2 - 40, 220, 140) + draw = ImageDraw.Draw(img) + + if motif == "book": + draw_open_book(draw, SIZE // 2, SIZE // 2 - 36, 1.35, (*cover, 255), (248, 244, 235, 255), (*glow, 55)) + # tiny sparkles + for sx, sy in [(120, 140), (390, 160), (150, 300), (370, 290)]: + draw.ellipse([sx, sy, sx + 6, sy + 6], fill=(255, 255, 255, 160)) + elif motif == "note": + # music note / short video + cx, cy = SIZE // 2, SIZE // 2 - 40 + draw.ellipse([cx - 70, cy - 20, cx + 10, cy + 50], fill=(20, 20, 24, 255), outline=(255, 255, 255, 230), width=8) + draw.rectangle([cx + 2, cy - 110, cx + 18, cy + 20], fill=(255, 255, 255, 230)) + draw.polygon([(cx + 18, cy - 110), (cx + 70, cy - 90), (cx + 18, cy - 70)], fill=(255, 80, 120, 255)) + radial_glow(img, (255, 80, 140), cx, cy, 160, 90) + elif motif == "play": + cx, cy = SIZE // 2, SIZE // 2 - 40 + draw.rounded_rectangle([cx - 90, cy - 60, cx + 90, cy + 60], radius=28, outline=(255, 60, 70, 255), width=14) + draw.polygon([(cx - 28, cy - 40), (cx - 28, cy + 40), (cx + 48, cy)], fill=(255, 60, 70, 255)) + radial_glow(img, (255, 60, 70), cx, cy, 150, 100) + elif motif == "crown": + draw_open_book(draw, SIZE // 2, SIZE // 2 - 10, 1.2, (*cover, 255), (252, 248, 235, 255), (*glow, 50)) + # crown + cx, cy = SIZE // 2, 150 + pts = [(cx - 70, cy + 30), (cx - 55, cy - 25), (cx - 25, cy + 10), (cx, cy - 40), (cx + 25, cy + 10), (cx + 55, cy - 25), (cx + 70, cy + 30)] + draw.polygon(pts, fill=(232, 184, 74, 255)) + draw.ellipse([cx - 10, cy - 52, cx + 10, cy - 32], fill=(255, 220, 120, 255)) + radial_glow(img, (255, 200, 80), cx, cy, 120, 110) + elif motif == "wrench": + cx, cy = SIZE // 2, SIZE // 2 - 30 + draw.rounded_rectangle([cx - 18, cy - 90, cx + 18, cy + 70], radius=10, fill=(80, 200, 120, 255)) + draw.ellipse([cx - 55, cy - 55, cx + 55, cy + 55], outline=(80, 200, 120, 255), width=18) + draw.ellipse([cx - 22, cy - 22, cx + 22, cy + 22], fill=(12, 28, 18, 255)) + + price_badge(img, price, accent) + frame(img, (*accent, 200), 8) + + out = img.resize((FINAL, FINAL), Image.Resampling.LANCZOS) + OUT.mkdir(parents=True, exist_ok=True) + path = OUT / filename + out.save(path, "PNG", optimize=True) + print("wrote", path, path.stat().st_size) + return path + + +def main() -> None: + # 入门 ¥29 — 青绿漫游 + make_icon( + "nomad_lite.png", + "29", + (8, 28, 36), + (18, 70, 72), + (255, 170, 80), + (20, 90, 88), + (245, 158, 11), + "book", + ) + # 进阶 ¥298 — 紫金 + make_icon( + "nomad_plus.png", + "298", + (18, 8, 36), + (58, 28, 92), + (180, 120, 255), + (40, 20, 70), + (232, 184, 74), + "book", + ) + # 精英 ¥588 — 深海蓝金 + make_icon( + "nomad_pro.png", + "588", + (6, 14, 36), + (20, 48, 90), + (255, 180, 70), + (16, 40, 78), + (245, 158, 11), + "book", + ) + # 联调占位 ¥1 — 绿,明确非卖品观感 + make_icon( + "pay_test.png", + "1", + (10, 28, 18), + (20, 60, 36), + (80, 220, 140), + (30, 90, 50), + (80, 200, 120), + "wrench", + ) + # 兼容旧文件名(已上传过丑图的 id)也覆盖一份精品图,方便微信侧改图 + for src, dst in [ + ("nomad_lite.png", "29.png"), + ("nomad_plus.png", "298.png"), + ("nomad_pro.png", "588.png"), + ("pay_test.png", "test.png"), + ]: + data = (OUT / src).read_bytes() + (OUT / dst).write_bytes(data) + print("mirror", dst) + + +if __name__ == "__main__": + main() diff --git a/apps/miniprogram/scripts/gen_wx_props_batch_xlsx.py b/apps/miniprogram/scripts/gen_wx_props_batch_xlsx.py index 86426ce..3ec41bb 100644 --- a/apps/miniprogram/scripts/gen_wx_props_batch_xlsx.py +++ b/apps/miniprogram/scripts/gen_wx_props_batch_xlsx.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -"""Generate WeChat MP virtual-pay batch props xlsx (example_batch_add_product format).""" +"""生成微信虚拟支付「批量创建道具」xlsx(运营货架文案)。""" from __future__ import annotations from pathlib import Path @@ -7,28 +7,28 @@ from pathlib import Path import openpyxl from openpyxl.styles import Alignment, Font -# SoT: apps/api/.../products.py (paid only) -# 价格单位:元(整数);图片须可被 mp.weixin.qq.com CORS 拉取 +# 图片须可被 mp.weixin.qq.com CORS 拉取;名称≤10字;备注≤50且不对外 IMG_BASE = "https://admin.nomadro.cn/props" +# 按价位从低到高:给用户看的货架,不是开发草稿 ROWS = [ - # (道具id, 道具名称≤10字, 图片URL, 价格元, 备注≤50) - ("tiktok", "tiktok", f"{IMG_BASE}/tiktok.png", 88, "已发布方案 · 试读30%"), - ("youtube", "youtube", f"{IMG_BASE}/youtube.png", 188, "默认付费方案 · 试读30%"), - ("nomad", "nomad", f"{IMG_BASE}/nomad.png", 49, "已发布方案 · 试读30%"), - ("svip", "svip", f"{IMG_BASE}/svip.png", 998, "已发布方案 · 试读30%"), - ("29", "29", f"{IMG_BASE}/29.png", 29, "新方案 · ¥29 · 试读30%"), - ("298", "298", f"{IMG_BASE}/298.png", 298, "新方案 · ¥298 · 试读30%"), - ("588", "588", f"{IMG_BASE}/588.png", 588, "新方案 · ¥588 · 试读30%"), - ("ebook_unlock_default", "ebook", f"{IMG_BASE}/ebook.png", 188, "旧默认道具 · 试读30%"), - ("test", "test", f"{IMG_BASE}/test.png", 1, "联调测试道具 · ¥1"), + # (道具id, 道具名称, 图片URL, 价格元, 备注说明) + ("nomad_lite", "轻享全书", f"{IMG_BASE}/nomad_lite.png", 29, "入门价·首次解锁单本推荐"), + ("nomad", "漫游全书", f"{IMG_BASE}/nomad.png", 49, "标准漫游档·性价比主推"), + ("tiktok", "短视频全书", f"{IMG_BASE}/tiktok.png", 88, "短视频向专题全书"), + ("youtube", "长视频全书", f"{IMG_BASE}/youtube.png", 188, "长视频向·默认推荐档"), + ("ebook_unlock_default", "经典全书", f"{IMG_BASE}/ebook.png", 188, "历史默认档·兼容旧订单"), + ("nomad_plus", "进阶全书", f"{IMG_BASE}/nomad_plus.png", 298, "进阶价·高价值小册"), + ("nomad_pro", "精英全书", f"{IMG_BASE}/nomad_pro.png", 588, "精英价·深度专题册"), + ("svip", "超级会员", f"{IMG_BASE}/svip.png", 998, "旗舰会员·最高权益档"), + ("pay_test", "联调占位", f"{IMG_BASE}/pay_test.png", 1, "仅内部联调·禁止对用户上架"), ] _DOCS = Path(__file__).resolve().parents[1] / "docs" OUT_DIRS = [ - _DOCS / "wx-props-batch", # 项目内固定目录(下次直接用) - _DOCS, # 短路径副本 - Path(r"c:\Users\Administrator\Desktop"), # 桌面方便上传 + _DOCS / "wx-props-batch", + _DOCS, + Path(r"c:\Users\Administrator\Desktop"), ] @@ -36,6 +36,7 @@ def main() -> None: wb = openpyxl.Workbook() ws = wb.active ws.title = "Sheet1" + # 微信模板列名以官方 example 为准(道具价格 / 备注) headers = ["道具id", "道具名称", "道具图片", "道具价格", "备注"] ws.append(headers) for cell in ws[1]: @@ -43,10 +44,9 @@ def main() -> None: cell.alignment = Alignment(wrap_text=True) for row in ROWS: - # validate pid, name, url, price, remark = row - assert len(pid) <= 32 and pid.isascii() and pid.replace("_", "").isalnum() - assert len(name) <= 10 + assert len(pid) <= 32 and pid.isascii() and all(c.isalnum() or c == "_" for c in pid) + assert 1 <= len(name) <= 10 assert url.lower().endswith((".png", ".jpg", ".jpeg")) assert isinstance(price, int) and 1 <= price <= 10000 assert len(remark) <= 50 @@ -56,7 +56,7 @@ def main() -> None: ws.column_dimensions["B"].width = 14 ws.column_dimensions["C"].width = 56 ws.column_dimensions["D"].width = 12 - ws.column_dimensions["E"].width = 28 + ws.column_dimensions["E"].width = 32 name = "nomadro_wx_props_batch_upload.xlsx" for d in OUT_DIRS: