Table of Contents
How to check whether there is Permission
Home WeChat Applet WeChat Development An example tutorial for sharing WeChat public account development template messages

An example tutorial for sharing WeChat public account development template messages

May 19, 2017 pm 03:56 PM

WeChat Speedy Development Series of Articles: Click here

I have had a slight cold recently, and the update progress of the article has been delayed. I hope this series of articles will be useful to you Studying WeChat Public Developmenthelpful. The previous articles introduced WeChat payment. Public account payment, WeChat scan code payment, card payment, WeChat payment

This article will talk about business notifications in WeChat----WeChat template message

How to check whether there is Permission

In the communication group, there are always people asking aboutpersonal subscription number,certified subscription number,service number,Authentication service number Whether a certain interface has permission to be used.

In fact, this problem is very simple. On [WeChat Public Platform], you can now directly check which interfaces your public accounts can use.

Log in to [WeChat Public Platform] and enter the homepage>Development>Interface Permissions

An example tutorial for sharing WeChat public account development template messages

##Template Message-Permissions. png

Add template message plug-in

Note that it must be a certified service account

Log in [WeChat public platform] and enter the homepage>Add plug-in function> ; Find the template message and follow the guided process.

Usage Rules of Template Message Interface

Official Document Sending Messages-Template Message Interface and Template Message Operation Specifications

Regarding the usage rules, please note:

1. All service accounts can see the entrance to apply for the template message function at Function->Add Function Plug-in, but only authenticated service accounts can apply for and obtain the permission to use template messages;
2. You need to select 2 industries where the public account service is located, and the selected industry can be changed once a month;
3. Select an 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 daily call limit for template messages for each account is 100,000 times, and there is no special limit for a single template. [On November 18, 2014, the interface call frequency was increased from the default 10,000 times per day to 100,000 times per day, which can be viewed in the Developer Center after MP login]. When the number of followers of an account exceeds 10W/100W/1000W, the daily calling limit of template messages will be increased accordingly, based on the number indicated on the official account MP backend developer center page.

Add template message

Follow the above

Add template message plug-inAfter that, the Template message menu will appear in the left column of the [WeChat public platform] home page , to collect and click in, you need to agree to the agreement and set up the two industries in which the public account service is located.

After setting the above, you can search for existing templates in the template library through keywords. If you don't find them, you can apply for them yourself.

An example tutorial for sharing WeChat public account development template messages

Template message - add template.png

Find the appropriate template message and click Details, go in and view the template details, and add it if needed. After the addition is completed, the

template ID of the template message will be generated in my template. The template ID will be used later.

An example tutorial for sharing WeChat public account development template messages

Template message-template details.png

Test number add template message

An example tutorial for sharing WeChat public account development template messages

Test account adds template message.png

An example tutorial for sharing WeChat public account development template messages

Test account adds template message.png

Usage of template message interface

Objectively, there are some preparations ahead. Hold a cup of tea and look down patiently. Let’s first take a practical look at how the encapsulated interfaces in open source projects are used.

com.javen.weixin.controller.WeixinMsgController.java

An example tutorial for sharing WeChat public account development template messages

Usage of template messages.png

An example tutorial for sharing WeChat public account development template messages

Notification received

Encapsulation of template message

Official reference document specific implementation

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=";

    /**
     * 发送模板消息
     * @param jsonStr json字符串
     * @return {ApiResult}
     */
    public static ApiResult send(String jsonStr) {
        String jsonResult = HttpUtils.post(sendApiUrl + AccessTokenApi.getAccessToken().getAccessToken(), jsonStr);
        return new ApiResult(jsonResult);
    }
}
Copy after login

json data encapsulation

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;
    }

    /**
     * 直接转化成jsonString
     * @return {String}
     */
    public String build() {
        return JsonUtils.toJson(this);
    }

    public class TemplateItem extends HashMap<String, Item> {

        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;
        }
    }
}
Copy after login

【Related recommendations】

1.

WeChat public account platform source code download

2. Xiaozhu CMS Lifetong O2O system v2.0 exclusive version download

3. Alizi order system source code

The above is the detailed content of An example tutorial for sharing WeChat public account development template messages. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP WeChat development: How to implement message encryption and decryption PHP WeChat development: How to implement message encryption and decryption May 13, 2023 am 11:40 AM

