WeChat Mini Program API Template Message


Based on WeChat’s notification channel, we provide developers with template messaging capabilities that can efficiently reach users, in order to achieve a closed-loop service and provide a better experience.

Template push location: Service notification

Template delivery conditions: Triggered after the user interacts with the page in the WeChat system. For details, please see the delivery condition description

Template Jump ability: Clicking to view details can only jump to each page of the account where the template is issued

Instructions


  1. Get the template id

Log in to https://mp.weixin.qq.com to obtain the template. If there is no suitable template, you can apply to add a new template. It can be used after passing the review. For details, please see the template review instructions

201609261354219112.png

  1. The <form/> component of the page, when the attribute report-submit is true, can be declared as You need to send a template message. At this time, click the button to submit the form to get formId, which is used to send the template message. Or when the user completes the payment behavior, he can obtain prepay_id for sending template messages.

  2. Call the interface to deliver template messages (see interface description for details)

Interface description


1. Get access_token

access_token is a globally unique interface calling credential. Developers need to use access_token when calling each interface. Please keep it properly. At least 512 characters of space must be reserved for access_token storage. The validity period of access_token is currently 2 hours and needs to be refreshed regularly. Repeated acquisition will cause the last access_token to become invalid.

Instructions on the use and generation of access_token required for API calls on the public platform:

  1. In order to keep appsecrect secret, the third party needs a central control server to obtain and refresh the access_token. The access_token used by other business logic servers comes from the central control server and should not be refreshed individually, otherwise the access_token will be overwritten and affect the business;
  2. The current validity period of the access_token is conveyed through the returned expire_in. Currently It is the value within 7200 seconds. The central control server needs to refresh the new access_token in advance according to this valid time. During the refresh process, the central control server still outputs the old access_token. At this time, the public platform backend will ensure that both the old and new access_token are available within a short time of refresh, which ensures the smooth transition of third-party services;
  3. The validity time of access_token may be adjusted in the future, so the central control server not only needs to actively refresh internally at regular intervals, but also needs to provide an interface for passively refreshing access_token, so that the business server can trigger access_token when the API call learns that access_token has timed out. refresh process.

Developers can use AppID and AppSecret to call this interface to obtain access_token. AppID and AppSecret can be obtained by logging into the WeChat official website - Settings - Development Settings (you need to be bound to become a developer, and the account has no abnormal status). Please save the AppSecret yourself after it is generated, because every time it is generated and viewed on the public platform, the AppSecret will be reset. Note that the https protocol must be used when calling all WeChat interfaces. If the third party does not use the central control server, but chooses each business logic point to refresh the access_token separately, conflicts may occur, leading to service instability.

Interface address:

https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET

HTTP request method:

GET

Parameter description:

QQ截图20170208152001.png

Return parameter description:

Under normal circumstances, WeChat will return the following JSON data packet to the developer :

{"access_token":"ACCESS_TOKEN","expires_in":7200}

QQ截图20170208152013.png

When an error occurs, WeChat will return error code and other information. The JSON data packet example is as follows (this example is an invalid AppID error):

{"errcode":40013,"errmsg":"invalid appid"}

2. Send template message

Interface address: (ACCESS_TOKEN needs to be replaced with the access_token obtained above)

https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=ACCESS_TOKEN

HTTP request method:

POST

POST parameter description:

QQ截图20170208152030.png

##Example:

{
  "touser": "OPENID",  
  "template_id": "TEMPLATE_ID", 
  "page": "index",          
  "form_id": "FORMID",         
  "data": {
      "keyword1": {
          "value": "339208499", 
          "color": "#173177"
      }, 
      "keyword2": {
          "value": "2015年01月05日 12:30", 
          "color": "#173177"
      }, 
      "keyword3": {
          "value": "粤海喜来登酒店", 
          "color": "#173177"
      } , 
      "keyword4": {
          "value": "广州市天河区天河路208号", 
          "color": "#173177"
      } 
  },
  "emphasis_keyword": "keyword1.DATA" 
}

Return code description:

After calling the template message interface, a JSON data packet will be returned.

Example of returning JSON data packet when normal:

{  "errcode":0,  "errmsg":"ok",
}

In case of error, error code information will be returned, the description is as follows:

##40037template_id is incorrect41028form_id is incorrect or expired41029form_id has been used41030page is incorrect

Usage effect:

201609261355055576.png

Note: During the internal testing phase, after the template message is issued, the client can only see the A simple notification issued by the "Official Account Security Assistant". If you receive this prompt, it means that the template message function has been debugged successfully. After this function is officially launched, it will be displayed as shown in the picture above.

Issue condition description

  1. Payment

    When the user completes the payment behavior in the mini program, the developer can be allowed to issue the payment to the user in the mini program. Push a limited number of template messages within 7 days (one message can be sent for one payment, and the number of messages sent for multiple payments is independent and does not affect each other)

  2. Submit form

    When a user submits a form in a mini program and the form is declared to send template messages, and the developer needs to provide services to the user, the developer can be allowed to push a limited number of template messages to the user within 7 days ( One form submission can be issued once, and the number of entries issued for multiple submissions is independent and does not affect each other)

Audit Instructions


1.Title

1.1 Titles cannot be the same

1.2 Titles cannot be overly similar in meaning

1.3 Titles must end with "reminder" or "notification"

1.4 Titles cannot Content with special symbols, personalized words, etc. that has no industry commonality

1.5 The title must reflect the specific service scenario

1.6 The title cannot involve marketing-related content, including but not limited to:

Consumer discounts, shopping rebates, product updates, coupons, vouchers, red envelopes, membership cards, points, activities and other marketing trend notifications

2.Keywords

2.1 Under the same title, the keywords cannot be the same

2.2 Under the same title, the keywords cannot be overly similar

2.3 Keywords cannot have special symbols or personalized words Wait for content that is not industry-wide

2.4 Keyword content examples must match the keywords

2.5 Keywords cannot be too broad and need to be restrictive, for example: "content" Too broad to pass the review

Violation Description


In addition to not violating the operating specifications, the following rules may not be violated, including but not limited to:

  1. It is not allowed to maliciously induce users to perform triggering operations in order to achieve the purpose of delivering templates to users
  2. Malicious harassment is not allowed, and templates that cause harassment to users are not allowed to be distributed
  3. Malicious marketing is not allowed, and templates are distributed Marketing purpose template
  4. It is not allowed to issue templates through service accounts to inform users of service-related content triggered within the mini program

Penalty instructions


According to Violations will be punished with corresponding gradients. The general penalty rules are as follows:

For the first violation, the violation template will be deleted as a warning;

For the second violation, the interface will be banned for 7 days.

For the third violation, the interface will be banned for 30 days.

For the fourth violation, the interface will be permanently banned.

The punishment results and reasons will be informed in the form of an internal letter

Return codeDescription