Skip to content

Instantly share code, notes, and snippets.

@heywin
Created November 20, 2015 04:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heywin/95fecf5d9562b6f824a6 to your computer and use it in GitHub Desktop.
Save heywin/95fecf5d9562b6f824a6 to your computer and use it in GitHub Desktop.
微信Token验证失败测试代码
<?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