当前位置:网站首页>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 .
边栏推荐
- "Adobe international certification" Adobe Photoshop adjusts cropping, rotation and canvas size
- 喜欢就去行动
- Install wpr Exe command
- Act as you like
- Preparation for a series of courses on WordPress applet generation
- Oxylabs live online: website capture demo
- A group of skeletons flying canvas animation JS special effect
- 把騰訊搬到雲上,治愈了他們的技術焦慮
- Canvas infinite scan JS special effect code
- 图片的可视化呈现有效增强大屏吸引力
猜你喜欢

2D 照片变身 3D 模型,来看英伟达的 AI 新“魔法”!

math_等比数列求和推导&等幂和差推导/两个n次方数之差/

【本周六活动】.NET Day in China

Canvas infinite scan JS special effect code

Today in history: Turing's birth day; The birth of the founder of the Internet; Reddit goes online

图片的可视化呈现有效增强大屏吸引力
![[activities this Saturday] NET Day in China](/img/33/c0e8eeb8f673232a7c27bbaf5e713f.jpg)
[activities this Saturday] NET Day in China

软件测试 对前一日函数的基本路径测试

Understanding of homogeneous coordinates

喜歡就去行動
随机推荐
[IEEE] International Conference on naturallanguageprocessing and information retrieval (ecnlpir 2022)
How to use arbitrarygen code generator what are the characteristics of this generator
Any 与 TypeVar,让 IDE 的自动补全更好用
Shell脚本(.sh文件)如何执行完毕之后不自动关闭、闪退?
Clickhouse deployment and basic usage 1
Why should we make the best use of the external chain in SEO?
[latest in the whole network] how to start the opentsdb source code in the local ide run
图片的可视化呈现有效增强大屏吸引力
Canvas infinite scan JS special effect code
Besides technology, programmers also need to master a skill - self marketing ability
Déplacer Tencent sur le cloud a guéri leur anxiété technologique
Anonymous Messenger: hidden communication of Trojan horse
喜歡就去行動
What is wireless WiFi? What are the benefits of wireless WiFi
Why choose b+ tree as storage engine index structure
[latest - lightweight cloud servers - hot sales] new lightweight application server optimization scheme, 1-core 2g5m time limit as low as 99 yuan / year
08. Tencent cloud IOT device side learning - device shadow and attributes
Svg+js drag slider round progress bar
如何开发短信通知和语音功能医院信息系统(HIS系统)
Using the collaboration database query of Poole in laravel5.6