php微信开发之谷歌测距
程序员文章站
2022-06-08 20:30:59
本文实例为大家分享了php微信谷歌测距的具体代码,供大家参考,具体内容如下
本文实例为大家分享了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; $customrevent = $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>"; switch ($type) { case "event"; if ($customrevent=="subscribe") {$contentstr = '';} break; case "image"; $contentstr = "你的图片很棒!"; break; case "location"; $disurl="http://maps.googleapis.com/maps/api/distancematrix/xml?origins={$latitude},{$longitude}&destinations=23.355164,116.681889&mode=walking&language=zh-cn&sensor=false"; $apistr=file_get_contents($disurl); $apiobj=simplexml_load_string($apistr); $disobj=$apiobj->row->element->distance->text; $durobj=$apiobj->row->element->duration->text; $contentstr = "你离我公司约{$disobj}公里,步行约{$durobj}"; break; case "link" ; $contentstr = "你的链接有病毒吧!"; break; case "text"; $weatherurl="http://api.map.baidu.com/telematics/v2/weather?location={$keyword}&ak=1a3cde429f38434f1811a75e1a90310c"; $apistr=file_get_contents($weatherurl); $apiobj=simplexml_load_string($apistr); $placeobj=$apiobj->currentcity;//读取城市 $todayobj=$apiobj->results->result[0]->date;//读取星期 $weatherobj=$apiobj->results->result[0]->weather;//读取天气 $windobj=$apiobj->results->result[0]->wind;//读取风力 $temobj=$apiobj->results->result[0]->temperature;//读取温度 $contentstr = "{$placeobj}{$todayobj}天气{$weatherobj},风力{$windobj},温度{$temobj}"; break; default; $contentstr ="此项功能尚未开发"; } $msgtype="text"; $resultstr = sprintf($texttpl, $fromusername, $tousername, $time, $msgtype, $contentstr); echo $resultstr; }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微信公众开发之获取周边酒店信息的方法,公众周边
-
PHP微信公众平台开发 - 消息回复的封装_PHP教程
-
微信开发 多图图文信息PHP代码
-
微信小程序开发之Tabbar实例图文详解
-
微信订阅号开发之token验证后,自动回复消息功能做好,发送消息没有返回,token自动回复_PHP教程
-
微信公众帐号开发教程第14篇-自定义菜单的创建及菜单事件响应_PHP教程
-
微信/易信公共平台开发(2):自定义菜单的PHP实现(提供源码)
-
微信支付PHP SDK之微信公众号支付代码详解_php实例
-
PHP微信开发之根据用户回复关键词位置返回附近信息_php实例
-
PHP使用Face++接口开发微信公众平台人脸识别系统的方法