废话不多说,直接上代码:
/**
* @return void 微信公众平台设置url
*/
public function WechatAppletcheckToken(){
header("Content-type: text/html; charset=utf-8");
//1.将timestamp,nonce,toke按字典顺序排序
$timestamp = $_GET['timestamp'];
$nonce = $_GET['nonce'];
$token = '***************'; //token要和微信公众平台中服务器配置的一致(可以随便填写)
$signature = $_GET['signature'];
$array = array($timestamp,$nonce,$token);
//2.将排序后的三个参数拼接之后用sha1加密
$tmpstr = implode('',$array);
$tmpstr = sha1($tmpstr);
//3.将加密后的字符串与signature进行对比,判断该请求是否来自微信
if($tmpstr == $signature) {
echo $_GET['echostr'];
exit;
}
}
小伙伴们!这样就完成了哦! QQ学习交流群:842167453 ,欢迎小伙伴加入一起学习。