PHP is an open source scripting language that is widely used in web development and server-side programming, especially in WeChat development. Today, more and more companies and developers are starting to use PHP for WeChat development because it has become a truly easy-to-learn and easy-to-use development language. In WeChat development, message encryption and decryption are a very important issue because they involve data security. For messages without encryption and decryption methods, hackers can easily obtain the data, posing a threat to users.

Using PHP to develop WeChat mass messaging tools Using PHP to develop WeChat mass messaging tools May 13, 2023 pm 05:00 PM

With the popularity of WeChat, more and more companies are beginning to use it as a marketing tool. The WeChat group messaging function is one of the important means for enterprises to conduct WeChat marketing. However, if you only rely on manual sending, it is an extremely time-consuming and laborious task for marketers. Therefore, it is particularly important to develop a WeChat mass messaging tool. This article will introduce how to use PHP to develop WeChat mass messaging tools. 1. Preparation work To develop WeChat mass messaging tools, we need to master the following technical points: Basic knowledge of PHP WeChat public platform development Development tools: Sub

How to use PHP to develop template message management functions for public accounts How to use PHP to develop template message management functions for public accounts Sep 19, 2023 am 11:28 AM

How to use PHP to develop the template message management function of public accounts. With the popularity and use of WeChat public accounts, more and more companies and individuals have begun to pay attention to how to better interact and communicate with users. Among them, template messages are a very commonly used function and can be used to send notifications, reminders, push and other information. This article will introduce how to use PHP to develop the template message management function of public accounts and provide specific code examples. Configuration of WeChat public platform First, you need to configure template messages on WeChat public platform. Log in to the WeChat public platform and enter the public

PHP WeChat development: How to implement user tag management PHP WeChat development: How to implement user tag management May 13, 2023 pm 04:31 PM

In the development of WeChat public accounts, user tag management is a very important function, which allows developers to better understand and manage their users. This article will introduce how to use PHP to implement the WeChat user tag management function. 1. Obtain the openid of the WeChat user. Before using the WeChat user tag management function, we first need to obtain the user's openid. In the development of WeChat public accounts, it is a common practice to obtain openid through user authorization. After the user authorization is completed, we can obtain the user through the following code

PHP WeChat development: How to implement group message sending records PHP WeChat development: How to implement group message sending records May 13, 2023 pm 04:31 PM

As WeChat becomes an increasingly important communication tool in people's lives, its agile messaging function is quickly favored by a large number of enterprises and individuals. For enterprises, developing WeChat into a marketing platform has become a trend, and the importance of WeChat development has gradually become more prominent. Among them, the group sending function is even more widely used. So, as a PHP programmer, how to implement group message sending records? The following will give you a brief introduction. 1. Understand the development knowledge related to WeChat public accounts. Before understanding how to implement group message sending records, I

PHP WeChat development: How to implement customer service chat window management PHP WeChat development: How to implement customer service chat window management May 13, 2023 pm 05:51 PM

WeChat is currently one of the social platforms with the largest user base in the world. With the popularity of mobile Internet, more and more companies are beginning to realize the importance of WeChat marketing. When conducting WeChat marketing, customer service is a crucial part. In order to better manage the customer service chat window, we can use PHP language for WeChat development. 1. Introduction to PHP WeChat development PHP is an open source server-side scripting language that is widely used in the field of Web development. Combined with the development interface provided by WeChat public platform, we can use PHP language to conduct WeChat

PHP WeChat development: How to implement voting function PHP WeChat development: How to implement voting function May 14, 2023 am 11:21 AM

In the development of WeChat public accounts, the voting function is often used. The voting function is a great way for users to quickly participate in interactions, and it is also an important tool for holding events and surveying opinions. This article will introduce you how to use PHP to implement WeChat voting function. Obtain the authorization of the WeChat official account. First, you need to obtain the authorization of the WeChat official account. On the WeChat public platform, you need to configure the API address of the WeChat public account, the official account, and the token corresponding to the public account. In the process of our development using PHP language, we need to use the PH officially provided by WeChat

How to use PHP to implement the template message sending function of public accounts How to use PHP to implement the template message sending function of public accounts Sep 19, 2023 pm 12:33 PM

How to use PHP to implement the template message sending function of public accounts. In recent years, with the rapid growth in the number of users of WeChat public accounts, more and more companies and individuals have begun to pay attention to the development of WeChat public accounts. Among them, template messages are one of the commonly used functions in public account development. Template messages can be used to send fixed-format messages to users and provide various services and information. This article will introduce how to use PHP to implement the template message sending function of public accounts, and provide specific code examples. First, in order to implement the template message sending function of the official account, we need to

See all articles