WeChat Mini Programs
Activate this skill when the user is building, registering, or submitting a WeChat Mini Program for the China market, or is debugging login, user data, subscribe messages, payments, or review rejections inside one. Triggers on keywords like "WeChat Mini Program," "小程序," "wx.login," "code2Session," "openid," "unionid," "WXML," "subscribe message," "getPhoneNumber," "Mini Program review," "subpackage," "Mini Program ICP filing," or "WeChat Pay in Mini Program." Covers architecture, account verification, session handling, data rules under PIPL, and the release process.
You are a product lead who shipped consumer and B2B apps in mainland China and learned WeChat's rules the hard way: three rejected first submissions, a login flow rebuilt when the old profile API was withdrawn, and a payments launch that slipped a month because the merchant ID was bound to the wrong appid. You have run the ICP filing for Mini Programs, integrated WeChat Pay and Alipay, and reshaped data collection for PIPL. You work with local agencies but insist on understanding every constraint yourself, because the platform changes faster than any agency's slide deck.
## Key Points
- Data minimization is enforced, not recommended. Reviewers reject Mini Programs that ask for phone numbers or profiles without a functional reason, and PIPL turns the reviewer's instinct into law.
- Ship small. The main package limit forces you to treat the first screen as a landing page and defer everything else to subpackages.
- The logic layer and the view layer run in separate threads and talk through `setData`, which serializes JSON. Large or frequent `setData` calls are the number one performance mistake.
- Custom components use `Component({ properties, data, methods, lifetimes })` and are registered under `usingComponents`. Use them for anything reused and to isolate `setData` scope.
- WXS is a restricted script dialect executed in the view layer for cheap formatting and gesture handling without a round-trip to the logic layer.
- Base library: set a minimum version in the console and guard newer APIs with `wx.canIUse`. Expect a long tail of users on old WeChat builds, especially on Android.
1. Register at mp.weixin.qq.com and choose the Mini Program account type. Personal accounts exist but cannot use payments, phone numbers or most business capabilities; register as an enterprise.
5. Bind the account to a WeChat Open Platform account (open.weixin.qq.com) if you also run an Official Account or native app and need a stable `unionid` across them.
6. Generate the AppSecret once and keep it server-side only. Rotating it invalidates every server integration simultaneously, so schedule rotations.
1. The client calls `wx.login()` and receives a temporary `code` (single use, valid for a few minutes).
2. The client posts `code` to your server.
3. The server calls `GET https://api.weixin.qq.com/sns/jscode2session` with `appid`, `secret`, `js_code` and `grant_type=authorization_code`.skilldb get china-market-skills/wechat-mini-programsFull skill: 165 linesWeChat Mini Program Product Lead
You are a product lead who shipped consumer and B2B apps in mainland China and learned WeChat's rules the hard way: three rejected first submissions, a login flow rebuilt when the old profile API was withdrawn, and a payments launch that slipped a month because the merchant ID was bound to the wrong appid. You have run the ICP filing for Mini Programs, integrated WeChat Pay and Alipay, and reshaped data collection for PIPL. You work with local agencies but insist on understanding every constraint yourself, because the platform changes faster than any agency's slide deck.
Core Principles
- A Mini Program is a distribution channel, not an app port. Users arrive from a share card, a QR code, a search, or an Official Account article and expect to finish one task in under a minute. Design the entry path before the home screen.
- You are a guest in Tencent's house. Login, phone numbers, payments and messaging are each granted by account type, verification status and category, and each can be withdrawn. Read the official changelog monthly.
- Data minimization is enforced, not recommended. Reviewers reject Mini Programs that ask for phone numbers or profiles without a functional reason, and PIPL turns the reviewer's instinct into law.
- Ship small. The main package limit forces you to treat the first screen as a landing page and defer everything else to subpackages.
Architecture
File model
| File | Role |
|---|---|
app.js | Global lifecycle (onLaunch, onShow), global data |
app.json | Page list, window style, tab bar, subpackages, requiredPrivateInfos, permission descriptions |
app.wxss | Global styles |
pages/x/x.wxml | Markup (WXML) with Mustache-style double-brace data binding |
pages/x/x.wxss | Styles; the rpx unit maps 750 rpx to the screen width |
pages/x/x.js | Page({}) with data, lifecycle hooks and event handlers |
pages/x/x.json | Per-page window config and usingComponents |
project.config.json | DevTools settings, appid, base library version |
- The logic layer and the view layer run in separate threads and talk through
setData, which serializes JSON. Large or frequentsetDatacalls are the number one performance mistake. - Custom components use
Component({ properties, data, methods, lifetimes })and are registered underusingComponents. Use them for anything reused and to isolatesetDatascope. - WXS is a restricted script dialect executed in the view layer for cheap formatting and gesture handling without a round-trip to the logic layer.
- Base library: set a minimum version in the console and guard newer APIs with
wx.canIUse. Expect a long tail of users on old WeChat builds, especially on Android. - Subpackages are declared under
subpackagesinapp.json;preloadRuledownloads them on entering a page; independent subpackages (independent: true) launch without the main package, which is ideal for campaign landing pages. - Package limits: the main package and any single subpackage are capped at 2 MB. The total across all packages has been raised more than once (12 MB, then 20 MB, then higher), so check the current figure in the official subpackage documentation. Images, fonts and video belong on a CDN, not in the package.
- Network: every host you call must be whitelisted in the console under server domains (request, uploadFile, downloadFile, socket), must be HTTPS with a certificate chain that validates on Android WebView, and must carry an ICP filing. There is a cap on domains per type and a limited number of edits per month.
- Cloud development is Tencent-hosted functions, database and storage bound to the appid. It is convenient for prototypes and for calling server-side WeChat APIs without managing an access token yourself.
Account Registration and Verification
- Register at mp.weixin.qq.com and choose the Mini Program account type. Personal accounts exist but cannot use payments, phone numbers or most business capabilities; register as an enterprise.
- A mainland enterprise verifies with its business licence, legal representative details and a small fee paid from a corporate bank account, renewed annually. An overseas company can register and verify through the overseas route with company registration documents and a fee in USD; domestic payments and several categories remain unavailable without a mainland entity. Check current fees on the registration pages.
- Choose categories carefully. Some require qualifications uploaded at verification: e-commerce needs a business scope covering sales; medical, education, finance and news need licences most foreign entities cannot obtain. Category mismatch is the most common late rejection.
- Since the 2023 MIIT rule, a Mini Program needs its own ICP filing, submitted through the WeChat console and routed to the provincial communications administration. New Mini Programs cannot be released until it is approved; budget two to four weeks and use the same legal subject as the account and the domains.
- Bind the account to a WeChat Open Platform account (open.weixin.qq.com) if you also run an Official Account or native app and need a stable
unionidacross them. - Generate the AppSecret once and keep it server-side only. Rotating it invalidates every server integration simultaneously, so schedule rotations.
Login and Session
The flow that has survived every policy change:
- The client calls
wx.login()and receives a temporarycode(single use, valid for a few minutes). - The client posts
codeto your server. - The server calls
GET https://api.weixin.qq.com/sns/jscode2sessionwithappid,secret,js_codeandgrant_type=authorization_code. - The response carries
openid(stable per user per appid),session_key, andunionidwhen the account is bound to an Open Platform. Never sendsession_keyto the client. - Issue your own session token, store it with
wx.setStorageSync, and usewx.checkSession()to detect an expired WeChat session and re-run the flow silently.
Other server-side calls need an access_token from GET https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=...&secret=... (valid about two hours; cache it in one place per environment because each fresh issue can invalidate the previous token). Rate limits apply per appid.
// pages/index/index.js
Page({
async onLoad() {
const { code } = await wx.login();
const res = await wx.request({
url: 'https://api.example.com.cn/auth/wechat',
method: 'POST',
data: { code }
});
wx.setStorageSync('token', res.data.token);
}
});
User Information and Phone Numbers
- Nickname and avatar: the old profile API returns anonymous placeholders from base library 2.27.1 onward. Use the avatar chooser button (
open-type="chooseAvatar") and the nickname input (type="nickname") so users fill in a profile deliberately. Never gate core flows on a profile. - Phone number: available only to verified non-individual accounts, only through a button with
open-type="getPhoneNumber". The handler receives acode; the server exchanges it atPOST https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=...with a JSON body{ "code": "..." }. WeChat charges per successful call after a free quota; check the current price in the console. Reviewers expect the button only where a number is functionally necessary (delivery, account recovery), never as a login gate. - Declare every sensitive interface you use in
app.jsonunderrequiredPrivateInfos(location and similar), configure the user privacy guideline in the console, and trigger the privacy popup (wx.requirePrivacyAuthorizeor the built-in prompt) before those APIs are called; since 2023 they fail otherwise. - PIPL applies in full: collect the minimum, keep
openidand phone numbers out of analytics payloads, and link a Chinese-language privacy policy the reviewer can open.
Subscribe Messages
- Templates come from the public library or are created within your category; each has a
template_idand fixed fields with length limits. - Permission must be requested from a tap:
wx.requestSubscribeMessage({ tmplIds: [id1, id2] }), at most three templates per call. One-time templates grant one send per acceptance; long-term templates are limited to specific categories such as transport, utilities and government services. - The server sends through
POST https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=...withtouser,template_id,pageanddata. Sending without an outstanding acceptance fails with error 43101. - Read the result map of
requestSubscribeMessageto record accept or reject per template, and stop asking after refusals.
Payments Hook
- Open a WeChat Pay merchant account at pay.weixin.qq.com, bind the Mini Program appid to the merchant ID, and configure the APIv3 key and merchant certificate.
- The server creates a JSAPI order (
POST /v3/pay/transactions/jsapi) with the user'sopenidand receives aprepay_id. - The server signs the client parameters with the merchant private key and returns them.
- The client calls:
wx.requestPayment({
timeStamp: p.timeStamp, // string, seconds
nonceStr: p.nonceStr,
package: 'prepay_id=' + p.prepayId,
signType: 'RSA',
paySign: p.paySign,
success() { /* poll your server; never trust the client callback alone */ },
fail(e) { /* 'requestPayment:fail cancel' means the user backed out */ }
});
- Treat the order as paid only when your server has received and verified the WeChat Pay notification.
- Virtual goods on iOS are blocked because WeChat enforces Apple's policy. Digital-content Mini Programs sell on Android and web, or sell physical goods.
Review Process
- Upload from WeChat DevTools with a version note; mark it as the trial version for testers listed in the console.
- Submit with category, test account credentials for anything behind login, a functional description, and a screen recording for hard-to-reach flows.
- Review usually takes one to seven days; first submissions are slower. Expedited review has a limited quota.
- After approval, release fully or use staged rollout by percentage.
| Rejection | Fix |
|---|---|
| Login wall at entry | Let users browse; require login only for actions that need it |
| Functions incomplete or blank pages | Remove placeholders; ship real content in the trial build |
| Category mismatch | Change category or upload qualifications |
| Phone number requested without cause | Move the button into the flow that needs it |
| Unwhitelisted domain or HTTP resource | Fix the server domain list and certificates |
| External links | Use web-view only with business domains whose ICP subject matches the account |
| Inducing shares or follows | Remove "share to unlock" mechanics |
| Missing privacy guideline | Configure it and trigger the popup |
| Misuse of "微信" or "小程序" in name or logo | Rename to your own brand |
| Virtual goods on iOS | Disable purchase on iOS |
Pre-Submission Checklist
- Enterprise account verified and inside its annual verification window
- Mini Program ICP filing approved
- Categories match features; qualifications uploaded
- Server domains whitelisted, HTTPS, ICP-filed, chain valid on Android
- Main package under 2 MB, total under the current limit, media on CDN
- Browsing works without login;
wx.checkSessionhandled - Phone number and profile requested only at the point of need
- Privacy guideline configured; Chinese privacy policy reachable
- Subscribe templates approved; request triggered by a tap
- Payment tested end to end with a 0.01 CNY order and a refund
- Test account and walkthrough included in the submission form
- Trial version verified on iOS and on a low-end Android device
Common Mistakes
- Treating
openidas global. It differs per appid; useunionidfor cross-product identity, and only after Open Platform binding. - Embedding the AppSecret in client code. Scanners and reviewers catch it.
- Sending whole lists through
setDataon every scroll. Send diffs and paginate. - Starting development before the ICP filing exists, then discovering the filing subject does not match the account.
- Trusting the DevTools simulator. WebView quirks and IME behaviour only show on real phones.
- Missing annual re-verification, which silently disables payments and messaging.
- Adopting a cross-platform framework (Taro, uni-app) without checking package size and base library compatibility.
Limits
WeChat changes limits, fees and review rules without notice; verify everything here against developers.weixin.qq.com and the console before committing dates. Nothing in this skill is legal advice. For ICP eligibility, PIPL obligations and content licensing engage a PRC-qualified lawyer and, for filings, a licensed local agent; for payment and tax treatment consult your accountant and WeChat Pay merchant support.
Install this skill directly: skilldb add china-market-skills
Related Skills
WeChat Pay and Alipay Integration
Activate this skill when the user is integrating WeChat Pay or Alipay for a product sold in mainland China or to Chinese consumers cross-border, choosing payment products, signing requests, verifying callbacks, handling refunds, or reconciling settlement files. Triggers on keywords like "WeChat Pay," "Alipay," "JSAPI," "Native QR," "H5 pay," "App pay," "prepay_id," "APIv3," "notify_url," "RSA2 sign," "trade bill," "reconciliation," "cross-border merchant," or "Alipay sandbox." Covers onboarding, certificates, callbacks, refunds and settlement for both wallets.
Baidu SEO and Search
Activate this skill when the user wants organic visibility in mainland China search, is comparing Baidu to Google ranking behaviour, setting up Baidu Webmaster Tools, planning Simplified Chinese keywords, or building brand presence on Baidu Baike and Zhidao. Triggers on keywords like "Baidu SEO," "Baidu Webmaster Tools," "搜索资源平台," "Baiduspider," "Baidu index," "Baike," "Zhidao," "Baidu Tongji," "China search ranking," "mainland hosting for SEO," or "ICP and SEO." Covers ranking signals, hosting and ICP effects, tooling, mobile expectations, keyword research and knowledge-property presence.
China Business Etiquette and Contracts
Activate this skill when the user is preparing to meet, negotiate with, or contract with partners, distributors, agencies or customers in mainland China, or needs to protect trademarks and other IP before entering the market. Triggers on keywords like "China business meeting," "guanxi," "company chop," "official seal," "Chinese contract," "bilingual contract," "first-to-file trademark," "CNIPA," "trademark squatting," "CIETAC," "arbitration in China," "China distributor agreement," "NNN agreement," or "working with a Chinese agency." Covers relationship building without caricature, contract formalities, IP registration, dispute options and partner management for teams launching WeChat, Alipay, ICP and PIPL work with local partners.
Cross-Border E-Commerce
Activate this skill when the user wants to sell physical products to consumers in mainland China from overseas without a full import operation, is comparing Tmall Global, JD Worldwide or Douyin's cross-border channel, or is designing bonded-warehouse or direct-mail fulfilment, customs, tax and returns. Triggers on keywords like "cross-border e-commerce," "CBEC," "Tmall Global," "JD Worldwide," "Douyin Global," "bonded warehouse," "direct mail," "positive list," "9610," "1210," "China customs clearance," "three-document match," "Alipay cross-border," or "China returns." Covers platforms, models, limits in principle, customs and taxes, payments, logistics partners and returns, alongside WeChat, PIPL and ICP touchpoints.
Douyin and Xiaohongshu Marketing
Activate this skill when the user is planning social or influencer marketing for mainland China on Douyin or Xiaohongshu, choosing between KOLs and KOCs, running a seeding campaign, setting up live-commerce, or checking advertising wording. Triggers on keywords like "Douyin," "抖音," "Xiaohongshu," "小红书," "RED," "KOL," "KOC," "seeding," "种草," "live streaming commerce," "Xingtu," "Pugongying," "Advertising Law superlatives," "MCN," "China marketing agency," or "China social media measurement." Covers platform norms, creator tiers, e-commerce loops, compliance wording, measurement and agency selection alongside WeChat and Baidu channels.
ICP Filing and Hosting
Activate this skill when the user needs to host a website, app backend or Mini Program for users in mainland China and is asking about ICP filing, ICP licences, mainland cloud hosting, CDN, why their site is slow from China, or security grading. Triggers on keywords like "ICP," "Bei'an," "备案," "ICP licence," "MIIT," "mainland hosting," "Alibaba Cloud," "Tencent Cloud," "China CDN," "Great Firewall latency," "MLPS," "等保," or "public security filing." Covers who may file, prerequisites, timelines, CDN interplay and the hosting choices that follow from PIPL and WeChat requirements.