微信公众号开发之获取位置信息php代码
发布:smiling 来源: PHP粉丝网 添加日期:2018-10-11 14:23:43 浏览: 评论:0
本文实例为大家分享了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 (!emptyempty($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(!emptyempty( $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; //phpfensi.com
- }else{
- return false;
- }
- }
- }
- ?>
Tags: 公众 位置 代码
- 上一篇:PHP基于递归算法解决兔子生兔子问题
- 下一篇:PHP实现多个关键词搜索查询功能示例
相关文章
- ·微信公众平台自定义菜单开发示例(2014-01-09)
- ·微信公众平台预约提交后发送email例子(2014-06-20)
- ·微信公众平台消息接口(PHP)-官方的Demo有问题(2014-07-29)
- ·微信公众平台模拟登录之验证码获取(2014-08-27)
- ·微信公众平台智能机器人PHP开发示例(2014-08-27)
- ·微信公众平台的开发接口简单例子(2014-09-21)
- ·微信公众平台开发关注/取消关注事件例子(2014-09-22)
- ·基于微信公众平台开发SDK(demo)扩展例子(2014-09-22)
- ·微信公众开发之获取周边酒店信息(2014-09-22)
- ·删除粉丝表中抓取错误的数据-微信公众平台开发(2014-09-22)
- ·开发微信公众平台接口参数调试-判断用户行为(2014-09-22)
- ·微信公众平台网页获取用户OpenID方法(2015-04-08)
- ·php 微信公众平台开发之验证步骤(2015-05-09)
- ·php版本微信公众平台回复乱码问题解决方法(2015-05-09)
- ·微信公众平台PHP开发版本例子(2015-12-10)
- ·微信公众平台开发通过php创建自定义菜单(2016-08-25)
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)