为了账号安全,请及时绑定邮箱和手机立即绑定

我查不出代码哪里错了/(ㄒoㄒ)/~~就是不成功,好心人帮我看看

//token 验证是通过的,但是关注事件的反馈不成功,查了几遍代码,改了几个错误,还是不行。

<?php



class IndexAction extends Action {

    protected function _initialize() {
        header("Content-Type:text/html; charset=utf-8");
    }
    public function index(){
		//获得参数 signature nonce token timestamp echostor
		$nonce		=$_GET['nonce'];
		$token		='we';
		$timestamp	=$_GET['timestamp'];
		$echostr	=$_GET['echostr'];
		$signature	=$_GET['signature'];
		//形成数组,然后按字典序排列
		$array	=array();
		$array	=array($nonce,$timestamp,$token);
		sort($array);
		//拼接成字符串,加密,然后与signature校验
		$str	=sha1(implode($array));
		if($str==$signature && $echostr){
            //第一次介入微信API接口,之后就没有$echostr这个参数了
			echo	$echostr;
			exit;
        }else{
            
        	$this->reponseMsg();
        }
	}
    
    //接收事件推送并回复
    public function reponseMsg(){
        //1.获取到微信送过来的post数据(xml形式)
        $postArr	=$GLOBALS['HTTP_RAW_POST_DATA'];
        //2.处理消息类型,并设置回复类型和内容
        $postObj =$simplexml_load_string($postArr);
        //$postObj->ToUserName = '';
        //$postObj->FromUserName = '';
        //$postObj->CreateTime = '';
        //$postObj->Msgtype = '';
        //$postObj->Event = '';
        //判断该数据包是否是消息订阅的时间推送
        
        if(strtolower($postObj->MsgType == 'event'){//strtolower将字符串转换成小写形式
           //如果是关注事件subscribe 事件
            if(strtolower($postObj->Event == 'subscribe')){
            	$toUser = $postObj->FromUserName;
            	$fromUser = $postObj->ToUserName;
                $time = time();
                $Msgtype = 'text';
                $Content = '欢迎关注我们的公众账号,zxy';
                $template=" <xml>
							<ToUserName><![CDATA[%s]]></ToUserName>
							<FromUserName><![CDATA[%s]]></FromUserName>
							<CreateTime>%s</CreateTime>
							<MsgType><![CDATA[%s]]></MsgType>
							<Content><![CDATA[%s]]></Content>
							</xml>";
                $info	 =sprintf($template,$toUser,$fromUser,$time,$msgType,$content);
                echo $info;
            }
        }
    }
    

}

?>


正在回答

5 回答

$postObj =$simplexml_load_string($postArr);这个地方不对的

0 回复 有任何疑惑可以回复我~

同问啊!

0 回复 有任何疑惑可以回复我~

不知道哪里出问题了,关注了以后也不出现回复

0 回复 有任何疑惑可以回复我~

一样啊,我也是这样的问题每次this->reponseMsg();这个有错误

0 回复 有任何疑惑可以回复我~

补充:我查到是this->reponseMsg();这句有符号错误,然后改成了this.reponseMsg();这个时候符号错误没有了,又出现说reponseMsg()函数未定义,我明明后面写了public function reponseMsg(){}啊!天啊,这是为什么?

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

我查不出代码哪里错了/(ㄒoㄒ)/~~就是不成功,好心人帮我看看

我要回答 关注问题
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号