首先准备内网穿透工具(推荐utools),然后在控制器中写入下面代码
/*
* 用于测试号验证接口配置信息
* url为内网穿透的网址:http://sdfs/html/vertify
* Token:wx_test
*/
public function getVertify()
{
$echoStr = $_GET["echostr"];
if($this->checkSignature()){
echo $echoStr;//一定要返回,才可以设置成功
exit;
}
}
private function checkSignature()
{
$signature = $_GET["signature"];
$timestamp = $_GET["timestamp"];
$nonce = $_GET["nonce"];
$token = 'wx_test';
$tmpArr = array($token, $timestamp, $nonce);
sort($tmpArr, SORT_STRING);
$tmpStr = implode( $tmpArr );
$tmpStr = sha1( $tmpStr );
if( $tmpStr == $signature ){
return true;
}else{
return false;
}
}