<?php
    // $postStr= file_get_contents("php://input");
       // $str='{signature":"05b3fd30b0c737cd4c1e63494ee916697574123f","echostr":"3513325349272158207","timestamp":"1637373938","nonce":"1296340635"}';
       // $_GET['signature']="05b3fd30b0c737cd4c1e63494ee916697574123f";
       // $_GET['echostr']="3513325349272158207";
       //  $_GET['timestamp']="1637373938";
       // $_GET['nonce']="1296340635";

       // file_put_contents("demo/postStr.txt", json_encode($_GET));
		$weObj = obj ();

	    $weObj->valid();

		$type = $weObj->getRev ()->getRevType ();

		$openid = $weObj->getRevFrom();//openid
		
		   switch ($type) {
            case Wechat::MSGTYPE_TEXT :     // 文本回复，这里可以根据 关键 词搞定
			   
			      $text=$weObj->getRev ()->getRevContent();

             $weObj->text ( $webset['gzreply'])->reply ();
				
					if(preg_match("/^1\d{10}$/",$text)){  

				      $weObj->text ( $str )->reply ();
				  }
                // $weObj->text ( $gz )->reply ();
                break;
            case Wechat::MSGTYPE_EVENT :
                $eventype = $weObj->getRev ()->getRevEvent ();
                if ($eventype ['event'] == "CLICK") {
                   
				    if( $eventype ['key']=='get_jfb'){
				     
						 $weObj->text ( $text )->reply ();
						}
				   
                }elseif ($eventype['event'] == "subscribe") {
                	    $param=$weObj->getRevSceneId();
                	    $res=$weObj->getUserInfo($openid);



                       //file_put_contents("demo/wx.txt", json_encode($res));exit();
                        try{
                          file_put_contents("info.txt", json_encode($res));
                          app("user")->subscribe($res,$param);
                        }catch(Exception $e){
                           $weObj->text ( $e->getMessage())->reply ();
                        }
                	    $text=$webset['gzreply'];
                      //  $text="欢迎关注福建天天向上教育";
                	    $weObj->text ( $text )->reply ();
                }elseif ($eventype['event'] == "unsubscribe") {

                        app("user")->unsubscribe($openid);
                      
                }
                exit ();
                break;
            default :
                //$weObj->text ( "help info" )->reply ();
        }
	
	
	
	

 
	
?>