Business scene:

When a user uses a certain service in the WeChat applet, such as purchase, reservation and other services, after the user's reservation is successful, a message reminder that the reservation is successful is pushed to the user.

picture

  • Step 1: Get the template ID

To subscribe a message push template, you need to apply for it in the WeChat applet background, log in to the WeChat applet management background and go to the [Functions] under the [Subscribe News] menu. You can select a message template similar to your own business type in the public template library. The message types are divided into One-time subscription messages, long-term subscription messages, and device subscription messages. At present, long-term subscription news is only open to offline public services such as government affairs and people's livelihood, medical care, transportation, finance, education, etc., so most businesses can only choose one-time subscription news. I also use one-time subscription news here .

Compared with the one-time subscription message, the user needs to pop up a query box after clicking to place an order. After clicking Allow, they can get a push opportunity. If the user clicks not to allow the push, even if the push is initiated, the user will not receive the message. Then after the message is pushed successfully, this opportunity will be used up. If you need to push again, you need to pop up the message push confirmation box again. The good side of WeChat doing this is to avoid users being pushed spam by some small program messages.

  • Step 2: Obtain the distribution permission

I use uni-app for development here, so just call the method provided by uni-app directly. Before calling the order method, call the uni.requestSubscribeMessage({ tmplIds: [''], success (res) { }}) method, and pass in the set of template IDs applied for, and then write the business code in the success callback.

  • Step 3: Call the API to send the subscription message

Message push interface: api.weixin.qq.com/cgi-bin/mes…

After the user places an order, request the WeChat applet to send the subscription message interface, and pass in the parameters: openId (WeChat applet user openid), templateId (subscription message template id), page (click the WeChat applet page to jump to the message, No configuration), data (parameters displayed on the subscription message page).

picture

Mini Program Subscription News

Author: Su Yu style
Link: https://juejin.cn/post/7124951993873317896