公众号回复:暂时无法提供服务

lsj1982 2017-08-12 09:11:09
主页代码如下,在公众号输入信息“?”,提示“暂进无法提供服务”,浏览器测试出错:
Fatal error: Call to a member function responsemsg() on null in /data1/www/htdocs/350/lsj2017/1/index.php on line 10
该页面的提供者尚未完成 实名认证 您的访问可能存在风险
不知觉厉!

<?php

define("TOKEN","LSJ20170123");

$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);

//sha1加密后与签名对比
if( $tmpArr == $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";
$content=date("y-m-d h:i:s",time());
$result=sprintf($texttpl,$fromusername,$tousername,$time,$msgtype,$content);
echo "wellcome lsj's world";
echo $result;
}
}else{
echo "";
exit;
}
}

}

?>
...全文
223 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

3,143

社区成员

发帖
与我相关
我的任务
社区描述
微信开发即微信公众平台开发,将企业信息、服务、活动等内容通过微信网页的方式进行表现,通过二次开发可以将公众账号由一个媒体型营销工具转化成提供服务的产品。
社区管理员
  • 微信开发
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