本文实例讲述了PHP微信公众开发之获取周边酒店信息的方法。分享给大家供大家参考。具体分析如下:
关注微信公众之后发送回复地理位置信息,即可回复周边附近的酒店信息列表,下面我就来给各位介绍利用PHP是怎么实现这个功能,希望全子对大家有帮助.代码如下:
$arr = array($token,$timestamp,$nonce);
sort($arr);
//完成字符串的拼接和sha1加密
$result = sha1(join($arr));
//判断生成的字符串和$signature是否相等,如果相等,直接输出$echostr,这样网站接入成功
if($result==$signature){
echo $echostr;
}
//接收微信公众账号接收到的信息
$poststr = $GLOBALS["HTTP_RAW_POST_DATA"];
$xmlObj = simplexml_load_string($poststr,'SimpleXMLElement',LIBXML_NOCDATA);
$ToUserName = $xmlObj->ToUserName;
$FromUserName = $xmlObj->FromUserName;
$CreateTime = $xmlObj->CreateTime;
$MsgType = $xmlObj->MsgType;
$Content = $xmlObj->Content;
if($MsgType=='location'){
$Location_X = $xmlObj->Location_X;
$Location_Y = $xmlObj->Location_Y;
$Scale = $xmlObj->Scale;
$Label = $xmlObj->Label;
$urlstr = "http://api.map.baidu.com/place/v2/search?&query=酒店&location=".$Location_X.",".$Location_Y."&radius=5000&output=json&ak=DESY8unmZnUlLB0mlowjuiRr"; //此处ak参数需要个人的百度开发序列号,自己去百度申请下就好了
$jsonstr = file_get_contents($urlstr);
$json = json_decode($jsonstr,true);
$pic_640 = "http://api.map.baidu.com/staticimage?width=640&height=320¢er=".$Location_Y.",".$Location_X."&zoom=15&markers=".$Location_Y.",".$Location_X."&markerStyles=l,";
$pic_80 = "http://api.map.baidu.com/staticimage?width=80&height=80¢er=".$Location_Y.",";
$p_640 = file_get_contents($pic_640);
file_putcontents('./images/640'.$FromUserName.".png",$p_640);
$p_80 = file_get_contents($pic_80);
file_putcontents('./images/80'.$FromUserName.".png",$p_80);
echo pic_send($json['results']);
}
function pic_send($arr){
global $ToUserName,$FromUserName;
$str = "
希望本文所述对大家的PHP程序设计有所帮助。
原文链接:/php/23052.html