Home > Backend Development > PHP Tutorial > WeChat public platform message interface verification and message interface response examples, verification examples_PHP tutorial

WeChat public platform message interface verification and message interface response examples, verification examples_PHP tutorial

WBOY
Release: 2016-07-13 10:10:57
Original
1098 people have browsed it

WeChat public platform message interface verification and message interface response examples, verification examples

The example in this article describes the method of message interface verification and message interface response on WeChat public platform. Share it with everyone for your reference. The specific analysis is as follows:

In the process of developing the WeChat public platform message interface, we first need to verify the validity of the message interface. After the verification is passed, we can proceed with other development. First, let's take a look at the PHP SDK given to me by the WeChat public platform.

1. You need to set a TOKEN information, the code is as follows:

Copy code The code is as follows:
efine("TOKEN", "weixin");

This TOKEN information can be set by the developer.

2. There is a wechatCallbackapiTest class, which contains 3 methods: valid, responseMsg, and checkSignature. The methods valid and checkSignature are used to verify the validity of the interface URL. responseMsg is the method we use most. It will be followed by Part of the development work will be completed here.

After we pass the validity verification of the interface, we no longer need to verify it. At this time, we need to use the responseMsg method. So how to ensure that after the interface verification passes, there is no need to switch the method or modify it. What about the code?

This is what I did, the code is as follows:

Copy code The code is as follows:
public function indexAction()
{
if(isset($_GET['echostr']))
{
$echoStr = $_GET["echostr"];

//valid signature , option
if($this->checkSignatureAction())
{
echo $echoStr;
exit;
}
}
else
{
$this->responseMsgAction();
}
return FALSE;
}

Let me explain: Because an echostr parameter is passed when verifying the validity of the interface, but there is no such parameter in the message interface response process, so we use this parameter here to determine whether to verify the interface or the interface response, the code is as follows:
Copy code The code is as follows:
isset($_GET['echostr'])

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/932076.htmlTechArticleWeChat public platform message interface verification and message interface response examples, verification examples This article describes WeChat public platform messages with examples Interface verification and message interface response methods. Share with everyone...
Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template