当前位置:网站首页>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 .
边栏推荐
- 程序员大部分时间不是写代码,而是。。。
- 【本周六活动】.NET Day in China
- 初识string+简单用法(一)
- 使用Process Monitor工具监测进程对注册表和文件的操作
- [net action!] Cos data escort helps SMEs avoid content security risks!
- Base64 decoding method three ways for non professionals
- 服乔布斯不服库克,苹果传奇设计团队解散内幕曝光
- Beauty of script │ VBS introduction interactive practice
- Detailed explanation of SQL Sever basic data types
- Why choose b+ tree as storage engine index structure
猜你喜欢

使用Process Monitor工具监测进程对注册表和文件的操作

Shape change loader loads jsjs special effect code

服乔布斯不服库克,苹果传奇设计团队解散内幕曝光

"Write once, run at all ends", Qualcomm released AI software stack!

Maui的学习之路 -- 开篇

Any 与 TypeVar,让 IDE 的自动补全更好用
![[IEEE publication] International Conference on natural language processing and information retrieval in 2022 (ecnlpir 2022)](/img/d6/8c20944ce354c9619a61a73f2c72b1.png)
[IEEE publication] International Conference on natural language processing and information retrieval in 2022 (ecnlpir 2022)

Cool interactive animation JS special effects implemented by p5.js

Simple pricelist style code

Today in history: Turing's birth day; The birth of the founder of the Internet; Reddit goes online
随机推荐
Maui的学习之路 -- 开篇
Canvas falling ball gravity JS special effect animation
@RequestBody注解
【本周六活动】.NET Day in China
What is the resource search platform and how resource search works
Smart energy: scenario application of intelligent security monitoring technology easycvr in the petroleum energy industry
程序员大部分时间不是写代码,而是。。。
Déplacer Tencent sur le cloud a guéri leur anxiété technologique
服乔布斯不服库克,苹果传奇设计团队解散内幕曝光
“一个优秀程序员可抵五个普通程序员!”
@Requestbody annotation
[net action!] Cos data escort helps SMEs avoid content security risks!
How to improve the quality of Baidu keyword?
Analysis and understanding of Jieba stutter word segmentation principle HMM application in Chinese word segmentation and partial code reading
PPT绘图相关,快捷键,美观度
Learn to use the kindeditor rich text editor. Click to upload a picture. The mask is too large or the white screen solution
How to use arbitrarygen code generator what are the characteristics of this generator
Multi gate mixture of experts and code implementation
Detailed explanation of SQL Sever basic data types
Install wpr Exe command