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

帮我看一下代码哪儿错了 关注后没有回复消息


<?php
class wei{
   public function index(){
       $timestamp = $_GET['timestamp'];
       $token     = '15228990111';
       $nonce     = $_GET['nonce'];
       $signature = $_GET['signature'];
       $echostr   = $_GET['echostr'];
       $array=array($nonce,$timestamp,$token);
       sort($array);
       $str=implode('',$array);
       $str=sha1($str);
       if($str == $signature && $echostr){
           echo $echostr;
           exit;
       }else{
           $this->info();
       }
   }
   public function info(){
       //获得微信推送过来的 POST 数据
       $postArr = $GLOBALS['HTTP_RAW_POST_DATA'];
       //处理消息类型 XML格式转换,并设置回复类型和内容
       $postObj=simplexml_load_string( $postArr );
//        $postObj->ToUserName='';
//        $postObj->FromUserName='';
//        $postObj->CreateTime='';
//        $postObj->MsgType='';
//        $postObj->Event='';
       //判断该数据是否是订阅事件
       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;
           }
       }
   }
}

$wei=new wei();
$wei->index();

正在回答

2 回答

你那有个小写 TO  to改成To

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

我是按照官方的文档里的demo写的,你最好还是用官方的试一试,改几个参数就行。然后在原有的基础上做其他的东西

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

举报

0/150
提交
取消

帮我看一下代码哪儿错了 关注后没有回复消息

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

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

帮助反馈 APP下载

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

公众号

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