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

求大家帮助,关注还是没有回复消息呢

<?php

// 本类由系统自动生成,仅供测试用途

class IndexAction extends Action {

    public function index(){

  $nonce=$_GET['nonce'];

  $token='wtl';

  $timestamp=$_GET['timestamp'];

  $echostr=$_GET['echostr'];

  $signature=$_GET['signature'];

//形成数组,然后按字典序排序

$array=array();

$array=array($nonce,$timestamp,$token);

sort($array);

//拼接成字符串,sha1加密,然后与signature进行检验

$str=sha1(implode($array));

if($str==$signature&&$echostr)

{

header('content-type:text');

//第一次接入微信API接口时候验证合法性

echo $echostr;

exit;

}

     else

{

this->responseMsg();

}


}



//接收事件推送回复

      public function responseMsg()

{

//1.获取到微信推送过来post数据(xml格式)

$postArr=$GLOBALS['HTTP_RAW_POST_DATA'];

//2.处理消息类型,并设置回复类型和内容

$postObj=simplexml_load_string($postArr);

        //判断该数据包是否是订阅de事件推送

        if(strtolower($postObj->MsgType)=='event')

        {

        //如果是关注 subscribe事件

        if(strtolower($postObj->Event)=='subscribe')

        {

        $toUser    =$postObj->FromUserName;

        $fromUser  =$postObj->ToUserName;

        $time      =time();

        $msgType   ='text';

        $content   ='欢迎关注我的微信公众号!';

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

        }

        }


}

}


正在回答

1 回答

终于找到了

this->responseMsg();

少了$

1 回复 有任何疑惑可以回复我~
#1

慕粉3809271 提问者

非常感谢!非常感谢!
2016-12-19 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

求大家帮助,关注还是没有回复消息呢

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

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

帮助反馈 APP下载

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

公众号

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