WeChat Official Account and Mini Program Development Workflow

Prerequisites

  1. Register for both a WeChat Official Account and a Mini Program. Official documentation covers the registration steps in detail.
  2. Bind the Official Account to the Mini Program. This binding is required for message push functionality.

Mini Program Development Process

  1. Register the Mini Program at https://mp.weixin.qq.com/cgi-bin/wx.
  2. To enable WeChat message push, register and log in to the WeChat Official Account development platform, then add the Mini Program (requires a 300 RMB payment). URL: https://mp.weixin.qq.com/cgi-bin/home.
  3. Obtain the Mini Program's appid and secret from the Mini Program backend management page.
  4. All interactions with WeChat require HTTPS. Use a domain name with a proper SSL certificate (e.g., configure it under Nginx). The Mini Program backend must expose a public port.
  5. For message push, the Mini Program must be bound to an Official Account. Also add the server IP to the IP whitelist; otherwise, you cannot obtain an access token.
  6. For image upload, use a dedicated image server and return the image URL to the frontend. When using Nginx, adjust the client_max_body_size directive (e.g., 20M) to allow larger uploads.
  7. The Mini Program package size must not exceed 2 MB. Store static resources such as images on an external static server.
  8. To test the Mini Program in experience version, add developers in the WeChat management backend. When logging in, enable development debugging (via the three-dot menu in the top-right corner). The experience version requires the backend service to be on the same local network for access.
  9. For Mini Program release, submit an audit for review (first review may take up to 3 days or more; subsequent reviews usually take about 1 day). Before going live, add the IP whitelist for token retrieval on the WeChat Official Account platform and ensure the backend service has public network access.

Official Account Development Process

This section focuses on message push using the Official Account.

WeChat API Documentation

  • Official Account interface permissions (admin required): https://mp.weixin.qq.com/advanced/advanced?action=table&token=396006949&lang=zh_CN
  • Official Account development documentation: https://developers.weixin.qq.com/doc/offiaccount/Getting_Started/Overview.html

Message Push Workflow

WeChat template message interface: https://developers.weixin.qq.com/doc/offiaccount/Message_Management/Template_Message_Interface.html

Prerequisites for Message Push

To associate users between the Mini Program and the Official Account, you need the unionid. This requires binding both the Mini Program and Official Account to the same WeChat Open Platform. Key concepts:

  • openid: Unique identifier for a user within a specific Mini Program or Official Account. Different for each application. Similar to a UUID.
  • unionid: Common identifier across Mini Programs and Official Accounts under the same WeChat Open Platform. Obtain via https://api.weixin.qq.com/sns/jscode2session, but the user must have used both the Mini Program and followed the Official Account (requires binding: Official Account, Mini Program, Open Platform).
  • appid: Unique identifier for the Mini Program or Official Account itself.
  • secret: Developer password for verifying identity. Keep it secure; do not store in code or share with third parties.

Step-by-Step Push Process

  1. User follows Official Account: Obtain the user's openid and unionid for the Official Account.

    1. Get the Offficial Account access token: https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=SECRET
    2. Get the list of followers (openids). First request does not require next_openid: https://api.weixin.qq.com/cgi-bin/user/get?access_token=TOKEN&next_openid=APPID
    3. Get unionid for a user (single or batch):
      • Single: GET https://api.weixin.qq.com/cgi-bin/user/info?access_token=ACCESS_TOKEN&openid=OPENID&lang=zh_CN
      • Batch: POST https://api.weixin.qq.com/cgi-bin/user/info/batchget?access_token=ACCESS_TOKEN
  2. User uses Mini Program: Obtain the user's openid and unionid for the Mini Program.

    1. Get the Mini Program access token (same endpoint as Official Account, but with different appid/secret): https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=SECRET
    2. Get session_key, openid, and unionid. The code comes from the frontend after login: https://api.weixin.qq.com/sns/jscode2session?appid=APPID&js_code=CODE&grant_type=authorization_code
  3. Associate using unionid and send template message:

    • Use the unionid to link the user across platforms, then send a template message. Construct a JSON payload containing the user's openid, template ID (available from the Official Account template management page), and template data.
    • Endpoint: POST https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=ACCESS_TOKEN

Flow Diagram

(A simple diagram of the process can be included here.)

Tags: WeChat mini program Official Account Message Push Development Workflow

Posted on Mon, 21 Sep 2026 16:12:36 +0000 by kashmirekat