代码如下
$token = '5tB3loEBrxETgAseOZGkI17rHyQCMzvh'; // 你在微信公众平台或微信开放平台上设定的token
$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) {
// 验证通过,将echostr参数返回给微信服务器
echo $echostr;
} else {
// 验证失败,可以返回错误信息
echo 'Token verification failed.';
}
exit;