当前位置:网站首页>Google ranging for PHP wechat development
Google ranging for PHP wechat development
2022-06-24 11:15:00 【PHP Development Engineer 】
This article is an example for you to share php Specific code of wechat Google ranging , For your reference , The details are as follows
<?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 = " Your picture is great !"; 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 = " You have an appointment with our company {$disobj} km , Walk around {$durobj}"; break; case "link" ; $contentStr = " Your link has a virus !"; 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;// Read city $todayobj=$apiobj->results->result[0]->date;// Read week $weatherobj=$apiobj->results->result[0]->weather;// Reading weather $windobj=$apiobj->results->result[0]->wind;// Read wind $temobj=$apiobj->results->result[0]->temperature;// Reading temperature $contentStr = "{$placeobj}{$todayobj} The weather {$weatherobj}, wind {$windobj}, temperature {$temobj}"; break; default; $contentStr =" This feature has not yet been developed "; } $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; } } } ?>
The above is the whole content of this paper , I hope it will be helpful for your study , I also hope you can support open source .
Complete example :http://github.crmeb.net/u/defu
come from “ Open source world ” , link :https://ym.baisou.ltd/post/681.html, If you want to reprint , Please indicate the source , Otherwise, the legal liability will be investigated .
边栏推荐
- 使用Process Monitor工具监测进程对注册表和文件的操作
- 初识string+简单用法(一)
- System design: key features of distributed systems
- Understanding of homogeneous coordinates
- Adobe Photoshop using the box selection tool for selection tutorial
- Give you a server. Can you deploy your code online?
- I pushed my younger brother into Tencent. Look at his benchmark resume!
- Visual presentation of pictures effectively enhances the attraction of large screen
- Canvas infinite scan JS special effect code
- Reliable remote code execution (1)
猜你喜欢
Rising bubble canvas breaking animation JS special effect
Any 与 TypeVar,让 IDE 的自动补全更好用
Beauty of script │ VBS introduction interactive practice
PHP短信通知+语音播报自动双呼
@Requestbody annotation
Programmers spend most of their time not writing code, but...
图片的可视化呈现有效增强大屏吸引力
使用Process Monitor工具监测进程对注册表和文件的操作
Plant growth H5 animation JS special effect
Moving Tencent to the cloud cured their technical anxiety
随机推荐
Any 与 TypeVar,让 IDE 的自动补全更好用
Attribute observer didset and willset in swift of swiftui swift internal skill
Fashionable pop-up mode login registration window
How to export only the titles in word documents? (i.e. delete all the text contents and keep only the title) stop B
Qt: 判断字符串是否为数字格式
Introduction to the use of splice() method
齐次坐标的理解
Several stacks of technology sharing: product managers' Online Official answers to several stacks of knowledge
math_ Summation and derivation of proportional series & derivation of sum and difference of equal powers / difference between two nth power numbers/
【206】使用php语言去生成go语言的代码
Clickhouse deployment and basic usage 1
TP-LINK 1208路由器教程(2)
Common third-party UI frameworks
Why should we make the best use of the external chain in SEO?
Which is a good CAD drawing software? How to select good software
Learn to use the kindeditor rich text editor. Click to upload a picture. The mask is too large or the white screen solution
Group policy export import
[technical tutorial] national standard protocol platform easygbs cascading supports customized national standard channels
Can text pictures be converted to word? How to extract text from pictures
What is the knowledge map? What does it do