PHP WeChat development template message reply, php template message reply

Source: Internet
Author: User
Tags php template

Template message reply in PHP development and php template message reply

On the public platform, there is a template message reply interface that can be used to reply to a specific message. For example, after a user places an order, your order is being processed... for example, the figure below:


After the user performs some operations, the service number can return a specific message-this is the template message.

To reply to template messages, your public account must be authenticated. For personal subscription accounts, authentication is not supported for the moment. However, the test is not affected. You can use the test public account:


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

After logging on to the test number with the dimension code, you need to follow the test number with your ID. Otherwise, you will not be able to see the reply to the template message.

During the test, I used a chrome plug-in: postman. This plug-in can specify various HTTP requests such as GET and POST, which are powerful and useful for testing interfaces.

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

2. Set the industry:

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 OBTAINED

Parameters:

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

1 and 2 in the parameter represents the industry, the specific industry can refer to the document: http://mp.weixin.qq.com/wiki/12/bd383158b0f8435c07b8b6bc7cdbac9c.html


It is not difficult to send a post request using curl. I use postman to send messages. After sending the message, a successful json message is returned, and you can proceed to the next step.

3. Obtain the template ID. You can customize the template or use the built-in template ID.

For example, use a custom template ID: In your test number, you have a new test template"


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


Then another method to generate the template ID is to send the post request (which can be sent using curl or postman)

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

Parameters:

 {      "template_id_short":"TM00015"    }

Where TM00015 is the ID of the built-in template, you can find it in the graphical interface of the https://mp.weixin.qq.com (authentication required)

4. After obtaining the template ID, refresh your test number page and you will see the following:


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

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

Sent data:

{"Touser": "openId of the test code consumer", "template_id": "template ID you just obtained", "url ": "The registrant clicks the link to jump to your template message", "data": {"first": {"value": "Congratulations! "," Color ":" #173177 "}," orderMoneySum ": {" value ":" 666 "," color ":" #173177 "}," orderProductName ": {"value": "Men's formal attire", "color": "#173177"}, "Remark": {"value": "Welcome to purchase again! "," Color ":" #173177 "}}}

Color indicates the color of fields in your template.

The official document does not describe the above parameters. I wrote the meaning of each field in Chinese. Note that touser is not the "Number" of the user on the client ", it is like the number in


After the parameter is sent in post mode, a msgid is obtained:


When you get this successful response, at the same time, your test public number should also return a template message to you (the author)

This article only describes how to make a template message. If you want to use a project, read the developer documentation and use it with advanced features such as micro-payment and event push.

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.