微信公众号开发者自动回复设置没反应
在新浪sea平台设置了微信公众号应用,设置关注自动回复功能,接口设置成功,,代码写好,url也修改代码的页面,但是测试后没反应。
//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;
$keyword = trim($postObj->Content);
$time = time();
$textTpl = "
%s
0
";
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()
{
$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;
}
}
}
?>
相关阅读:
android如何处理大批图片
这为什么总是提示错误?
网页要引入很多js文件,像bootstrap,jquery……,如果它们更新就要修改,很难看很麻烦,有什么方法解决?
javascript函数的问题
Android: 禁用电话和短信
ios webview 加载html文件,在9.2下没问题,但在8.1下底部出现横向排版层叠
能否使用注解找到所有被此注解注解的类?
在Flask的Templates中如何处理常量
jquery无法触发页面已有的a标签的点击事件
Mysql 单个表查询问题
SAE如何实现php锁?
可以对已经上传的图片进行裁剪吗
如何计算开学第几周, 要求每年通用
position:relative配合top:10%无效是什么原因?
Paramiko和os模块能否一起使用?
android qq app 是怎么做到那么流畅的?
使用AFNetWorking 上传字符串,提示:Request failed: 请求太大
如何在macbook上部署PHP应用?
webpack构建的项目的部署问题
css布局的设置问题
公众号自动回复不生效php php 微信公众平台开发者_微信公众号开发者自动回复设置没反应 php 微信公众平台开发者 - phpStudy...