[转]微信公众平台开发__导航

时间:2014-07-22 23:13:05   收藏:0   阅读:640

介绍:导航功能主要是调用百度地图的api,发送用户当前位置,然后根据和目的地的经纬度,在地图上显示用户到目的地睇线路图。

 

[php] view plaincopy
 
  1. <?php  
  2.   
  3. //define your token  
  4. define("TOKEN""wechatnow");  
  5. $wechatObj = new wechatCallbackapiTest();  
  6. $wechatObj->responseMsg();  
  7.   
  8. class wechatCallbackapiTest  
  9. {  
  10.     public function valid()  
  11.     {  
  12.         $echoStr = $_GET["echostr"];  
  13.   
  14.         //valid signature , option  
  15.         if($this->checkSignature()){  
  16.             echo $echoStr;  
  17.             exit;  
  18.         }  
  19.     }  
  20.   
  21.     public function responseMsg()  
  22.     {  
  23.         //get post data, May be due to the different environments  
  24.         $postStr = $GLOBALS["HTTP_RAW_POST_DATA"];  
  25.   
  26.         //extract post data  
  27.         if (!empty($postStr)){  
  28.                   
  29.               $postObj = simplexml_load_string($postStr‘SimpleXMLElement‘, LIBXML_NOCDATA);  
  30.                 $fromUsername = $postObj->FromUserName;  
  31.                 $toUsername = $postObj->ToUserName;  
  32.                 $MsgType=$postObj->MsgType;  
  33.         $latitude=$postObj->Location_X;  
  34.         $longitude =$postObj->Location_Y;  
  35.                 $time = time();  
  36.                 $textTpl = "<xml>  
  37.                             <ToUserName><![CDATA[%s]]></ToUserName>  
  38.                             <FromUserName><![CDATA[%s]]></FromUserName>  
  39.                             <CreateTime>%s</CreateTime>  
  40.                             <MsgType><![CDATA[news]]></MsgType>  
  41.                              <ArticleCount>1</ArticleCount>  
  42.                              <Articles>  
  43.                              <item>  
  44.                              <Title><![CDATA[导航]]></Title>   
  45.                              <Description><![CDATA[点击后导航到华师]]></Description>  
  46.                              <PicUrl><![CDATA[]]></PicUrl>  
  47.                              <Url><![CDATA[%s]]></Url>  
  48.                             </item>  
  49.                             </Articles>  
  50.                             <FuncFlag>0</FuncFlag>  
  51.                             </xml>";                    
  52.                 if($MsgType=="location")  
  53.                   
  54.                 {  
  55.                    
  56.                  $url="http://api.map.baidu.com/direction?origin=latlng:{$latitude},{$longitude}|name:你的位置&destination=latlng:23.14123802754,113.34233164787202|name:我的学校&mode=transit?ion=广州&output=html&src=yourCompanyName|yourAppName";//调用百度地图的api  
  57.                     $resultStr = sprintf($textTpl$fromUsername$toUsername$time,$url);  
  58.                     echo $resultStr;  
  59.                 }  
  60.   
  61.         }  
  62.     }  
  63.           
  64.     private function checkSignature()  
  65.     {  
  66.         $signature = $_GET["signature"];  
  67.         $timestamp = $_GET["timestamp"];  
  68.         $nonce = $_GET["nonce"];      
  69.                   
  70.         $token = TOKEN;  
  71.         $tmpArr = array($token$timestamp$nonce);  
  72.         sort($tmpArr);  
  73.         $tmpStr = implode( $tmpArr );  
  74.         $tmpStr = sha1( $tmpStr );  
  75.           
  76.         if$tmpStr == $signature ){  
  77.             return true;  
  78.         }else{  
  79.             return false;  
  80.         }  
  81.     }  
  82. }  
  83.   
  84. ?>  

 

源文地址:http://blog.csdn.net/zhihang527548263/article/details/12684813

原文:http://www.cnblogs.com/ibmghost/p/3514571.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!