Table of Contents
PHP微信开发之模板消息回复,php模板消息回复
Home Backend Development PHP Tutorial PHP微信开发之模板消息回复,php模板消息回复_PHP教程

PHP微信开发之模板消息回复,php模板消息回复_PHP教程

Jul 11, 2016 am 10:36 AM
php WeChat

PHP微信开发之模板消息回复,php模板消息回复

微信公众平台上,有个模板消息回复接口:可以用来实现回复特定的消息-----比如用户下了订单之后,回复给用户您的订单正在处理中...比如下面这张图:


用户进行了一些操作之后,服务号能够返回特定的消息----这就是模板消息。

要实现模板消息的回复,你的公众号必须是经过微信认证的,如果是个人的订阅号,暂时不支持微信认证。不过也不影响做测试-----你可以使用测试公众号:


使用测试号的时候,接口信息的配置就不讲了,可以参考我之前的博客。

使用维码登录测试号之后,需要用你的微信号去关注这个测试号,不然看不到模板消息的回复。

我在做测试的时候,用了chrome浏览器的一个插件:postman。该插件可以指定发送GET,POST等各种HTTP请求,功能强大,在测试接口时很有用。

1、发送GET请求获取测试号的access_token:https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=你的测试号appID&secret=你的测试号appsecret

2、设置所属行业:

发送一个POST请求,并带上参数:

请求:https://api.weixin.qq.com/cgi-bin/template/api_set_industry?access_token=你刚才得到的access_token

参数:

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

Copy after login

参数里的1和2表示所属的行业,具体的行业可以参考文档:http://mp.weixin.qq.com/wiki/12/bd383158b0f8435c07b8b6bc7cdbac9c.html


具体发送post请求大家可以使用curl发送,应该不难。我使用postman来发送。发送完成之后返回成功的json消息,然后就可以进行下一步

3、获得模板ID:这一块你可以自定义,也可以使用微信内置的一些。

比如使用自定义的模板ID:在你的测试号里有个“新增测试模板”


提交之后,就可以看到自己模板ID出现了:


然后另一种生成模板ID的方法是发送post请求(可以curl发送或者用postman发送)

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

参数:

 {
      "template_id_short":"TM00015"
    }

Copy after login

其中的TM00015是微信内置的模板的ID,你可以在https://mp.weixin.qq.com的图形化界面里找到(须微信认证)

4、获得模板ID之后,刷新你的测试号页面,可以看到出现了:


5、用你得到的template_id_short,再发送一个post请求就可以得到一个msgid:

请求:https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=你的access_token

发送的数据:

 {
      "touser":"测试号的关注者的openId",
      "template_id":"你刚才得到的模板ID",
      "url":"关注者点击你的模板消息时跳转的链接",      
      "data":{
          "first": {
            "value":"恭喜你购买成功!",
            "color":"#173177"
          },
          "orderMoneySum":{
            "value":"666",
            "color":"#173177"
          },
          "orderProductName": {
            "value":"男士正装",
            "color":"#173177"
          },
          "Remark":{
            "value":"欢迎再次购买!",
            "color":"#173177"
          }
      }
    }
Copy after login

color表示你的模板里字段的颜色

官方的文档里没有对上面的参数作说明,我在上面用中文写出了每个字段的意思,其中需要注意的是,touser不是关注者在微信客户端的“微信号”,而是如下图里的微信号


把参数用post方式发送之后,就会得到一个msgid:


得到这个成功响应的时候,同时,你的测试公众号应该也返回了一个模板消息给你(关注者)

本文只是介绍怎样做出一个模板消息,如果想用到项目里,还请自行翻阅微信开发者文档,结合微支付,事件推送等高级功能一起来做。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持帮客之家。

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1138989.htmlTechArticlePHP微信开发之模板消息回复,php模板消息回复 微信公众平台上,有个模板消息回复接口:可以用来实现回复特定的消息-----比如用户下了订...
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 Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

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)

Hot Topics

Java Tutorial
1669
14
PHP Tutorial
1273
29
C# Tutorial
1256
24
PHP and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

Choosing Between PHP and Python: A Guide Choosing Between PHP and Python: A Guide Apr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Python: A Deep Dive into Their History PHP and Python: A Deep Dive into Their History Apr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP's Impact: Web Development and Beyond PHP's Impact: Web Development and Beyond Apr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

Is the company's security software causing the application to fail to run? How to troubleshoot and solve it? Is the company's security software causing the application to fail to run? How to troubleshoot and solve it? Apr 19, 2025 pm 04:51 PM

Troubleshooting and solutions to the company's security software that causes some applications to not function properly. Many companies will deploy security software in order to ensure internal network security. ...

The Continued Use of PHP: Reasons for Its Endurance The Continued Use of PHP: Reasons for Its Endurance Apr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

The latest news APP ranking recommendation in the currency circle (authoritative release in 2025) The latest news APP ranking recommendation in the currency circle (authoritative release in 2025) Apr 21, 2025 pm 09:33 PM

The best cryptocurrency trading and analysis platforms include: 1. OKX: the world's number one in trading volume, supports multiple transactions, provides AI market analysis and on-chain data monitoring. 2. Binance: The world's largest exchange, providing in-depth market conditions and new currency first-time offerings. 3. Sesame Open Door: Known for spot trading and OTC channels, it provides automated trading strategies. 4. CoinMarketCap: an authoritative market data platform, covering 20,000 currencies. 5. CoinGecko: Known for community sentiment analysis, it provides DeFi and NFT trend monitoring. 6. Non-small account: a domestic market platform, providing analysis of linkage between A-shares and currency markets. 7. On-chain Finance: Focus on blockchain news and update in-depth reports every day. 8. Golden Finance: 24 small

The Compatibility of IIS and PHP: A Deep Dive The Compatibility of IIS and PHP: A Deep Dive Apr 22, 2025 am 12:01 AM

IIS and PHP are compatible and are implemented through FastCGI. 1.IIS forwards the .php file request to the FastCGI module through the configuration file. 2. The FastCGI module starts the PHP process to process requests to improve performance and stability. 3. In actual applications, you need to pay attention to configuration details, error debugging and performance optimization.

See all articles