Message Interface Verification and message interface response instance on WeChat public platform, verification instance _ PHP Tutorial

Source: Internet
Author: User
Public platform Message Interface Verification and message interface response instance, verify the instance. Examples of Message Interface Verification and message interface response on the public platform. Examples of this article describe the methods of Message Interface Verification and message interface response on the public platform. Shared with the public platform Message Interface validation and message interface response instances, validation instances

This document describes how to verify the message interface and respond to the message interface on the public platform. Share it with you for your reference. The specific analysis is as follows:

During the development of the public platform message interface, we first need to verify the validity of the message interface. after the verification is passed, we can perform other development. First, let's take a look at the php sdk provided by the public platform to me.

1. you need to set a TOKEN. the code is as follows:

The code is as follows:

Efine ("TOKEN", "weixin ");

The TOKEN information can be set by the developer.

2. there is a wechatCallbackapiTest class that contains three methods: valid, responseMsg, and checkSignature. the methods valid and checkSignature are used to verify the validity of the interface URL, responseMsg is the most widely used method, and most of the subsequent development work will be completed here.

After we pass the interface validation, we no longer need to verify the interface, then we need to use the responseMsg method, then how to ensure that after the interface verification is passed, you don't need to switch the method or modify the code in it?

The code is as follows:

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


Explanation: an echostr parameter is passed to verify the interface validity, but this parameter is not provided in the response process of the message interface, here we use this parameter to determine whether to verify the interface or interface response. the code is as follows:

The code is as follows:

Isset ($ _ GET ['echostr'])

I hope this article will help you with php programming.

The following example describes how to verify the message interface and respond to the message interface on the public platform. Share it with you...

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.