php订阅号文本回复,关注事件

laravel55框架做的微信订阅号,获取微信token就好 

Content;
            $fromuser = $obj->FromUserName;
            $touser = $obj->ToUserName;
            $msgType = $obj->MsgType;
                if ($msgType == 'event') {
                    $this->reponseMsg($obj);
                } else {
                    if ($content == '你好吗') {
                        $con = '我很棒';
                    } else {
                        $con = '我不知道呢在说啥';
                    }

                    //MsgType	消息类型,文本为text
                    $xml = "
                
                
                " . time() . "
                
                
            ";
                    echo $xml;
            }
            //上传到log日志
            //file_put_contents('./log',$obj->Content);
        } else {
            $signature = $_GET['signature'];
            $timestamp = $_GET["timestamp"];
            $nonce = $_GET["nonce"];
            $Token = 'vxstudy';
            //三个参数字典排序
            $tmpArr = array($timestamp, $nonce, $Token);
            sort($tmpArr);
            $tmpStr = implode($tmpArr);
            $tmpStr = sha1($tmpStr);

            if ($tmpStr == $signature) {
                return $_GET['echostr'];
            } else {
                return false;
            }
        }
    }
    public function reponseMsg($obj){
            if($obj->Event == 'subscribe' ){
                //回复用户消息(纯文本格式)
                $FromUserName   = $obj->FromUserName;
                $ToUserName = $obj->ToUserName;
                $time     = time();
                $msgType  =  'text';
                $content  = '欢迎关注嗷嗷火的微信订阅号';
                $xml = "
                            
                            
                            $time
                            
                            
                            ";
                echo $xml;
            }
        }
            public function dq(){

            }
}

 

你可能感兴趣的:(php订阅号文本回复,关注事件)