国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PHP > 正文

微信公眾號開發之獲取位置信息php代碼

2024-05-04 21:50:19
字體:
來源:轉載
供稿:網友

本文實例為大家分享了php微信公眾號獲取位置信息的具體代碼,供大家參考,具體內容如下:

  1. <?php 
  2. /** 
  3.  * wechat php test 
  4.  */ 
  5.   
  6. //define your token 
  7. define("TOKEN""weixin"); 
  8. $wechatObj = new wechatCallbackapiTest(); 
  9. //$wechatObj->valid(); 
  10. $wechatObj->responseMsg(); 
  11. class wechatCallbackapiTest 
  12.  public function valid() 
  13.  { 
  14.   $echoStr = $_GET["echostr"]; 
  15.   
  16.   //valid signature , option 
  17.   if($this->checkSignature()){ 
  18.    echo $echoStr
  19.    exit
  20.   } 
  21.  } 
  22.   
  23.  public function responseMsg() 
  24.  { 
  25.   //get post data, May be due to the different environments 
  26.   $postStr = $GLOBALS["HTTP_RAW_POST_DATA"]; 
  27.   
  28.   //extract post data 
  29.   if (!emptyempty($postStr)){ 
  30.   
  31.     $postObj = simplexml_load_string($postStr'SimpleXMLElement', LIBXML_NOCDATA); 
  32.     $fromUsername = $postObj->FromUserName; 
  33.     $toUsername = $postObj->ToUserName; 
  34.     $type = $postObj->MsgType; 
  35.     $customevent = $postObj->Event; 
  36.     $latitude = $postObj->Location_X; 
  37.     $longitude = $postObj->Location_Y; 
  38.     $keyword = trim($postObj->Content); 
  39.     $time = time(); 
  40.     $textTpl = "<xml> 
  41.        <ToUserName><![CDATA[%s]]></ToUserName> 
  42.        <FromUserName><![CDATA[%s]]></FromUserName> 
  43.        <CreateTime>%s</CreateTime> 
  44.        <MsgType><![CDATA[%s]]></MsgType> 
  45.        <Content><![CDATA[%s]]></Content> 
  46.        <FuncFlag>0</FuncFlag> 
  47.        </xml>";     
  48.     if($type=="event" and $customevent=="subscribe"){ 
  49.      $contentStr = "感謝你的關注/n回復1查看聯系方式/n回復2查看最新資訊/n回復3查看法律文書"
  50.      $msgType = "text"
  51.      $resultStr = sprintf($textTpl$fromUsername$toUsername$time$msgType$contentStr); 
  52.      echo $resultStr
  53.      }  
  54.     if($type=="image" ){ 
  55.      $contentStr = "你的圖片很棒!"
  56.      $msgType = "text"
  57.      $resultStr = sprintf($textTpl$fromUsername$toUsername$time$msgType$contentStr); 
  58.      echo $resultStr
  59.      }  
  60.     if($type=="location" ){ 
  61.      $contentStr = "你的緯度是{$latitude},經度是{$longitude},我已經鎖定!"
  62.      $msgType = "text"
  63.      $resultStr = sprintf($textTpl$fromUsername$toUsername$time$msgType$contentStr); 
  64.      echo $resultStr
  65.      }   
  66.     if(!emptyempty$keyword )) 
  67.     {         
  68.      $msgType = "text"
  69.      if($keyword=="1"){ 
  70.      $contentStr = "qiphon";} 
  71.      if($keyword=="2"){ 
  72.      $contentStr = "test222";} 
  73.      if($keyword=="3"){ 
  74.      $contentStr = "test333";}      
  75.      $resultStr = sprintf($textTpl$fromUsername$toUsername$time$msgType$contentStr); 
  76.      echo $resultStr
  77.     }else
  78.      echo "Input something..."
  79.     } 
  80.   
  81.   }else { 
  82.    echo ""
  83.    exit
  84.   } 
  85.  } 
  86.   
  87.  private function checkSignature() 
  88.  { 
  89.   $signature = $_GET["signature"]; 
  90.   $timestamp = $_GET["timestamp"]; 
  91.   $nonce = $_GET["nonce"];  
  92.   
  93.   $token = TOKEN; 
  94.   $tmpArr = array($token$timestamp$nonce); 
  95.   sort($tmpArr); 
  96.   $tmpStr = implode( $tmpArr ); 
  97.   $tmpStr = sha1( $tmpStr ); 
  98.   
  99.   if$tmpStr == $signature ){ 
  100.    return true; //Vevb.com 
  101.   }else
  102.    return false; 
  103.   } 
  104.  } 
  105.   
  106. ?> 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 汽车| 和林格尔县| 馆陶县| 壤塘县| 新疆| 丰原市| 南部县| 盐城市| 鄂托克前旗| 博兴县| 云梦县| 翼城县| 新津县| 广昌县| 长寿区| 保定市| 上饶市| 平湖市| 沁源县| 偏关县| 邢台市| 垣曲县| 广元市| 德兴市| 屏南县| 甘谷县| 观塘区| 灵宝市| 右玉县| 文昌市| 湘潭市| 开封县| 新化县| 吉木乃县| 兰溪市| 昌江| 长子县| 炉霍县| 池州市| 江华| 枣阳市|