php微信公众开发之获取周边酒店信息的方法
程序员文章站
2023-11-11 17:28:34
本文实例讲述了php微信公众开发之获取周边酒店信息的方法。分享给大家供大家参考。具体分析如下:
关注微信公众之后发送回复地理位置信息,即可回复周边附近的酒店信息列表,下面...
本文实例讲述了php微信公众开发之获取周边酒店信息的方法。分享给大家供大家参考。具体分析如下:
关注微信公众之后发送回复地理位置信息,即可回复周边附近的酒店信息列表,下面我就来给各位介绍利用php是怎么实现这个功能,希望全子对大家有帮助.代码如下:
复制代码 代码如下:
<?php
//将提交过来的信息接收
$signature = $_get['signature'];
$timestamp = $_get['timestamp'];
$nonce = $_get['nonce'];
$echostr = $_get['echostr'];
$token = "jb51.net";
//判断接入网站
//进行字典排序
$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.",".$location_x."&zoom=15&markers=".$location_y.",".$location_x."&markerstyles=l,";
$p_640 = file_get_contents($pic_640);
file_put_contents('./images/640_'.$fromusername.".png",$p_640);
$p_80 = file_get_contents($pic_80);
file_put_contents('./images/80_'.$fromusername.".png",$p_80);
echo pic_send($json['results']);
}
function pic_send($arr){
global $tousername,$fromusername;
$str = "<xml>
<tousername><![cdata[".$fromusername."]]></tousername>
<fromusername><![cdata[".$tousername."]]></fromusername>
<createtime>".time()."</createtime>
<msgtype><![cdata[news]]></msgtype>
<articlecount>".count($arr)."</articlecount>
<articles>";
foreach($arr as $k=>$v){
if($k==0){
$picurl = "http://jb51.net/weixin/images/640_".$fromusername.".png";
}else{
$picurl = "http://jb51.net.net/weixin/images/80_".$fromusername.".png";
}
$str .="
<item>
<title><![cdata[".$v['name']." 地址:".$v['address']." 电话:".$v['telephone']."]]></title>
<description><![cdata[".$v['name']." 地址:".$v['address']." 电话:".$v['telephone']."]]></description>
<picurl><![cdata[".$picurl."]]></picurl>
<url><![cdata[http://api.map.baidu.com/place/detail?uid=".$v['uid']."&output=html&src=".$v['name']."&output=html]]></url>
</item>";
}
$str .= "</articles></xml>";
return $str;
}
?>
//将提交过来的信息接收
$signature = $_get['signature'];
$timestamp = $_get['timestamp'];
$nonce = $_get['nonce'];
$echostr = $_get['echostr'];
$token = "jb51.net";
//判断接入网站
//进行字典排序
$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.",".$location_x."&zoom=15&markers=".$location_y.",".$location_x."&markerstyles=l,";
$p_640 = file_get_contents($pic_640);
file_put_contents('./images/640_'.$fromusername.".png",$p_640);
$p_80 = file_get_contents($pic_80);
file_put_contents('./images/80_'.$fromusername.".png",$p_80);
echo pic_send($json['results']);
}
function pic_send($arr){
global $tousername,$fromusername;
$str = "<xml>
<tousername><![cdata[".$fromusername."]]></tousername>
<fromusername><![cdata[".$tousername."]]></fromusername>
<createtime>".time()."</createtime>
<msgtype><![cdata[news]]></msgtype>
<articlecount>".count($arr)."</articlecount>
<articles>";
foreach($arr as $k=>$v){
if($k==0){
$picurl = "http://jb51.net/weixin/images/640_".$fromusername.".png";
}else{
$picurl = "http://jb51.net.net/weixin/images/80_".$fromusername.".png";
}
$str .="
<item>
<title><![cdata[".$v['name']." 地址:".$v['address']." 电话:".$v['telephone']."]]></title>
<description><![cdata[".$v['name']." 地址:".$v['address']." 电话:".$v['telephone']."]]></description>
<picurl><![cdata[".$picurl."]]></picurl>
<url><![cdata[http://api.map.baidu.com/place/detail?uid=".$v['uid']."&output=html&src=".$v['name']."&output=html]]></url>
</item>";
}
$str .= "</articles></xml>";
return $str;
}
?>
希望本文所述对大家的php程序设计有所帮助。