tips-1048079-01.php class WeChat{ private $_appid; private $_appsecret; private $_token; public function __construct($appid, $appsecret, $token) { $this-_appid = $appid; $this-_appsecret = $appsecret; $this-_token = $token; } public functio
class WeChat
{
private $_appid;
private $_appsecret;
private $_token;
public function __construct($appid, $appsecret, $token)
{
$this->_appid = $appid;
$this->_appsecret = $appsecret;
$this->_token = $token;
}
public function valid()
{
$echoStr = $_GET["echostr"];
//valid signature , option
if($this->checkSignature())
{
echo $echoStr;
exit;
}
}
private function checkSignature()
{
$signature = $_GET["signature"];
$timestamp = $_GET["timestamp"];
$nonce = $_GET["nonce"];
$token = $this->_token;
$tmpArr = array($token, $timestamp, $nonce);
sort($tmpArr);
$tmpStr = implode( $tmpArr );
$tmpStr = sha1( $tmpStr );
if( $tmpStr == $signature )
{
return true;
}
else
{
return false;
}
}
}
