Uni-app WeChat applet subscription message function development (process explanation)

Tips

" Template Message " is discarded in WeChat Mini Program , and WeChat Mini Program Template Message

scenes to be used

First of all, we need to understand the usage scenarios of WeChat subscription messages . For example, when a customer orders a Meituan takeaway, customers need to know whether the current order is received by the merchant, or whether the order is delivered, or when the order is scheduled to be picked up while queuing, etc., when the customer’s appointment is successful Or the merchant needs to inform the customer after receiving the order, it is best to use the subscription message at this time.

Precautions

Subscription message push location: service notification
Subscription message delivery condition: user self-subscribes
subscription message card jump ability: click to view details to jump to the page of the applet

There are two types of subscription messages:

One-time subscription news

The one-time subscription message is used to solve the notification problem of the follow-up service link after the user uses the mini program. After the user subscribes independently, the developer can send a corresponding service message without time limit; each message can be subscribed or unsubscribed separately. ( Special note: One-time subscription is the vernacular that the customer clicks "subscribe" once, and only one subscription message will be received. When you want to send 5 messages to the customer, the premise is that the customer has clicked 5 times )

Long-term subscription news (individual developers basically refuse this, so many people complain about the decision to discard template messages)

One-time subscription messages can meet the needs of most service scenarios of the mini program, but there are scenarios in the offline public service field that cannot be met by one-time subscription, such as flight delays, which need to send multiple message reminders based on the real-time flight status. For the convenience of service, we provide a long-term subscription message. After the user subscribes once, the developer can send multiple messages for a long time.

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. , and will gradually support other offline public service businesses in the future

Example ---- Take a one-time subscription as an example

Meituan is often used, so I’ll take Meituan’s applet as an example. When a customer places an order, the client’s applet subscription message interface will be called up. At this time, the customer will be prompted which news they want to subscribe to, such as There are " rider order notification ", " order delivery notification " and so on. If the customer subscribes to these messages, there will be one in the customer's WeChat " service notification " (there are two in the picture because they subscribed to two messages ).
Insert picture description here

Development Process

1: Open the WeChat public platform and log in to the background of your mini program.
2: Click "Subscribe News" in the "Function" category.
3: Select the template you need in the public template library and select it. After you select it, you can see your template in "My Template".

Insert picture description here
4: At this point, you can start to write the code, call (uni-app development call: uni.requestSubscribeMessage-----WeChat development call: wx.requestSubscribeMessage) method to start the client applet subscription message interface
Insert picture description here
front end call. It has been completed, because it is only a single description of the function, so the code is relatively simple. It’s important to note that when you pull up the authorization interface, there is a check box " Always keep the above selections " at the bottom . After checking, it means that the customer will not pop up the message subscription interface when subscribing to the message next time. It does not mean that the customer will be in the future. You can always receive messages, and you can only receive long-term subscriptions .

The next step is for the server to call the interface to issue a subscription message

Server code

1: Get access_token
Insert picture description here

2: Call the server api ---- forward pass
https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=ACCESS_TOKEN

Interface parameter description:
Insert picture description here
The one thing to note here is the value of data , you need to go to the background and click on the details to view in your template.

At this point, the overall process is complete. Because the function is relatively simple, and the convenient development code on hand has also been deleted, so the code is slightly simple, in fact, these methods such as getsetting should be added to make the customer experience better.

At this point, many people actually want to ask what should I do if I need to send messages to customers all the time. I can't achieve long-term subscription of messages, and the applet template message is also abandoned. What should I do?

Method 1: When the user clicks on the subscription message, the customer is repeatedly prompted to click on the subscription message, and tell him the truth. I will push you a few times after you click the message. Anyway, look at it. If you click the message, the message is not delivered. Don’t blame me. ( Purpose : Disgusting customers, and then let customers report Tencent's mentally handicapped practices).

Method 2: When you don't want to choose method one (you just don't dare), you can use the "unified service message" provided by WeChat to implement it. The next article explains.

Guess you like

Origin blog.csdn.net/q457201373/article/details/114121892