接口接入 和 微信消息驗證
如果有$_GET['echostr']說明是開發者接入,驗證成功 ,原樣返回字符串。
沒有$_GET['echostr']參數,則驗證消息是否符合規則,基本驗證過濾惡意請求。
~~~
/**
* 驗證
*/
public function authentication()
{
$signature = $_GET["signature"];
$timestamp = $_GET["timestamp"];
$nonce = $_GET["nonce"];
$tmpArr = array($this->_token, $timestamp, $nonce);
sort($tmpArr, SORT_STRING);
$tmpStr = implode($tmpArr);
$sign = sha1($tmpStr);
if ($sign == $signature) {
if(isset($_GET['echostr'])){
return $_GET['echostr'];
}
return true;
}
return false;
}
~~~