Everything about WeChat Subscription Message
So Far…
In the past, I wrote about template messages for WeChat Mini-Program.
In this article, I will attempt to cover broader spectrum of WeChat on this “new” subscription message. It’s new until they decide to change again.
Current Rule
One-time subscription message is the official translation for WeChat’s subscription message service.
However, the name is a bit misleading. It can seem like the user only have to subscribe once then the developer can send them an endless number of messages.
A one-time subscription message means one permission acquired from the user is only good for one message.
After you send the message, you will need to acquire the user’s permission again.
The following special business categories are an exception:
Governmental, Medical, Transportation, Finance, Education
Where to get Permission?
For Mini-Program:
User interaction is required to trigger the permission prompt.
Notes:
- You can request permissions for three different template messages at the same time
- If the user taps on “Don’t Ask Again”, the permission prompt won’t appear again for the user. However, for developers, we still need to trigger `wx.requestSubscribeMessage`
- Doc: https://developers.weixin.qq.com/miniprogram/dev/api/open-api/subscribe-message/wx.requestSubscribeMessage.html
For WeChat Official Account:
A user tap on a special link in a WeChat Official Account article.
Steps:
- Add subscribe message as a plugin in the official account dashboard
- Create template
- Add a link to the article when writing an article in the official account
Doc: https://developers.weixin.qq.com/doc/offiaccount/Subscription_Messages/intro.html
For Website opened within WeChat:
Through WeChat JSSDK, a permission prompt is triggered when the user tap on something on a website.
Steps:
- Setup WeChat JSSDK
- Use special weixin tag, example below
<wx-open-subscribe template="TenvU22BA1jCp4YHfYEpRuESXYReQyDuhs4vbdWA99I" id="subscribe-btn">
<template slot="style">
<style>
.subscribe-btn {
color: #fff;
background-color: #07c160;
}
</style>
</template>
<template>
<button class="subscribe-btn">
一次性模版消息订阅
</button>
</template>
</wx-open-subscribe>
<script>
var btn = document.getElementById('subscribe-btn');
btn.addEventListener('success', function (e) {
console.log('success', e.detail);
});
btn.addEventListener('error',function (e) {
console.log('fail', e.detail);
});
</script>
Doc: https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_Open_Tag.html#23
For Native App:
Through WeChat iOS or Android SDK, user jumps to WeChat to give permission.
Steps:
- Setup WeChat SDK with your iOS or Android app
- Trigger permission request on app
Doc: https://developers.weixin.qq.com/doc/oplatform/Mobile_App/One-time_subscription_info.html
How to send a message?
Here’s the part that is a bit troublesome. Depending on where you got the permission from, the API endpoint call to send the message is different.
Mini-Program
POST https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=ACCESS_TOKEN
Official Account/Website
POST https://api.weixin.qq.com/cgi-bin/message/subscribe/bizsend?access_token=ACCESS_TOKEN
Native App
POST https://api.weixin.qq.com/cgi-bin/message/template/subscribe?access_token=ACCESS_TOKEN
Doc: https://developers.weixin.qq.com/doc/oplatform/Mobile_App/One-time_subscription_info.html
Where do users get messages?
For Mini-Program and Native App, the message will appear in “Service Message”.
For WeChat Official Account or Website with JSSDK, it will appear in the Official Account’s conversation box if the user has already subscribed to the Official Account. Otherwise, it will fall into “Service Message” as well.
Conclusion
If you want to learn more about WeChat-related development, click here.