This article is an example of the development of the PHP micro-trust to obtain information about the surrounding hotel methods. Share to everyone for your reference. The specific analysis is as follows:
Attention to micro-letter public after sending a response to geographical information, you can reply to the surrounding hotel information list, I would like to give you an introduction to the use of PHP how to achieve this function, I hope all the children to help. The code is as follows:
Copy Code code as follows:
<?php
To receive the information submitted.
$signature = $_get[' signature '];
$timestamp = $_get[' timestamp '];
$nonce = $_get[' nonce '];
$echostr = $_get[' echostr '];
$token = "Jb51.net";
Judging access to the site
Do dictionary sorting
$arr = Array ($token, $timestamp, $nonce);
Sort ($arr);
Complete concatenation of strings and SHA1 encryption
$result = SHA1 (Join ($arr));
To determine if the generated strings and $signature are equal, and if they are equal, direct output $echostr, so that Web Access succeeds
if ($result = = $signature) {
Echo $echostr;
}
Receive information received by micro-credit 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 AK parameters need the individual Baidu development serial number, their own to Baidu application is good
$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 = "yun_qi_img/640_. $FromUserName. png";
}else{
$picurl = "yun_qi_img/q=jb51";
}
$str. = "
<item>
<title><! [cdata[]. $v [' name ']. "Address:". $v [' addresses ']. "Tel:" $v [' telephone ']. "] ></Title>
<description><! [cdata[]. $v [' name ']. "Address:". $v [' addresses ']. "Tel:" $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> ";
}
$str. = "</Articles></xml>";
return $str;
}
?>
I hope this article will help you with your PHP program design.