PHP micro-Letter Development Template Message reply _php instance

Source: Internet
Author: User
On the public platform, there is a template message reply interface: Can be used to respond to specific messages-----such as the user after the order, reply to the user your order is being processed ... For example, the following picture:


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

To implement a reply to a template message, your public number must be certified, and if it is a personal subscription number, it is not supported for the time being. But it does not affect the test-----You can use the test public number:


When using the test number, the configuration of the interface information is not spoken, you can refer to my previous blog.

After using the dimension code login test number, you need to use your number to pay attention to this test number, or not see the reply of the template message.

When I was doing the test, I used a plugin from chrome: Postman. The plug-in can specify various HTTP requests such as sending Get,post, which is powerful and useful when testing interfaces.

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

2. Set up industry:

Send a POST request with the parameters:

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

Parameters:

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

The parameters of 1 and 2 indicate the industry, the specific industry can refer to the document:http://mp.weixin.qq.com/wiki/12/bd383158b0f8435c07b8b6bc7cdbac9c.html


Send a POST request specifically you can use curl to send, should not be difficult. I use postman to send. A successful JSON message is returned after the send is complete, and then the next step can be made

3, get the template ID: This piece you can customize, you can also use some built-in.

For example, use a custom template ID: There's a "new test template" in your test number.


Once submitted, you can see that your template ID appears:


Then another way to generate the template ID is to send a POST request (either curl or send with 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 the built-in template, which you can find in the graphical interface of https://mp.weixin.qq.com (authentication required)

4, after obtaining the template ID, refresh your test number page, you can see the appearance of:


5. With the template_id_short you get, send a POST request to get a msgid:

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

The data sent:

{      "Touser": "Test number of the followers of OpenID",      "template_id": "You just got the template id",      "url": "Followers click on your template message when jumping link",            "data": {          "First": {            "value": "Congratulations on your successful purchase!" ",            " color ":" #173177 "          },          " Ordermoneysum ": {            " value ":" 666 ",            " color ":" #173177 "          },          "Orderproductname": {            "value": "Mens Dress",            "color": "#173177"          },          "Remark": {            "value": "Welcome to purchase again!" ",            " color ":" #173177 "}}    }

Color indicates the colors of the fields in your template

The official document does not explain the above parameters, I wrote the above in Chinese the meaning of each field, it should be noted that Touser is not the focus on the client's "number", but as the number


After you send the parameters by post, you get a msgid:


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

This article just describes how to make a template message, if you want to use the project, also please self-browsing developer documentation, combined with micro-payment, event push and other advanced features to do together.

The above is the whole content of this article, I hope that everyone's learning has helped, but also hope that we support the script home.

  • 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.