Heim php教程 php手册 微信公众开发之获取周边酒店信息

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

Jun 02, 2016 am 09:13 AM

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

<?php
//将提交过来的信息接收
$signature = $_GET[&#39;signature&#39;];
$timestamp = $_GET[&#39;timestamp&#39;];
$nonce = $_GET[&#39;nonce&#39;];
$echostr = $_GET[&#39;echostr&#39;];
$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, &#39;SimpleXMLElement&#39;, LIBXML_NOCDATA);
$ToUserName = $xmlObj->ToUserName;
$FromUserName = $xmlObj->FromUserName;
$CreateTime = $xmlObj->CreateTime;
$MsgType = $xmlObj->MsgType;
$Content = $xmlObj->Content; & nbsp;
if ($MsgType == &#39;location&#39;) {
    $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(&#39;./images/640_&#39; . $FromUserName . ".png", $p_640);
    $p_80 = file_get_contents($pic_80);
    file_put_contents(&#39;./images/80_&#39; . $FromUserName . ".png", $p_80);
    echo pic_send($json[&#39;results&#39;]);
}
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[&#39;name&#39;] . " 地址:" . $v[&#39;address&#39;] . " 电话:" . $v[&#39;telephone&#39;] . "]]></Title> 
<Description><![CDATA[" . $v[&#39;name&#39;] . " 地址:" . $v[&#39;address&#39;] . " 电话:" . $v[&#39;telephone&#39;] . "]]></Description> 
<PicUrl><![CDATA[" . $picurl . "]]></PicUrl> 
<Url><![CDATA[http://api.map.baidu.com/place/detail?uid=" . $v[&#39;uid&#39;] . "&output=html&src=" . $v[&#39;name&#39;] . "&output=html]]></Url> 
</item>"; //开源代码phprm.com
    }
    $str.= "</Articles></xml>";
    return $str;
}
Nach dem Login kopieren


Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn

Heiße KI -Werkzeuge

Undresser.AI Undress

Undresser.AI Undress

KI-gestützte App zum Erstellen realistischer Aktfotos

AI Clothes Remover

AI Clothes Remover

Online-KI-Tool zum Entfernen von Kleidung aus Fotos.

Undress AI Tool

Undress AI Tool

Ausziehbilder kostenlos

Clothoff.io

Clothoff.io

KI-Kleiderentferner

AI Hentai Generator

AI Hentai Generator

Erstellen Sie kostenlos Ai Hentai.

Heißer Artikel

R.E.P.O. Energiekristalle erklärten und was sie tun (gelber Kristall)
4 Wochen vor By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Beste grafische Einstellungen
4 Wochen vor By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. So reparieren Sie Audio, wenn Sie niemanden hören können
1 Monate vor By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat -Befehle und wie man sie benutzt
1 Monate vor By 尊渡假赌尊渡假赌尊渡假赌

Heiße Werkzeuge

Notepad++7.3.1

Notepad++7.3.1

Einfach zu bedienender und kostenloser Code-Editor

SublimeText3 chinesische Version

SublimeText3 chinesische Version

Chinesische Version, sehr einfach zu bedienen

Senden Sie Studio 13.0.1

Senden Sie Studio 13.0.1

Leistungsstarke integrierte PHP-Entwicklungsumgebung

Dreamweaver CS6

Dreamweaver CS6

Visuelle Webentwicklungstools

SublimeText3 Mac-Version

SublimeText3 Mac-Version

Codebearbeitungssoftware auf Gottesniveau (SublimeText3)