Update: Template Message for WeChat Mini-Program

David Yu
David Yu
Nov 25, 2019 · 4 min read
Image for post
Image for post
Photo by Thought Catalog on Unsplash

In the past, I wrote an article about how to send template message for WeChat Mini-Program:

https://medium.com/china-software-development/how-to-send-template-message-for-wechat-mini-program-856dbc4af7cc

Unfortunately, Tencent announced that they deprecate this way of sending a template message on January 10th, 2020.

Image for post
Image for post
https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/template-message/templateMessage.send.html

What has changed?

Image for post
Image for post

2. No more Form ID or Prepay ID is needed

Which means a message is not bound to a button or payment anymore.

3. One permission for one message except for the following industry:

Governmental, Medical, Transportation, Finance, Education

How to implement it?

Add Template in Mini-Program Dashboard

Image for post
Image for post
Image for post
Image for post

4. Select the keyword you wish to include in the template

Image for post
Image for post

5. Return to “My template” in the subscription message

6. Open the detail

Image for post
Image for post

7. Copy template id and take note of the keyword

8. Take note of the keywords

Image for post
Image for post

Note: Unlike the previous template message method, the variable key is not always “keyword” and number, but something like “name1” or “time2”, etc.

Mini-Program Code

wx.requestSubscribeMessage({
tmplIds: [''],
success (res) { }
})

So no more formId is needed, you only need to pass in the template id which you need permission for.

Note: You can pass multiple template IDs. The users can check or uncheck the message they want to receive.

For the response, you will receive either “accept”, “reject”, “ban” for each of the template ids.

Backend Code

Here’s an example in NodeJS

// Send messageconst message = { "touser": "OPEN_ID_OF_RECEIVING_USER", "template_id": "TEMPLATE_ID", "page": "/pages/index/index", "data": { "name1": {  "value": "Class Name" }, "time2": {  "value": "2015年01月05日" }, "thing3": {  "value": "TIT创意园" } , "thing4": {  "value": "comment" } }};const response = await axios.post(`https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=${access_token}`, message);

Result

If you’re not in one of those special industry categories mentioned above, then for one permission, you will be able to send one message.

Image for post
Image for post

Links

Official Doc: https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/subscribe-message.html

MP Code Example(Frontend):

https://github.com/davidyu37/wechat-mp-template-message-frontend

Backend Example:

Userland

You can control which message you wish to receive by going into the setting of the Mini-Program.

Image for post
Image for post
Image for post
Image for post
Image for post
Image for post

Conclusion

If you’re new to WeChat related development, here’s a free glossary for you to get up to speed.

Shanghai Coders

Sharing software development required in China

David Yu

Written by

David Yu

Software Freelancer based in Shanghai. More articles at https://shanghaicoders.com Work with me: https://davidyu37.github.io/

Shanghai Coders

Sharing software development required in China

David Yu

Written by

David Yu

Software Freelancer based in Shanghai. More articles at https://shanghaicoders.com Work with me: https://davidyu37.github.io/

Shanghai Coders

Sharing software development required in China

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store