接入微信公众账号API--验证的代码实现

<?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;
}
原文地址:https://www.cnblogs.com/chenyingying0/p/12763501.html