验证的代码实现
public function index()
{
//将timestamp,nonce,token按字典序排序
$timestamp = $_GET['timestamp'];
$nonce = $_GET['nonce'];
$token = 'weixin';
$signature = $_GET['signature'];
//将排序之后的三个参数拼接之后用sha1加密
$array = array($timestamp, $nonce, $token);
sort($array);
$tmpstr = implode('', $array);
$tmpstr = sha1($tmpstr);
//将加密后的字符串与sianature进行对比,判断请求是否来自于微信
if ($tmpstr == $signature) {
echo $_GET['echostr'];
exit;
}
}
接口写好之后,点击提交,如果提示token验证失败,检查代码,确认代码没错的话,可能是网络等原因的问题,多点几次就行