当前位置:首页 > PHP教程 > php高级应用 > 列表

微信公众开发之获取周边酒店信息

发布:smiling 来源: PHP粉丝网  添加日期:2014-09-22 10:42:07 浏览: 评论:0 

关注微信公众之后发送回复地理位置信息,即可回复周边附近的酒店信息列表,下面我就来给各位介绍利用php是怎么实现这个功能,希望全子对大家有帮助.代码如下:

  1. <?php 
  2.  //将提交过来的信息接收 
  3.  
  4. $signature = $_GET['signature']; 
  5.  
  6.  $timestamp = $_GET['timestamp']; 
  7.  
  8.  $nonce = $_GET['nonce']; 
  9.  
  10.  $echostr = $_GET['echostr']; 
  11.  
  12.  $token = "yanjiadong"
  13.  
  14.  //判断接入网站 
  15.  
  16.  //进行字典排序 
  17.  $arr = array($token,$timestamp,$nonce); 
  18.  
  19.  sort($arr); 
  20.  
  21.  //完成字符串的拼接和sha1加密 
  22.  
  23.  $result = sha1(join($arr)); 
  24.  
  25.  //判断生成的字符串和$signature是否相等,如果相等,直接输出$echostr,这样网站接入成功 
  26.  
  27.  if($result==$signature){ 
  28.  
  29.  echo $echostr
  30.  
  31.  } 
  32.  
  33.  //接收微信公众账号接收到的信息 
  34.  $poststr = $GLOBALS["HTTP_RAW_POST_DATA"]; 
  35.  
  36.  $xmlObj = simplexml_load_string($poststr,'SimpleXMLElement',LIBXML_NOCDATA); 
  37.  
  38.  $ToUserName = $xmlObj->ToUserName; 
  39.  
  40.  $FromUserName = $xmlObj->FromUserName; 
  41.  
  42.  $CreateTime = $xmlObj->CreateTime; 
  43.  
  44.  $MsgType = $xmlObj->MsgType; 
  45.  
  46.  $Content = $xmlObj->Content; 
  47.  
  48. &nbsp; 
  49.  if($MsgType=='location'){ 
  50.  
  51.  $Location_X = $xmlObj->Location_X; 
  52.  
  53.  $Location_Y = $xmlObj->Location_Y; 
  54.  
  55.  $Scale = $xmlObj->Scale; 
  56.  
  57.  $Label = $xmlObj->Label; 
  58.  
  59.  $urlstr = "http://api.map.baidu.com/place/v2/search?&query=酒店&location=".$Location_X.",".$Location_Y."&radius=5000&output=json&ak=DESY8unmZnUlLB0mlowjuiRr";  //此处ak参数需要个人的百度开发序列号,自己去百度申请下就好了 
  60.  
  61.  $jsonstr = file_get_contents($urlstr); 
  62.  
  63.  $json = json_decode($jsonstr,true); 
  64.  
  65.  $pic_640 = "http://api.map.baidu.com/staticimage?width=640&height=320&center=".$Location_Y.",".$Location_X."&zoom=15&markers=".$Location_Y.",".$Location_X."&markerStyles=l,"
  66.  
  67.  $pic_80 = "http://api.map.baidu.com/staticimage?width=80&height=80&center=".$Location_Y.",".$Location_X."&zoom=15&markers=".$Location_Y.",".$Location_X."&markerStyles=l,"
  68.  
  69.  $p_640 = file_get_contents($pic_640); 
  70.  
  71.  file_put_contents('./images/640_'.$FromUserName.".png",$p_640); 
  72.  
  73.  $p_80 = file_get_contents($pic_80); 
  74.  
  75.  file_put_contents('./images/80_'.$FromUserName.".png",$p_80); 
  76.  
  77.  echo pic_send($json['results']); 
  78.  
  79.  } 
  80.  function pic_send($arr){ 
  81.  global $ToUserName,$FromUserName
  82.  $str = "<xml> 
  83.  <ToUserName><![CDATA[".$FromUserName."]]></ToUserName> 
  84.  <FromUserName><![CDATA[".$ToUserName."]]></FromUserName> 
  85.  <CreateTime>".time()."</CreateTime> 
  86.  <MsgType><![CDATA[news]]></MsgType> 
  87.  <ArticleCount>".count($arr)."</ArticleCount> 
  88.  <Articles>"; 
  89.  foreach($arr as $k=>$v){ 
  90.  if($k==0){ 
  91.  $picurl = "http://yanjiadong.net/weixin/images/640_".$FromUserName.".png"
  92.  }else
  93.  $picurl = "http://yanjiadong.net/weixin/images/80_".$FromUserName.".png"
  94.  } 
  95.  $str .=" 
  96.  <item> 
  97.  <Title><![CDATA[".$v['name']." 地址:".$v['address']." 电话:".$v['telephone']."]]></Title> 
  98.  <Description><![CDATA[".$v['name']." 地址:".$v['address']." 电话:".$v['telephone']."]]></Description> 
  99.  <PicUrl><![CDATA[".$picurl."]]></PicUrl> 
  100.  <Url><![CDATA[http://api.map.baidu.com/place/detail?uid=".$v['uid']."&output=html&src=".$v['name']."&output=html]]></Url> 
  101.  </item>";//开源代码phpfensi.com 
  102.  } 
  103.  
  104.  $str .= "</Articles></xml>"
  105.  
  106.  return $str
  107.  } 
  108.  
  109. ?>

Tags: php微信公众开发 php周边酒店

分享到: