公众平台配置信息
下方为代码,可一直复制调用 替换成自己的参数即可
<?php
namespace app\api\controller;
use think\Controller;
define("TOKEN", "你的token");
class Index extends Controller
{
public function index()
{
$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,SORT_STRING);//注意!此处最好填第二参数
$tmpStr = implode( $tmpArr );
$tmpStr = sha1( $tmpStr );
if( $tmpStr == $signature ){
return true;
}else{
return false;
}
}
}