PHP version of the micro-credit public platform for the development of verification steps to explain _php example

Source: Internet
Author: User

This article illustrates the verification steps of the development of the PHP version of the micro-trust public platform. Share to everyone for your reference, specific as follows:

Development of micro-credit public platform We are doing a lot more now, here to introduce you to an entry-level micro-letter public platform to verify the basic knowledge, interested and small to see.

The development of micro-letters need to verify that in the official developer center where there is the source code, login to the public account to see the bottom left corner of a developer center click, and then fill in your corresponding Token and URL and then you can verify the success of the words can be developed.

Download micro-letter PHP verification source code in developer Center-developer Documentation-Interface message-Verify message authenticity-pull to the bottom of PHP demo code.

After the download good code is as follows:

<?php/** * WeChat PHP Test * Update time:20141008///define Your token define ("token", "Weixin");
$WECHATOBJ = new Wechatcallbackapitest ();
$WECHATOBJ->valid ();
  Class Wechatcallbackapitest {public function valid () {$echoStr = $_get["Echostr"];
  Valid signature, option if ($this->checksignature ()) {echo $echoStr;
  Exit The Public Function responsemsg () {//get post data, May is due to the different environments $postStr = $GLOBALS ["HT
  Tp_raw_post_data "]; Extract post Data if (!emptyempty ($POSTSTR)) {$POSTOBJ = simplexml_load_string ($postStr, ' simplexmlelement ', LIBXML
    _nocdata);
    $fromUsername = $POSTOBJ->fromusername;
    $toUsername = $POSTOBJ->tousername;
    $keyword = Trim ($postObj->content);
    $time = time (); $TEXTTPL = "<xml> <tousername><! [cdata[%s]]></tousername> <fromusername><! [cdata[%s]]></fromusername> <CreateTime>%s</CreateTime> <msgtype><! [cdata[%S]]></msgtype> <content><!
[cdata[%s]]></content> <FuncFlag>0</FuncFlag> </xml> ";
    if (!emptyempty ($keyword)) {$msgType = "text";
    $CONTENTSTR = "Welcome to WeChat world!";
    $RESULTSTR = sprintf ($TEXTTPL, $fromUsername, $toUsername, $time, $msgType, $CONTENTSTR);
    Echo $resultStr;
    }else{echo "Input something ...";
  }}else {echo "";
  Exit
  The Private Function checksignature () {$signature = $_get["signature"];
  $timestamp = $_get["timestamp"];
$nonce = $_get["nonce"];
$token = token;
  $TMPARR = Array ($token, $timestamp, $nonce);
Sort ($TMPARR, sort_string);
$TMPSTR = implode ($TMPARR);
$TMPSTR = SHA1 ($TMPSTR); if ($tmpStr = = $signature) {return true;}
else{return false;}

 }?>

Where: TOKEN modified for what you want and then in the developer Center to write the same, in the process of validation $wechatObj->valid (); This code can not be removed this is validated, after the success of the validation we will be able to->valid this paragraph $wechatObj (); This annotation is dropped and then used $WECHATOBJ->responsemsg (); For the test.

Note: In the development of the need to put $WECHATOBJ->valid (); To comment out, or in the mobile phone when the test will not show anything.

For more information on PHP related content readers can view the site topics: "PHP micro-credit Development Skills summary", "PHP coding and transcoding Operation skills Summary", "PHP Network Programming Skills Summary", "PHP basic Grammar Introductory Course", "PHP string (String) Usage Summary", "php+ MySQL Database operations Introduction tutorial and PHP Common database operation Skills Summary

I hope this article will help you with the PHP program design.

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.