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

为什么我的公众号回复总是空白呢

   //获得参数 signature nonce token timestamp echostr
   $timestamp = $_GET['timestamp'];
   $nonce     = $_GET['nonce'];
   $token     = 'hua';
   $signature = $_GET['signature'];
   $echostr   = $_GET['echostr'];    //形成数组,然后按字典序排序
   $array     = array();
   $array     = array( $nonce,  $timestamp, $token);
   sort( $array);                   //拼接成字符串,sha1加密,然后与signature进行校验
   $tmpstr = sha1(implode( $array ));
 
   if ( $tmpstr == $signature && $echostr )    //第一次接入微信api接口的时候
    { echo $echostr;
       exit;
    } else { // $this->reponseMsg(); }
                    
   //   function reponseMsg(){
     //1.获取到微信推送过来post数据(xml格式)
    $postArr = $GlOBALS['HTTP_RAW_POST_DATA'];
       //2.处理消息类型,并设置回复类型和内容
    $postObj = simplexml_load_string( $postArr );
     //判断该数据包是否是订阅事件的推送
    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
       }
                                            }
                               }

这是代码https://img1.sycdn.imooc.com//5c7b8199000103a007201279.jpg

正在回答

举报

0/150
提交
取消

为什么我的公众号回复总是空白呢

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

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

帮助反馈 APP下载

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

公众号

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