// 1)將token、timestamp、nonce三個參數進行字典序排序
// 2)將三個參數字符串拼接成一個字符串進行sha1加密
// 3)開發者獲得加密后的字符串可與signature對比,標識該請求來源於微信
$signature = $_GET['signature'];
$token = 'mashi';
$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) {
echo $echostr;
} else {
echo '';
}