Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize template message reply developed by Wechat

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly shows you "how to achieve template message reply in Wechat development". The content is simple and clear. I hope it can help you solve your doubts. Let the editor lead you to study and learn this article "how to achieve template message reply in Wechat development".

On Wechat public platform, there is a template message reply interface: it can be used to reply to specific messages-for example, after the user has placed an order, reply to the user that your order is being processed. For example, the following picture:

After the user has done something, the service number can return a specific message-this is the template message.

To achieve the reply of the template message, your official account must be verified by Wechat. If it is a personal Subscription account, Wechat authentication is not supported for the time being. But it doesn't affect doing the test-you can use the test official account:

When using the test number, the configuration of the interface information will not be discussed, you can refer to my previous blog.

After logging in to the test number using the dimension code, you need to use your WeChat account to follow the test number, otherwise you will not see the reply of the template message.

When I was doing the test, I used a plug-in in chrome browser: postman. The plug-in can specify to send various HTTP requests such as GET,POST. It is powerful and useful when testing the interface.

1. Send GET request to get access_token: https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid= of test number, your test number appID&secret=, your test number appsecret

2. Set the industry to which you belong:

Send a POST request with parameters:

Request: https://api.weixin.qq.com/cgi-bin/template/api_set_industry?access_token= the access_token you just got

Parameters:

{"industry_id1": "1", "industry_id2": "2"}

1 and 2 in the parameters indicate the industry to which they belong. For specific industries, please refer to the document: http://mp.weixin.qq.com/wiki/12/bd383158b0f8435c07b8b6bc7cdbac9c.html

You can send specific post requests using curl, which should not be difficult. I use postman to send. A successful json message is returned after sending it, and then you can proceed to the next step.

3, get the template ID: you can customize this piece, or you can use some built-in Wechat.

For example, use a custom template ID: there is a "new test template" in your test number.

After submitting, you can see that your template ID appears:

Then another way to generate a template ID is to send a post request (can be sent by curl or by postman)

Request: https://api.weixin.qq.com/cgi-bin/template/api_add_template?access_token=ACCESS_TOKEN

Parameters:

{"template_id_short": "TM00015"}

The TM00015 is the ID of Wechat's built-in template, which you can find in the graphical interface of https://mp.weixin.qq.com (Wechat certification is required)

4. After obtaining the template ID, refresh your test number page, and you can see that it appears:

5. Use the template_id_short you got and send a post request to get a msgid:

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

Data sent:

{"touser": "openId of the follower of the test number", "template_id": "the template ID you just got", "url": "the link that the follower jumps when the follower clicks on your template message", "data": {"first": {"value": "Congratulations on your successful purchase!" , "color": "# 173177"}, "orderMoneySum": {"value": "666", "color": "# 173177"}, "orderProductName": {"value": "Men's formal dress", "color": "# 173177"} "Remark": {"value": "Welcome to buy again!" , "color": "# 173177"}}

Color indicates the color of the fields in your template

There is no description of the above parameters in the official document. I wrote down the meaning of each field in Chinese. It should be noted that touser is not the "WeChat account" of the follower on the Wechat client, but the WeChat account in the following figure.

After sending the parameters in post, you get a msgid:

When you get this successful response, your test official account should also return a template message to you (follower).

The above is all the contents of the article "how to achieve template message reply in Wechat Development". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report