signature:微信加密簽名,signature結合了開發者填寫的token參數和請求中的timestamp參數、nonce參數。
其中:
timestamp:時間戳
nonce:隨機數
ampechostr:隨機字串ampechostr:隨機字串nonce:隨機數位元、別序。
2.將三個參數拼接成一個字串,並使用sha1加密。
<span style="font-family:KaiTi_GB2312;font-size:14px;"><?php define("TOKEN","weixin"); $weixinObj = new Wechat(); $weixinObj->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); $tmpStr = implode($tmpArr); $tmpStr = sha1($tmpStr); if($tmpStr == $signature){ return true; }else{ return false; } } }</span>