Home > Backend Development > PHP Tutorial > PHP WeChat public development method to obtain surrounding hotel information, public surroundings_PHP tutorial

PHP WeChat public development method to obtain surrounding hotel information, public surroundings_PHP tutorial

WBOY
Release: 2016-07-13 10:11:03
Original
890 people have browsed it

php WeChat public development method to obtain surrounding hotel information, public surroundings

The example in this article describes the method of obtaining surrounding hotel information through PHP WeChat public development. Share it with everyone for your reference. The specific analysis is as follows:

After following the public on WeChat and sending a reply with geographical location information, you can reply with a list of nearby hotel information. Now I will introduce to you how to implement this function using php. I hope Quanzi can be helpful to everyone. The code is as follows:

Copy code The code is as follows:
//Receive the submitted information
$signature = $_GET['signature'];
$timestamp = $_GET['timestamp'];
$nonce = $_GET['nonce'];
$echostr = $_GET['echostr'];
$token = "jb51.net";
//Determine the access website

//Carry out dictionary sorting
$arr = array($token,$timestamp,$nonce);

sort($arr);

//Complete string splicing and sha1 encryption
$result = sha1(join($arr));
//Determine whether the generated string and $signature are equal. If they are equal, directly output $echostr, so that the website access is successful
if($result==$signature){
echo $echostr;
}

//Receive information received from WeChat public account
$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=hotel&location=".$Location_X.",".$Location_Y."&radius=5000&output=json&ak=DESY8unmZnUlLB0mlowjuiRr"; / /The ak parameter here requires a personal Baidu development serial number. Just go to Baidu to apply for it
$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 = "


".time()."

".count($arr)."
";
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 .="

<![CDATA[".$v['name']." Address: ".$v['address']." Telephone: ".$v['telephone']."]]> ;



";
}
$str .= "
";
return $str;
}
?>

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/931542.htmlTechArticleHow to obtain surrounding hotel information through php WeChat public development, public surroundings This article describes how to obtain php WeChat public development Methods for surrounding hotel information. Share it with everyone for your reference...
Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template