<?php

//1、将timestamp, nonce, token 按字典序排序
$timestamp = $_get['timestamp'];
$nonce = $_get['nonce'];
$token = 'weixin';   //你在公众平台上填写的token
$signature = $_get['signature'];
$arr = array( $timestamp, $nonce, $token );
sort($arr);

//2、将排序后的3个参数拼接后用sha1加密
$tmpstr = implode('', $arr);
$tmpstr = sha1($tmpstr);

//3、将加密后的字符串与signature进行对比,判断该请求是否来自微信
if($tmpstr == $signature){
    echo $_get['echostr'];
    exit;
}