欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php微信開發(fā)之谷歌測(cè)距

 更新時(shí)間:2018年06月14日 10:36:47   作者:qiphon3650  
這篇文章主要為大家詳細(xì)介紹了php微信開發(fā)之谷歌測(cè)距的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了php微信谷歌測(cè)距的具體代碼,供大家參考,具體內(nèi)容如下

<?php
/**
 * wechat php test
 */

//define your token
define("TOKEN", "weixin");
$wechatObj = new wechatCallbackapiTest();
//$wechatObj->valid();
$wechatObj->responseMsg();
class wechatCallbackapiTest
{
  public function valid()
  {
    $echoStr = $_GET["echostr"];

    //valid signature , option
    if($this->checkSignature()){
      echo $echoStr;
      exit;
    }
  }

  public function responseMsg()
  {
    //get post data, May be due to the different environments
    $postStr = $GLOBALS["HTTP_RAW_POST_DATA"];

    //extract post data
    if (!empty($postStr)){

        $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
        $fromUsername = $postObj->FromUserName;
        $toUsername = $postObj->ToUserName;
        $type = $postObj->MsgType;
        $customrevent = $postObj->Event;
        $latitude = $postObj->Location_X;
        $longitude = $postObj->Location_Y;
        $keyword = trim($postObj->Content);
        $time = time();
        $textTpl = "<xml>
              <ToUserName><![CDATA[%s]]></ToUserName>
              <FromUserName><![CDATA[%s]]></FromUserName>
              <CreateTime>%s</CreateTime>
              <MsgType><![CDATA[%s]]></MsgType>
              <Content><![CDATA[%s]]></Content>
              <FuncFlag>0</FuncFlag>
              </xml>";       
        switch ($type)
      {  case "event";
        if ($customrevent=="subscribe")
          {$contentStr = '';}
        break;
        case "image";
        $contentStr = "你的圖片很棒!";
        break;
        case "location";
        $disurl="http://maps.googleapis.com/maps/api/distancematrix/xml?origins={$latitude},{$longitude}&destinations=23.355164,116.681889&mode=walking&language=zh-CN&sensor=false";
      $apistr=file_get_contents($disurl);
      $apiobj=simplexml_load_string($apistr);
      $disobj=$apiobj->row->element->distance->text;
      $durobj=$apiobj->row->element->duration->text;
      $contentStr = "你離我公司約{$disobj}公里,步行約{$durobj}";

        break;
        case "link" ;
        $contentStr = "你的鏈接有病毒吧!";
        break;
        case "text";
        $weatherurl="http://api.map.baidu.com/telematics/v2/weather?location={$keyword}&ak=1a3cde429f38434f1811a75e1a90310c";
         $apistr=file_get_contents($weatherurl);
         $apiobj=simplexml_load_string($apistr);
         $placeobj=$apiobj->currentCity;//讀取城市
         $todayobj=$apiobj->results->result[0]->date;//讀取星期
         $weatherobj=$apiobj->results->result[0]->weather;//讀取天氣
         $windobj=$apiobj->results->result[0]->wind;//讀取風(fēng)力
         $temobj=$apiobj->results->result[0]->temperature;//讀取溫度
         $contentStr = "{$placeobj}{$todayobj}天氣{$weatherobj},風(fēng)力{$windobj},溫度{$temobj}";
         break;          
      default;
      $contentStr ="此項(xiàng)功能尚未開發(fā)";  
      }
        $msgType="text";
        $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);
        echo $resultStr;


    }else {
      echo "";
      exit;
    }
  }

  private function checkSignature()
  {
    $signature = $_GET["signature"];
    $timestamp = $_GET["timestamp"];
    $nonce = $_GET["nonce"];  

    $token = TOKEN;
    $tmpArr = array($token, $timestamp, $nonce);
    sort($tmpArr);
    $tmpStr = implode( $tmpArr );
    $tmpStr = sha1( $tmpStr );

    if( $tmpStr == $signature ){
      return true;
    }else{
      return false;
    }
  }
}

?>

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • php+layui數(shù)據(jù)表格實(shí)現(xiàn)數(shù)據(jù)分頁渲染代碼

    php+layui數(shù)據(jù)表格實(shí)現(xiàn)數(shù)據(jù)分頁渲染代碼

    今天小編就為大家分享一篇php+layui數(shù)據(jù)表格實(shí)現(xiàn)數(shù)據(jù)分頁渲染代碼,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2019-10-10
  • php微信開發(fā)之關(guān)注事件

    php微信開發(fā)之關(guān)注事件

    這篇文章主要為大家詳細(xì)介紹了php微信開發(fā)之關(guān)注事件,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-06-06
  • php實(shí)現(xiàn)文件下載功能的幾個(gè)代碼分享

    php實(shí)現(xiàn)文件下載功能的幾個(gè)代碼分享

    我們一般實(shí)現(xiàn)下載都是調(diào)用url來下載,但是遇到ie能識(shí)別打開的文件就不能用這種方式了,比如下載一個(gè)圖片、html網(wǎng)頁等,這時(shí)就需要編程來實(shí)現(xiàn)
    2014-05-05
  • PHP Yaf框架的簡(jiǎn)單安裝使用教程(推薦)

    PHP Yaf框架的簡(jiǎn)單安裝使用教程(推薦)

    下面小編就為大家?guī)硪黄狿HP Yaf框架的簡(jiǎn)單安裝使用教程(推薦)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2016-06-06
  • 獲取URL文件名后綴

    獲取URL文件名后綴

    用php分析URL網(wǎng)址,可以得到文件名、目錄路徑,還有其它數(shù)據(jù),原理就是使用PHP的explode函數(shù)分隔字符串。
    2013-10-10
  • PHP增刪改查項(xiàng)目的實(shí)戰(zhàn)詳解

    PHP增刪改查項(xiàng)目的實(shí)戰(zhàn)詳解

    這篇文章主要為大家詳細(xì)介紹了PHP增刪改查項(xiàng)目,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助
    2022-03-03
  • AES加解密在php接口請(qǐng)求過程中的應(yīng)用示例

    AES加解密在php接口請(qǐng)求過程中的應(yīng)用示例

    在我們的編程的過程中,經(jīng)常會(huì)遇到加密的情況,怎么才會(huì)合理運(yùn)用,本篇文章主要介紹了AES加解密在php接口請(qǐng)求過程中的應(yīng)用示例,有需要的可以了解一下。
    2016-10-10
  • 使用PHP導(dǎo)出Word文檔的原理和實(shí)例

    使用PHP導(dǎo)出Word文檔的原理和實(shí)例

    PHP操作Word文檔的方法有很多,這里再為大家提供一種方法。
    2013-10-10
  • Yii2中hasOne、hasMany及多對(duì)多關(guān)聯(lián)查詢的用法詳解

    Yii2中hasOne、hasMany及多對(duì)多關(guān)聯(lián)查詢的用法詳解

    hasOne、hasMany是Yii2特有的用于多表關(guān)聯(lián)查詢的函數(shù),平時(shí)在使用多表關(guān)聯(lián)查詢的時(shí)候建議使用它們。這篇文章主要介紹了Yii2中hasOne、hasMany及多對(duì)多關(guān)聯(lián)查詢的用法詳解,需要的朋友可以參考下
    2017-02-02
  • laravel框架實(shí)現(xiàn)后臺(tái)登錄、退出功能示例

    laravel框架實(shí)現(xiàn)后臺(tái)登錄、退出功能示例

    這篇文章主要介紹了laravel框架實(shí)現(xiàn)后臺(tái)登錄、退出功能,結(jié)合實(shí)例形式詳細(xì)分析了Laravel框架后臺(tái)登錄、退出相關(guān)的請(qǐng)求發(fā)送、驗(yàn)證、session讀寫與刪除等相關(guān)操作技巧,需要的朋友可以參考下
    2019-10-10

最新評(píng)論