当前位置:网站首页>Token verification program index.php when configuring wechat official account server
Token verification program index.php when configuring wechat official account server
2022-07-28 20:02:00 【Confused Zha Zha Hui】
When configuring wechat official account server token Verification procedure index.php
When I did it , I have used many words written by individuals , But it is token Validation error , It may be related to this coding format , It is recommended to copy the code to notepad++ On , Then copy to the server index.php On . This code doesn't need to be understood , In the future, wechat development is directly deleted .
The code is as follows :
<?php
traceHttp();
define("TOKEN", "weixin");
$wechatObj = new wechatCallbackapiTest();
if (isset($_GET['echostr'])) {
$wechatObj->valid();
}else{
$wechatObj->responseMsg();
}
class wechatCallbackapiTest
{
public function valid()
{
$echoStr = $_GET["echostr"];
if($this->checkSignature()){
echo $echoStr;
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;
}
}
public function responseMsg()
{
$postStr = $GLOBALS["HTTP_RAW_POST_DATA"];
if (!empty($postStr)){
$postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
$fromUsername = $postObj->FromUserName;
$toUsername = $postObj->ToUserName;
$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($keyword == "?" || $keyword == "?")
{
$msgType = "text";
$contentStr = date("Y-m-d H:i:s",time());
$resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);
echo $resultStr;
}
}else{
echo "";
exit;
}
}
}
function traceHttp()
{
logger("\n\nREMOTE_ADDR:".$_SERVER["REMOTE_ADDR"].(strstr($_SERVER["REMOTE_ADDR"],'101.226')? " FROM WeiXin": "Unknown IP"));
logger("QUERY_STRING:".$_SERVER["QUERY_STRING"]);
}
function logger($log_content)
{
if(isset($_SERVER['HTTP_APPNAME'])){ //SAE
sae_set_display_errors(false);
sae_debug($log_content);
sae_set_display_errors(true);
}else{ //LOCAL
$max_size = 500000;
$log_filename = "log.xml";
if(file_exists($log_filename) and (abs(filesize($log_filename)) > $max_size)){unlink($log_filename);}
file_put_contents($log_filename, date('Y-m-d H:i:s').$log_content."\r\n", FILE_APPEND);
}
}
?>
边栏推荐
- Const pointer of C language and parameter passing of main function
- Deploy LNMP automatically with saltstack
- String中常用的API
- Know small and medium LAN WLAN
- 并发程序设计,你真的懂吗?
- “中国网事·感动2022”二季度网络感动人物评选结果揭晓
- How does app automated testing achieve H5 testing
- Can China make a breakthrough in the future development of the meta universe and occupy the highland?
- A chip company fell in round B
- leetcode day5 删除重复的电子邮箱
猜你喜欢
English Translation Spanish - batch English Translation Spanish tools free of charge
editor.md中markdown编辑器的实现
How navicate modifies the database name
2022年下半年系统集成项目管理工程师认证8月20日开班
利用STM32的HAL库驱动1.54寸 TFT屏(240*240 ST7789V)
Source insight project import and use tutorial
时间转日期的sql语句应该怎么写?
How openocd directly downloads programs to STM32 board through stlink (solved)
Android section 13 03xutils detailed explanation of database framework (addition, deletion and modification)
Leetcode Day1 score ranking
随机推荐
There are five certificates in the soft examination advanced examination, which is more worth taking?
软考中级(系统集成项目管理工程师)高频考点
[in depth study of 4g/5g/6g topics -44]: urllc-15 - in depth interpretation of 3GPP urllc related protocols, specifications and technical principles -9-low delay technology -3-non slot scheduling mini
Read how to deploy highly available k3s with external database
leetcode day3 查找重复的电子邮箱
Idea properties file display \u solution of not displaying Chinese
leetcode day4 部门工资最高的员工
A chip company fell in round B
Theoretical knowledge of digital image (I) (personal analysis)
leetcode day5 删除重复的电子邮箱
基于MATLAB的函数拟合
MySQL8 tmp_ table_ Size and Max_ heap_ table_ size
English translation Italian - batch English translation Italian tools free of charge
Implementation of markdown editor in editor.md
冲刺金九银十丨熬夜半个月汇集大厂Android岗1600道面试真题
Application skills of programming rising and falling edge instructions of botu 1200/1500plc (bool array)
Implementation of strstr in C language
数字图像理论知识(一)(个人浅析)
C language functions and pointers
Leetcode Day1 score ranking