溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

微信公眾號(hào)開(kāi)發(fā)之如何獲取位置信息php代碼

發(fā)布時(shí)間:2021-05-22 10:30:03 來(lái)源:億速云 閱讀:234 作者:小新 欄目:開(kāi)發(fā)技術(shù)

小編給大家分享一下微信公眾號(hào)開(kāi)發(fā)之如何獲取位置信息php代碼,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!

具體內(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;
    $customevent = $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>";    
    if($type=="event" and $customevent=="subscribe"){
     $contentStr = "感謝你的關(guān)注\n回復(fù)1查看聯(lián)系方式\n回復(fù)2查看最新資訊\n回復(fù)3查看法律文書(shū)";
     $msgType = "text";
     $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);
     echo $resultStr;
     } 
    if($type=="image" ){
     $contentStr = "你的圖片很棒!";
     $msgType = "text";
     $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);
     echo $resultStr;
     } 
    if($type=="location" ){
     $contentStr = "你的緯度是{$latitude},經(jīng)度是{$longitude},我已經(jīng)鎖定!";
     $msgType = "text";
     $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);
     echo $resultStr;
     }  
    if(!empty( $keyword ))
    {        
     $msgType = "text";
     if($keyword=="1"){
     $contentStr = "qiphon";}
     if($keyword=="2"){
     $contentStr = "test222";}
     if($keyword=="3"){
     $contentStr = "test333";}     
     $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);
     echo $resultStr;
    }else{
     echo "Input something...";
    }

  }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;
  }
 }
}

?>

PHP開(kāi)發(fā)環(huán)境搭建工具有哪些

一、phpStudy,是一個(gè)新手入門(mén)最常用的開(kāi)發(fā)環(huán)境。二、WampServer,WampServer也同樣的也是和phpStudy一樣操作簡(jiǎn)單對(duì)小白比較友好。三、XAMPP,XAMPP(Apache+MySQL+PHP+PERL)是一個(gè)功能強(qiáng)大的建站集成軟件包;四、MAMP,MAMP分為兩種MAMP和MAMP Pro for Mac。五、寶塔面板,寶塔面板是一款服務(wù)器管理軟件,支持windows和linux系統(tǒng)。六、UPUPW,UPUPW是目前Windows平臺(tái)下最具特色的Web服務(wù)器PHP套件。

以上是“微信公眾號(hào)開(kāi)發(fā)之如何獲取位置信息php代碼”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI