WeChat public platform Message Interface Development Tutorial with PHP source code

Source: Internet
Author: User
Tags sha1 encryption
This system tutorial illustrates the interface development process by using the weather god (WeatherGod account, which supports weather query of nearly 2500 counties and cities in China) on the public platform. You are welcome to pay attention to this account. the QR code is shown in the bottom figure.

This system tutorial is applied on the public platformWeather God(Account WeatherGod, supports near Domestic2500County and City weather query) as an example to explain the interface development process. You are welcome to pay attention to this account. the QR code is shown in the bottom figure.

Prerequisites: you have an HTTP server host space on the Internet and the permission to create directories and upload files. Yes for free, but a second-level domain name is required. If you want to quickly apply for a free stable and easy to use service, you can use Sina's SAE first. However, the free time is subject to restrictions.

I. Register a fair platform account

Address: http://mp.weixin.qq.com/

For more information about registration, see:

  1. Graphic tutorials on public platform registration and certification
  2. Public Platform message management and group text tutorials
  3. Document editing and automatic reply tutorials on the public platform
  4. Graphic tutorial on public platform development mode
  5. Public platform public meeting account usage details

II. Upload code

The following code is the message interface authentication code. Save the following PHP code as index. php (MytokenAnd upload it to the directory specified by the HTTP server,

 Valid (); class wechatCallbackapiTest {public function valid () {$ echoStr = $ _ GET ["echostr"]; // random string if ($ this-> checkSignature ()) {echo $ echoStr; exit ;}} private function checkSignature () {$ signature =$ _ GET ["signature"]; // encrypted signature $ timestamp = $ _ GET ["timestamp"]; // timestamp $ nonce = $ _ GET ["nonce"]; // random number $ token = TOKEN; $ tmpArr = array ($ token, $ timestamp, $ nonce); sort ($ tmpArr); // performs lexicographically ordered sorting // after sha1 encryption and signature pair Than if (sha1 (implode ($ tmpArr) ==$ signature) {return true;} else {return false ;}}?>

Or download the sample code directly. Address http://mp.weixin.qq.com/mpres/htmledition/res/wx_sample.zip

II. enable the Message Interface
Go to the public platform and selectSet-Keyword automatic reply, SelectEnable, Click next to the message interface of the public platformEditTo go to the interface configuration page:
Enter the following options as required. Note that the URL is the path where you Upload index. php. it must start with http: // and port 80.

After filling in the information, click Submit. the following results will be displayed:

1.Your server does not correctly respond to Token verification. please read the message interface user guide.

Check whether the configuration is correct. If you are sure that the configuration is correct, follow these steps to check

2. Request URL timeout

Your server is abroad, or the server's network speed is not powerful. you can try it several times. If this happens frequently, consider changing the server.

3. submission successful

Congratulations, the configuration is successful.

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.