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

Example Analysis of Wechat official account Development template message

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

Share

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

The editor would like to share with you an example analysis of Wechat official account development template messages. I believe most people don't know much about it, so share this article for your reference. I hope you will learn a lot after reading this article. Let's take a look at it!

How to check if you have permission

In the communication group, someone always asks whether the individual Subscription account, the certified Subscription account, the service number and the authenticated service number have permission to use an interface.

In fact, the problem is very simple. In [Wechat Public platform], you can now directly view your official account and use those interfaces.

Log in to [Wechat Public platform] to go to the home page > Development > API permissions.

Template message-permission .png

Add template message plug-in

Note that it must be the certified service number.

Log in to [Wechat Public platform] to go to the home page, add plug-in function, find the template message and follow the instructions.

Template message interface usage rules

Official document sending message-template message interface and template message operation specification

With regard to the rules of use, please note:

1. All service numbers can see the entry of the application template message function at function-> add function plug-in, but only the authenticated service number can apply for and obtain the permission to use the template message.

2. You need to select the two industries in which the public account service is located, and you can change the selected industry once a month.

3. Select the existing template in the template library of the selected industry to call.

4. Each account can use 25 templates at the same time.

5. Currently, the maximum number of daily calls to template messages for each account is 100000. There is no special limit for a single template. [increase the frequency of API calls from the default 10,000 times per day to 100000 times per day on November 18, 2014, which can be viewed in the developer Center after logging in to MP]. When the number of fans of the account exceeds 10W/100W/1000W, the daily call limit of template messages will be raised accordingly, subject to the number indicated in the developer center page of the official MP backend.

Add template message

After adding the template message plug-in as above, the template message menu will appear in the left column of the home page of [Wechat Public platform], where you need to agree to the agreement and set up the public account service.

If the above settings are set up, you can check the existing templates in the template library through keywords, and you can apply for them if you don't find them.

Template message-add template. png

Find the appropriate template message, click on the details, go in and view the template details, if you need to add them. After adding the template ID, which will generate template messages in my template, the template ID will be used later.

Template message-template details. Png

Test number add template message

Test number add template message .png

Test number add template message .png

The use of template message interface

Objective front is some preparatory work, bring a cup of tea patiently look down. Let's take a practical look at how the encapsulated interfaces in open source projects are used.

Com.javen.weixin.controller.WeixinMsgController.java

Use of template messages .png

Notification received

Encapsulation of template messages

The official reference document specifically implements com.jfinal.weixin.sdk.api.TemplateMsgApi.java.

Public class TemplateMsgApi {private static String sendApiUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="; / * send template message * @ param jsonStr json string * @ return {ApiResult} * / public static ApiResult send (String jsonStr) {String jsonResult = HttpUtils.post (sendApiUrl + AccessTokenApi.getAccessToken (). GetAccessToken (), jsonStr); return new ApiResult (jsonResult) }}

Encapsulation of json data

Com.jfinal.weixin.sdk.api.TemplateData.java

Public class TemplateData {private String touser; private String template_id; private String url; private String topcolor; private TemplateItem data; public static TemplateData New () {return new TemplateData ();} private TemplateData () {this.data = new TemplateItem ();} public String getTouser () {return touser;} public TemplateData setTouser (String touser) {this.touser = touser; return this } public String getTemplate_id () {return template_id;} public TemplateData setTemplate_id (String template_id) {this.template_id = template_id; return this;} public String getUrl () {return url;} public TemplateData setUrl (String url) {this.url = url; return this;} public String getTopcolor () {return topcolor } public TemplateData setTopcolor (String topcolor) {this.topcolor = topcolor; return this;} public TemplateItem getData () {return data;} public TemplateData add (String key, String value, String color) {data.put (key, new Item (value, color)); return this } / * directly converted to jsonString * @ return {String} * / public String build () {return JsonUtils.toJson (this);} public class TemplateItem extends HashMap {private static final long serialVersionUID =-3728490424738325020L; public TemplateItem () {} public TemplateItem (String key, Item item) {this.put (key, item) }} public class Item {private Object value; private String color; public Object getValue () {return value;} public void setValue (Object value) {this.value = value;} public String getColor () {return color } public void setColor (String color) {this.color = color;} public Item (Object value, String color) {this.value = value; this.color = color;} these are all the contents of the article "sample Analysis of Wechat official account Development template message". 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