微信账号 echo_server 的实现

<?php
/*
* 微信账号 echo_server 的实现
*/
/*
* 定义 echo_server 的 TOKEN 为 echo_server
*/
define("TOKEN","echo_server");
//获取GET参数
$signature=$_GET['signature'];
$nonce=$_GET['nonce'];
$timestamp=$_GET['timestamp'];
$echostr=$_GET['echostr'];
//把 nonce、timestamp和TOKEN组装到数组里并做排序
$tmpArr=array($nonce,$timestamp,TOKEN);
sort($tmpArr);
//把数组中的元素合并成字符串
$tmpStr=implode($tmpArr);
//sha1加密
$tmpStr=sha1($tmpStr);
//判断加密后的字符串是否和signature相等
if($tmpStr==$signature){
//相等就返回echostr
echo $echostr;
}
?>

原文地址:https://www.cnblogs.com/lykouyi/p/5726174.html