微信公众号开发之获取位置信息php代码

作者:qiphon3650 时间:2023-11-17 06:33:15 

本文实例为大家分享了php微信公众号获取位置信息的具体代码,供大家参考,具体内容如下

<?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 = "感谢你的关注\n回复1查看联系方式\n回复2查看最新资讯\n回复3查看法律文书";
    $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},经度是{$longitude},我已经锁定!";
    $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;
 }
}
}
?>

来源:https://blog.csdn.net/qiphon3650/article/details/80659652

标签:php,微信公众号,位置
0
投稿

猜你喜欢

  • 浅谈python3.6的tkinter运行问题

    2021-08-04 01:29:16
  • asp如何显示自定义随机信息?

    2010-06-08 09:39:00
  • 完美的js验证网址url(正则表达式)

    2008-06-07 09:36:00
  • Pycharm及python安装详细教程(图解)

    2023-01-06 00:26:00
  • vue项目中api接口管理总结

    2024-04-30 10:42:44
  • 安装sql server 2008 management提示已安装 SQL Server 2005 Express的解决方法

    2024-01-15 12:49:03
  • 在django中查询获取数据,get, filter,all(),values()操作

    2023-09-04 16:10:27
  • Python Pandas教程之series 上的转换操作

    2023-08-16 22:20:50
  • MySQL分页分析原理及提高效率

    2024-01-20 08:45:09
  • Python实现k-means算法

    2023-07-01 22:06:53
  • django实现web接口 python3模拟Post请求方式

    2023-07-28 15:18:14
  • 详解python的变量

    2021-01-26 20:44:20
  • 你会使用python爬虫抓取弹幕吗

    2021-04-28 03:06:50
  • 源码解析python的内存回收机制

    2023-05-19 18:12:16
  • python交互模式下输入换行/输入多行命令的方法

    2022-06-08 07:18:37
  • 使用SQL语句快速获取SQL Server数据字典

    2009-01-08 16:31:00
  • 如何在TypeScript中正确的遍历一个对象

    2024-04-25 13:09:36
  • python docx 中文字体设置的操作方法

    2021-01-12 22:33:44
  • 使用python的pyplot绘制函数实例

    2021-07-27 01:21:30
  • Firefox Bug: inline/inline-block的间隙

    2009-11-03 13:20:00
  • asp之家 网络编程 m.aspxhome.com