Home Backend Development PHP Tutorial php微信公众开发之获取周边酒店信息的方法_PHP

php微信公众开发之获取周边酒店信息的方法_PHP

Jun 01, 2016 am 11:06 AM
php develop WeChat Obtain

本文实例讲述了php微信公众开发之获取周边酒店信息的方法。分享给大家供大家参考。具体分析如下:

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

代码如下:

 //将提交过来的信息接收
$signature = $_GET['signature'];
 $timestamp = $_GET['timestamp'];
 $nonce = $_GET['nonce'];
 $echostr = $_GET['echostr'];
 $token = "bitsCN.com";
 //判断接入网站
 
 //进行字典排序
 $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&center=".$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&center=".$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 = "
 
 
 ".time()."
 
 ".count($arr)."
 ";
 foreach($arr as $k=>$v){
 if($k==0){
 $picurl = "http://bitsCN.com/weixin/images/640_".$FromUserName.".png";
 }else{
 $picurl = "http://bitsCN.com.net/weixin/images/80_".$FromUserName.".png";
 }
 $str .="
 
 
 
 
 
 
";
 }
 $str .= "
";
 return $str;
 }
?>

希望本文所述对大家的php程序设计有所帮助。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

deepseek image generation tutorial deepseek image generation tutorial Feb 19, 2025 pm 04:15 PM

deepseek image generation tutorial

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

Discuss CakePHP

CakePHP Quick Guide CakePHP Quick Guide Sep 10, 2024 pm 05:27 PM

CakePHP Quick Guide

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

How To Set Up Visual Studio Code (VS Code) for PHP Development

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

How do you parse and process HTML/XML in PHP?

gateio Chinese official website gate.io trading platform website gateio Chinese official website gate.io trading platform website Feb 21, 2025 pm 03:06 PM

gateio Chinese official website gate.io trading platform website

CakePHP Useful Resources CakePHP Useful Resources Sep 10, 2024 pm 05:27 PM

CakePHP Useful Resources

See all articles