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

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

rush:PHP;"> //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><a href="https://www.jb51.cc/tag/s/" target="_blank" class="keywords">%s</a></CreateTime>
   <MsgType><![CDATA[%s]]></MsgType>
   <Content><![CDATA[%s]]></Content>
   <FuncFlag>0</FuncFlag>
   </xml>";    
if($type=="event" and $customevent=="subscribe"){
 $contentStr = "感谢你的关注\n<a href="https://www.jb51.cc/tag/huifu/" target="_blank" class="keywords">回复</a>1查看联系方式\n<a href="https://www.jb51.cc/tag/huifu/" target="_blank" class="keywords">回复</a>2查看最新资讯\n<a href="https://www.jb51.cc/tag/huifu/" target="_blank" class="keywords">回复</a>3查看法律文书";
 $msgType = "text";
 $resultStr = sprintf($textTpl,$fromUsername,$toUsername,$time,$msgType,$contentStr);
 echo $resultStr;
 } 
if($type=="image" ){
 $contentStr = "你的<a href="https://www.jb51.cc/tag/tupian/" target="_blank" class="keywords">图片</a>很棒!";
 $msgType = "text";
 $resultStr = sprintf($textTpl,$contentStr);
 echo $resultStr;
 } 
if($type=="location" ){
 $contentStr = "你的纬度是{$latitude},经度是{$longitude},我已经锁定!";
 $msgType = "text";
 $resultStr = sprintf($textTpl,$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,$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;
}
}
}

?>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程之家。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


接入微信号对接步骤 第一步:后台添加产品->配置微信号->获取代码 第二步:复制代码加到页面</head>前面
逐条转发与合并转发的区别是什么
实现微信发布文章信息采集
微信公众号-获取用户信息(网页授权获取)实现步骤
php微信公众号开发(2)百度BAE搭建和数据库使用
java开发微信分享到朋友圈功能
php微信公众号开发(3)php实现简单微信文本通讯
C#微信公众号开发--微信事件交互
js微信分享API
PHP微信分享开发详解
C#微信公众号开发--网页授权(oauth2.0)获取用户基本信息一
C# 微信公众号开发--准备工作
php版微信小店调用api示例代码
php微信公众号开发(4)php实现自定义关键字回复
微信小程序 教程之小程序配置
iOS实现类似微信和支付宝的密码输入框(UIKeyInput协议)
C#微信公众号开发--网页授权(oauth2.0)获取用户基本信息二
php版微信小店API二次开发及使用示例
PHP微信刮刮卡
微信开发学习路线