<?php
/**
* wechat php test
*/
//define your token
define("TOKEN", "wxToShow");
$wechatObj = new wechatCallbackapiTest();
$wechatObj->valid();
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)){
/* libxml_disable_entity_loader is to prevent XML eXternal Entity Injection,
the best way is to check the validity of xml by yourself */
libxml_disable_entity_loader(true);
$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(!empty( $keyword ))
{
$msgType = "text";
$contentStr = "Welcome to wechat world!";
$resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);
echo $resultStr;
}else{
echo "Input something...";
}
}else {
echo "";
exit;
}
}
private function checkSignature()
{
// you must define TOKEN by yourself
if (!defined("TOKEN")) {
throw new Exception('TOKEN is not defined!');
}
$signature = $_GET["signature"];
$timestamp = $_GET["timestamp"];
$nonce = $_GET["nonce"];
$token = TOKEN;
$tmpArr = array($token, $timestamp, $nonce);
// use SORT_STRING rule
sort($tmpArr, SORT_STRING);
$tmpStr = implode( $tmpArr );
$tmpStr = sha1( $tmpStr );
if( $tmpStr == $signature ){
return true;
}else{
return false;
}
}
}
?>

moTzxx
- 粉丝: 695
- 资源: 40
最新资源
- STM32F103驱动LoRa模块(SX1278)IO口模拟SPI通讯
- xournalpp-ui-1.1.3-1.el8.x64-86.rpm.tar.gz
- 基于YOLO11深度学习的学生课堂行为检测系统(带GUI界面)(Python源码+Pyqt5界面+2000多张标注好的数据集+安装使用教程+训练好的模型+评估指标曲线+演示图片视频),开箱即用
- xournalpp-plugins-1.1.3-1.el8.x64-86.rpm.tar.gz
- xournalpp-1.1.3-1.el8.x64-86.rpm.tar.gz
- xosd-devel-2.2.14-33.el8.x64-86.rpm.tar.gz
- python学习资料、基础知识代码
- 88025710008-04.pdf
- 【css酷炫效果】纯CSS实现球形阴影效果
- 【css酷炫效果】纯CSS实现毛玻璃效果
- 模拟工程师电路设计指导手册 - 放大器
- 【css酷炫效果】纯CSS实现文字立体投影效果
- 【css酷炫效果】纯CSS实现字体动态裂纹纹理
- HP惠普增霸卡最新底层驱动使用说明书
- 【css酷炫效果】纯CSS实现动态星云背景效果
- 【css酷炫效果】纯CSS实现球上下浮动填充效果
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



- 1
- 2
- 3
前往页