php后台实现微信公众平台的关注后自动回复功能,但是没有信息返回,代码如下
public function index(){
$request = Request::instance();
$get = $request->param();
$timestamp = $get['timestamp'];
$nonce = $get['nonce'];
$token = "weiwei";
$signature = $get['signature'];
$echostr = $get['echostr'];
$array = array();
$array = array($token,$timestamp,$nonce);
sort($array);
$tmpstr = sha1(implode('',$array));
if($tmpstr == $signature){
if (!isset($get['echostr'])) {
$this->responText();
}else{
ob_clean();
echo $get['echostr'];
exit;
}
}
}
private function responText(){
$getInfo = $GLOBALS["HTTP_RAW_POST_DATA"];
$InfoObj = simplexml_load_string($getInfo);
if (strtolower(trim($InfoObj->MsgType))=='event') {
if (strtolower($InfoObj->Event)=='subscribe') {
$tousername = $InfoObj->FromUserName;
$fromusername = $InfoObj->ToUserName;
$ctime = time();
$content = '欢迎关注本公众号,你果然是个聪明人';
$Msg = "<xml>
<ToUserName><![CDATA[%s]]></ToUserName>
<FromUserName><![CDATA[%s]]></FromUserName>
<CreateTime>%s</CreateTime>
<MsgType><![CDATA[text]]></MsgType>
<Content><![CDATA[%s]]></Content>
</xml>";
$sendMsg = sprintf($Msg,$tousername,$fromusername,$ctime,$content);
echo $sendMsg;
}
}
}
token是可以提交的,url上用的是阿里云服务器的ip地址,不是备案的域名,不知有没有影响,求大神指教!