The WeChat official account is developed in PHP. your server does not correctly respond to Token verification. please read the message interface user guide.

Source: Internet
Author: User
Your server does not correctly respond to Token verification. please refer to the message interface user guide when using URL and Token to enable the public platform development mode message interface, "Your server does not correctly respond to Token verification. please read the message interface user guide, my token verification code uses the sample code in the development documentation, which is the server applied for at SAE. Hosts file ).

Define ("TOKEN", "weixin ");
TraceHttp ();
$ WechatObj = new wechat ();
$ WechatObj-> valid ();

Class wechat {

Public function valid (){

$ EchoStr = $ _ GET ["echostr"];

If ($ this-> checkSignature ()){
Echo $ echoStr;
Exit ();
}
}
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;
}
}
}
Function traceHttp (){
Logger ("REMOTE_ADDR:". $ _ SERVER ['remote _ ADDR '].
(Strpos ($ _ SERVER ['remote _ ADDR '], "101.226 "))? "From WeiXin": "Unknown IP "));

Logger ("QUERY_STRING:". $ _ SERVER ["QUERY_STRING"]);

}
Function logger ($ content)
{
File_put_contents ("\ log.html", date ('Y-m-d H: I: s'). $ content ."
", FILE_APPEND );
}

?>


Reply to discussion (solution)

Is the url you accessed reported an error?

I downloaded a code package online, but it is the same as before. I uploaded it again, and then I can access it. I don't know what's going on.

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.