//将此文件放在服务器上,URL上地址连接到此文件上并在后面加上 /80(微信80端口)
<?php//定义常量token,任意内容,和网页上一致即可
define('TOKEN','feiyushang');
//检查标签 function checkSignature() { //先获取到这三个参数 $signature = $_GET['signature']; $nonce = $_GET['nonce']; $timestamp = $_GET['timestamp'];
//把这三个参数存到一个数组里面 $tmpArr = array($timestamp,$nonce,TOKEN); //进行字典排序 sort($tmpArr); //把数组中的元素合并成字符串,impode()函数是用来将一个数组合并成字符串的 $tmpStr = implode($tmpArr);
//sha1加密,调用sha1函数 $tmpStr = sha1($tmpStr); //判断加密后的字符串是否和signature相等 if($tmpStr == $signature) { return true; } return false; }//如果相等,验证成功就返回echostr if(checkSignature()) { //返回echostr $echostr = $_GET['echostr']; if($echostr) { echo $echostr; exit; } }
?>
转载于:https://www.cnblogs.com/feiyushang/p/7686130.html
相关资源:微信公众平台(1)搭建php开发配置详细步骤1