微信公众开发之获取周边酒店信息
关注微信公众之后发送回复地理位置信息,即可回复周边附近的酒店信息列表,下面我就来给各位介绍利用php是怎么实现这个功能,希望全子对大家有帮助.代码如下:
<?php //将提交过来的信息接收 $signature = $_GET['signature']; $timestamp = $_GET['timestamp']; $nonce = $_GET['nonce']; $echostr = $_GET['echostr']; $token = "yanjiadong"; //判断接入网站 //进行字典排序 $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; & nbsp; 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://yanjiadong.net/weixin/images/640_" . $FromUserName . ".png"; } else { $picurl = "http://yanjiadong.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>"; //开源代码phprm.com } $str.= "</Articles></xml>"; return $str; }
Copy after login
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 AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Assassin's Creed Shadows: Seashell Riddle Solution
2 weeks ago
By DDD
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics
CakePHP Tutorial
1376
52

