php微信公眾開(kāi)發(fā)之獲取周邊酒店信息的方法
本文實(shí)例講述了php微信公眾開(kāi)發(fā)之獲取周邊酒店信息的方法。分享給大家供大家參考。具體分析如下:
關(guān)注微信公眾之后發(fā)送回復(fù)地理位置信息,即可回復(fù)周邊附近的酒店信息列表,下面我就來(lái)給各位介紹利用php是怎么實(shí)現(xiàn)這個(gè)功能,希望全子對(duì)大家有幫助.代碼如下:
//將提交過(guò)來(lái)的信息接收
$signature = $_GET['signature'];
$timestamp = $_GET['timestamp'];
$nonce = $_GET['nonce'];
$echostr = $_GET['echostr'];
$token = "jb51.net";
//判斷接入網(wǎng)站
//進(jìn)行字典排序
$arr = array($token,$timestamp,$nonce);
sort($arr);
//完成字符串的拼接和sha1加密
$result = sha1(join($arr));
//判斷生成的字符串和$signature是否相等,如果相等,直接輸出$echostr,這樣網(wǎng)站接入成功
if($result==$signature){
echo $echostr;
}
//接收微信公眾賬號(hào)接收到的信息
$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參數(shù)需要個(gè)人的百度開(kāi)發(fā)序列號(hào),自己去百度申請(qǐng)下就好了
$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']." 電話(huà):".$v['telephone']."]]></Title>
<Description><![CDATA[".$v['name']." 地址:".$v['address']." 電話(huà):".$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;
}
?>
希望本文所述對(duì)大家的php程序設(shè)計(jì)有所幫助。
- 微信公眾號(hào)開(kāi)發(fā)之獲取位置信息php代碼
- 實(shí)例分析基于PHP微信網(wǎng)頁(yè)獲取用戶(hù)信息
- php 微信開(kāi)發(fā)獲取用戶(hù)信息如何實(shí)現(xiàn)
- PHP版微信第三方實(shí)現(xiàn)一鍵登錄及獲取用戶(hù)信息的方法
- php微信公眾平臺(tái)開(kāi)發(fā)之微信群發(fā)信息
- PHP微信開(kāi)發(fā)之根據(jù)用戶(hù)回復(fù)關(guān)鍵詞\位置返回附近信息
- php微信公眾平臺(tái)開(kāi)發(fā)之獲取用戶(hù)基本信息
- php微信公眾號(hào)開(kāi)發(fā)之音樂(lè)信息
相關(guān)文章
shell腳本作為保證PHP腳本不掛掉的守護(hù)進(jìn)程實(shí)例分享
以下是對(duì)用shell腳本作為保證PHP腳本不掛掉的守護(hù)進(jìn)程實(shí)例進(jìn)行了分析介紹,需要的朋友可以參考下2013-07-07
使用PHP和Xunsearch實(shí)現(xiàn)歌曲搜索功能
這篇文章主要為大家詳細(xì)介紹了如何用 PHP 和 Xunsearch 搭配,快速打造一個(gè)又快又準(zhǔn)的歌曲搜索功能,讓用戶(hù)的體驗(yàn)直線(xiàn)上升,感興趣的可以了解下2024-11-11
PHP使用memcache緩存技術(shù)提高響應(yīng)速度的方法
這篇文章主要介紹了PHP使用memcache緩存技術(shù)提高響應(yīng)速度的方法,以實(shí)例形式分析了memcache緩存技術(shù)的使用技巧,具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2014-12-12
mysql下創(chuàng)建字段并設(shè)置主鍵的php代碼
php+mysql創(chuàng)建字段并設(shè)置主鍵示例2010-05-05
一個(gè)漂亮的php驗(yàn)證碼類(lèi)(分享)
下面小編就為大家分享一個(gè)漂亮的php驗(yàn)證碼類(lèi)。需要的朋友可以過(guò)來(lái)參考下2013-08-08

