一个包含了全部变量的全局组合数组。变量的名字就是数组的键。
<?php
function test() {
$foo = "local variable";
echo '$foo in global scope: ' . $GLOBALS["foo"] . "\n";
echo '$foo in current scope: ' . $foo . "\n";
}
$foo = "Example content";
test();
?>
第三方服务器接收微信post携带的变量名为HTTP_POST_DATA通过$GLOBALS解析数据,实际上HTTP_POST_DATA这个变量是微信发送的一个xml数据
<?php
//GET请求来自微信服务器发送的数据
//加密签名
$signature = $_GET["signature"];
//时间戳
$timestamp = $_GET["timestamp"];
//随机数
$nonce = $_GET["nonce"];
//随机字符串
$echostr = $_GET["echostr"];
//定义TOKEN
define('TOKEN','binbin');
//组装数组
$tmpArr = array(TOKEN, $timestamp, $nonce);
//对数组进行字典序排序
sort($tmpArr, SORT_STRING);
//数组转字符串拼接
$tmpStr = join($tmpArr);
//sha1加密
$tmpStr = sha1( $tmpStr );
//与拼接的加密签名比较
if( $tmpStr == $signature ){
echo $echostr;
}else{
return 'error';
}
//接收微信服务器送到第三方服务器的xml数据,微信服务器将POST消息的XML数据包到开发者填写的URL上
$postStr = $GLOBALS['HTTP_POST_DATA'];
if(!$postStr){
echo "post data error";
exit;
}