Created
November 20, 2015 04:20
-
-
Save heywin/95fecf5d9562b6f824a6 to your computer and use it in GitHub Desktop.
微信Token验证失败测试代码
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
define("TOKEN", "weixin"); | |
traceHttp(); | |
$wechatObj = new wechatCallbackapiTest(); | |
$wechatObj -> valid(); | |
class wechatCallbackapiTest | |
{ | |
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); | |
$tmpStr = implode( $tmpArr ); | |
$tmpStr = sha1( $tmpStr ); | |
if( $tmpStr == $signature ){ | |
return true; | |
}else{ | |
return false; | |
} | |
} | |
} | |
function traceHttp() | |
{ | |
logger("REMOTE_ADDR:".$_SERVER["REMOTE_ADDR"].(strstr($_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."<br>", FILE_APPEND); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment