Php WeChat public development: how to obtain information about nearby hotels

Source: Internet
Author: User
Tags sha1 encryption
This article mainly introduces the php public development method for getting information about surrounding hotels, and involves the application skills of the public platform on geographic information, which has some reference value, for more information about how to obtain information about nearby hotels, see examples in this article. Share it with you for your reference. The specific analysis is as follows:

After paying attention to the public, you can send a reply to the location information, and then you can reply to the list of nearby hotels. next I will introduce you to how php can be used to implement this function. the code is as follows:

The code is as follows:

<? Php
// Receive the submitted information
$ Signature = $ _ GET ['signature'];
$ Timestamp = $ _ GET ['timestamp'];
$ Nonce = $ _ GET ['nonce '];
$ Echostr = $ _ GET ['echostr'];
$ Token = "bitsCN.com ";
// Determine website access

// Sort the dictionary
$ Arr = array ($ token, $ timestamp, $ nonce );

Sort ($ arr );

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

// Receive information received by the 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"; // Here, the ak parameter requires the serial number of the individual Baidu developer. you can apply for it on your own.
$ 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 ['result']);
}
Function pic_send ($ arr ){
Global $ ToUserName, $ FromUserName;
$ Str ="
".$FromUserName."
".$ToUserName."
". Time ()."
news
". 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. ="

<! [CDATA [". $ v ['name']. "Address :". $ v ['address']. "Phone :". $ v ['telphone']. "]>
".$v['name']." 地址:".$v['address']." 电话:".$v['telephone']."
".$picurl."
http://api.map.baidu.com/place/detail&#63;uid=".$v['uid']."&output=html&src=".$v['name']."&output=html
";
}
$ Str. =" ";
Return $ str;
}
?>

I hope this article will help you with php programming.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.