在本身的服務器上新建一個空白php文件,輸入如下任一版本的代碼,以下:php
版本一:服務器
<?php $token = "dige1994"; $signature = $_GET["signature"]; $timestamp = $_GET["timestamp"]; $nonce = $_GET["nonce"]; $echostr = $_GET["echostr"]; $tmpArr = array($token, $timestamp, $nonce); sort($tmpArr); $tmpStr = implode( $tmpArr ); $tmpStr = sha1( $tmpStr ); if($tmpStr == $signature ){ echo $echostr; }else{ echo "err"; } ?>
版本二:微信
<?php define("TOKEN", "dige1994"); //TOKEN值 $wechatObj = new wechat(); $wechatObj->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; } } } ?>
在微信公衆平臺——基本配置——服務器配置中,將上述文件的地址填到URL欄中,將$token的值填到Token欄,消息加解密密鑰隨機生成,消息加解密方式在學習階段建議選擇明文方式,而後提交,提交成功後再點啓用配置。微信公衆平臺