从零快速搭建一个微信小程序(后端用微信云开发/CloudBase)的脚手架与方法论:单函数 REST 路由、幂等建号/幂等建集合、实时统计、订阅消息+定时触发器、全生命周期坑。Scaffold & methodology for building a WeChat Mini Program on WeChat CloudBase: single-function REST routing, idempotent user/collection seeding, real-time stats, subscribe messages + scheduled triggers, full-lifecycle pitfalls. Use when: 做一个云开发小程序 / 从零搭小程序 / 小程序 MVP / building a WeChat Mini Program MVP. Deployment details → wechat-miniprogram-cloudbase-deploy skill.
Data & analysis
WeChat MiniProgram CloudBase Deploy
Try itWeChat Mini Program deployment onto WeChat CloudBase (云开发): deploy cloud functions via tcb, manually create database collections in the console, and upload the frontend via miniprogram-ci. Covers real-environment pitfalls: CLI cannot create collections, tcb fn invoke returns a Namespace metadata bug, the upload IP-whitelist only accepts IPv4 (so an IPv6 egress is always rejected), and the trial env defaults to ap-shanghai. Trigger when the task involves 部署微信小程序, 云开发, CloudBase, tcb 部署云函数, or miniprogram-ci 上传.
What it does
WeChat Mini Program deployment onto WeChat CloudBase (云开发): deploy cloud functions via tcb, manually create database collections in the console, and upload the frontend via miniprogram-ci. Covers real-environment pitfalls: CLI cannot create collections, tcb fn invoke returns a Namespace metadata bug, the upload IP-whitelist only accepts IPv4 (so an IPv6 egress is always rejected), and the trial env defaults to ap-shanghai. Trigger when the task involves 部署微信小程序, 云开发, CloudBase, tcb 部署云函数, or miniprogram-ci 上传.
The skill document
微信小程序云开发部署
This skill documents the end-to-end deployment of a WeChat Mini Program whose
backend runs on WeChat CloudBase (云开发), including cloud functions (tcb),
the NoSQL database (collections), and the miniprogram frontend upload
(miniprogram-ci).
When to use
- Deploying a Mini Program whose backend is (or will be) WeChat CloudBase.
- Migrating a self-hosted Express/SQLite backend to cloud functions + cloud DB.
- Uploading the miniprogram frontend to produce a 体验版 / 开发版.
- Diagnosing deploy failures:
collection not exists,GetFunction Namespace,errCode -10008 invalid ip.
Prerequisites (must be collected from the user first)
| Item | How the user obtains it | Why |
|---|---|---|
| Real AppID | MP backend → 开发 → 开发管理 → 开发设置 | touristappid cannot use CloudBase |
| Env ID | WeChat DevTools → 云开发 button → 环境设置 → 环境 ID (system-generated, looks like xxx-4g1a2b3c) | Target env for tcb deploy |
| Subscribe template ID | MP backend → 功能 → 订阅消息 → 我的模板 | For daily push dailyPush |
Upload private key (.key) | MP backend → 开发设置 → 小程序代码上传密钥 → 生成/下载 | Required by miniprogram-ci. Never paste key content into chat — use a local file path only. |
Never ask the user to paste secret key contents. Read the path from disk.
Deployment workflow
-
Install CloudBase CLI into the managed node workspace (avoid polluting the user's global env):
cd ~/.workbuddy/binaries/node/workspace npm install @cloudbase/cli@latestThe
tcbbinary lives atnode_modules/@cloudbase/cli/bin/tcb. -
tcb login— runs a device-code OAuth flow. Launch in background, scrape the authorization URL from/tmp/tcb-login.log, ask the user to open it and approve (confirm the shownuser_code). -
Deploy cloud functions:
tcb fn deploy 函数名 --force -r ap-shanghaiDeploy
api,login,seed,dailyPush(or whatever the project defines).wx-server-sdkis installed in the cloud automatically. (Or runscripts/deploy-cloud.shto batch-deploy all functions + seed in one command.) -
Create the 7 collections in the CloudBase console (see Pitfall 1 — CLI cannot do this). Then invoke
seedonce:tcb fn invoke seed -r ap-shanghaiVerify with
tcb db nosql execute --command '[...find gangs...]' -r ap-shanghai. -
Upload the frontend with
scripts/upload.jsfrom this skill (parameterized via env vars). See Pitfall 3 for the IP-whitelist trap.
Critical pitfalls (detailed in references/pitfalls.md)
- Pitfall 1 — Collections must be created in the console.
tcb db createwas removed in CLI v3.8.1;tcb api tcb CreateCollectionis offline;tcb db nosql executeINSERT writes to a different MongoDB instance invisible towx-server-sdk; SDK.add()does NOT auto-create collections. Build aseedfunction that idempotently ensures collections + seed data. - Pitfall 2 —
tcb fn invokereturnsGetFunction Namespace取值与规范不符for most functions (butseedsucceeds). This is a CLI metadata bug in the CloudBase-namespace resolution; it does NOT affect the realwx.cloud.callFunctionpath. End-to-end verification must happen in WeChat DevTools, not viatcb fn invoke. - Pitfall 3 — Upload IP whitelist only accepts IPv4. If the egress is IPv6
(common when traffic routes through a local proxy like
127.0.0.1:xxxx), the error iserrCode -10008 invalid ip: 该IPv6地址. Whitelist UI cannot accept IPv6, so the only fix is to turn off the whitelist toggle in MP backend, or switch the machine to an IPv4 egress. - Pitfall 4 —
zshPIPESTATUSgotcha. When chainingnode ... | tail,${PIPESTATUS[0]}is misread in zsh; a non-zero exit can be masked as 0. Prefer the JS API (ci.upload) which returns a structured error object. - Pitfall 5 — Trial env is
ap-shanghai. Always pass-r ap-shanghaitotcbcommands;fn list/env listwork without it, butinvoke/deployneed the region.
Post-deploy, manual (compliance) actions only the user can do
| # | Action | Location |
|---|---|---|
| 1 | Fill 隐私保护指引 | MP backend → 设置 → 用户隐私保护指引 (required for review) |
| 2 | Create unique indexes | CloudBase console → 数据库 → 索引管理: checkins{openid:1,date:1}, gang_memberships{openid:1,gangId:1} |
| 3 | Verify subscribe field names | dailyPush/index.js thing1/time2 must match the template's keyword order |
| 4 | Submit review → release | MP backend → 版本管理 (the only externally-visible, irreversible step) |
Note: uploading produces a 体验版 only — real users cannot see it. Review + release is a separate, human-only action.
Related skills
This skill provides battle-tested guidance for integrating WeChat Mini Program payment and refund flows using Tencent CloudBase. It covers cloud.cloudPay.unifiedOrder() for payments, cloud.cloudPay.refund() for refunds, cloud functions, deployment via CLI, and a catalog of critical pitfalls with fix
Fast path for a minimal CloudBase Web + database demo (最小前后端 / 最小可用 fullstack / Lovable-like BaaS). Defaults to @cloudbase/js-sdk client CRUD (NoSQL app.database / PG app.rdb), MCP-only schema, preview-first, and forbids cloud functions unless secrets, cron/background jobs, or logic that security rules/RLS cannot express. Use for 搭一套 demo、留言板、Todo、Notes、Kanban, or when users say 带云函数+云数据库 but only need CRUD. NOT for production multi-service backends, CloudRun, WeChat Mini Programs, or tasks that truly need server secrets.
CloudBase WeChat integration guide for Mini Program WeChat Pay, Mini Program virtual payment (虚拟支付, wx.requestVirtualPayment), Official Account JSAPI Pay, Native QR-code Pay, Official Account OAuth, openid handling, payment callbacks, and CloudBase Integration Center generated functions. This skill should be used when users ask to add, debug, or extend WeChat payment, virtual payment, or official-account flows on CloudBase.
Route CloudBase scenarios to the right child skill and enforce the prep-then-implement-then-review workflow.
One-click deploy, publish, and update a local project or Git repository to Alibaba Cloud International (alibabacloud.com), producing an accessible online service with a public IP. Supports full-stack ROS orchestration, automatic cloud-resource provisioning, pre-deployment price confirmation, service