PHP version of micro-credit development token validation failure or request URL Timeout problem Solution _php Instance

Source: Internet
Author: User
Tags cdata

In this paper, we analyze the solution to the problem of token authentication failure or request URL Timeout in PHP version of micro-credit development. Share to everyone for your reference, specific as follows:

One of the most recent features of micro-credit development in fact, is a very simple user input and then automatically search the database and a data reply, this and the official not much problem, but small series on the micro-letter token verification failed to toss a lot, the following resolved to analyze for you.

1.Token validation failed

This is to check the configuration file, the most basic is

Define ("TOKEN", "Weixin"); Weixin is the ID of your micro-credit development backstage.

Micro-credit Development token authentication failure or request URL Timeout problem Resolution

2. Request URL Timeout

This is no way to submit more than a few times, this is the server installed a security dog, such as software to intercept the micro-letter IP, you can check.

3. The official download a Wechatcallbackapitest class and then the operation can be, the code is as follows:

Define ("TOKEN", "Weixin");
$WECHATOBJ = new Wechatcallbackapitest ();
if (Isset ($_get[' echostr ')) {
  $wechatObj->valid ();
} else{
  $wechatObj->responsemsg ();
}

The Wechatcallbackapitest class has the following code:

Class Wechatcallbackapitest {public function valid () {$echoStr = $_get["Echostr"];
      if ($this->checksignature ()) {echo $echoStr;
    Exit
    The Private Function checksignature () {$signature = $_get["signature"];
    $timestamp = $_get["timestamp"];
    $nonce = $_get["nonce"];
    $token = token;
    $TMPARR = Array ($token, $timestamp, $nonce);
    Sort ($TMPARR);
    $TMPSTR = implode ($TMPARR);
    $TMPSTR = SHA1 ($TMPSTR);
    if ($tmpStr = = $signature) {return true;
    }else{return false;
    The Public Function responsemsg () {$postStr = $GLOBALS ["Http_raw_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 ($keyword!= "" | |!
  Emptyempty ($keyword)) {Msgtype = "text";
  $contentStr. = Date ("Y-m-d h:i:s", Time ());
  $RESULTSTR = sprintf ($TEXTTPL, $fromUsername, $toUsername, $time, $msgType, $CONTENTSTR);
      Echo $resultStr;
      }}else{echo "";
    Exit

 }
  }
}

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.