<?php   
date_default_timezone_set("Asia/Shanghai");   
 
 //这个是中文编码
 
class XiaoI   
{   
    //by Hackfan   
    public $sid = '';   
  
    public function __construct($sid = false)   
    {   
        if(!$sid)   
        {   
            $this->join();   
        }   
        else  
        {   
            $this->sid = $sid;   
        }   
    }   
    public function join()   
    {   
        $fp = fsockopen('61.172.205.36', 80);   
        fwrite($fp, 'GET /engine/flashrobot2/webbot.js?encoding=utf-8 HTTP/1.1
Accept: */*
Referer: http://i.xiaoi.com/
Accept-Language: zh-cn
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1;  Embedded Web Browser from: http://bsalsa.com/; 56flvplayer 1.0; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; InfoPath.2)
Host: webbot.xiaoi.com
Connection: close

');      
        $r = '';  
		
        while(!feof($fp))   
        {   
            $line = fgets($fp, 512);
			if ($line == "\n" || $line == "\r\n") break;
            $r .= $line;  
        }
		
        fclose($fp);   
        preg_match('/ibotsessionid=(\d+)/',$r ,$match);   
        $this->sid = $match[1];   
		echo "Get SID: ".$this->sid."\n";
        $fp = fsockopen('61.172.205.36', 80);   
        fwrite($fp, 'GET /engine/flashrobot2/send.js?encoding=utf-8&SID='.$this->sid.'&USR='.$this->sid.'&CMD=JOIN&r= HTTP/1.1
Accept: */*
Referer: http://i.xiaoi.com/
Accept-Language: zh-cn
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1;  Embedded Web Browser from: http://bsalsa.com/; 56flvplayer 1.0; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; InfoPath.2)
Host: 61.172.205.36
Connection: Close

');   
        fclose($fp);   
  
        $fpr = fsockopen('61.172.205.36', 80);   
        fwrite($fpr, 
'GET /engine/flashrobot2/recv.js?encoding=utf-8&SID='.$this->sid.'&USR='.$this->sid.'&r= HTTP/1.1
Accept: */*
Referer: http://i.xiaoi.com/
Accept-Language: zh-cn
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1;  Embedded Web Browser from: http://bsalsa.com/; 56flvplayer 1.0; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; InfoPath.2)
Host: 61.172.205.36
Connection: Keep-Alive

 ');   
        fclose($fpr);   
  
    }   
    public function chat($msg)   
    {   
  
        $fps = fsockopen('61.172.205.36', 80);   
        fwrite($fps, 
'GET /engine/flashrobot2/send.js?encoding=utf-8&SID='.$this->sid.'&USR='.$this->sid.'&CMD=CHAT&SIG=You&MSG='.urlencode($msg).'&FTN=&FTS=&FTC=&r= HTTP/1.1
Accept: */*
Referer: http://i.xiaoi.com/
Accept-Language: zh-cn
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1;  Embedded Web Browser from: http://bsalsa.com/; 56flvplayer 1.0; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; InfoPath.2)
Host: 61.172.205.36
Connection: Close

');   
        fclose($fps);   
  
		sleep(1);
         $fpr = fsockopen('61.172.205.36', 80);   
        fwrite($fpr, 
'GET /engine/flashrobot2/recv.js?encoding=utf-8&SID='.$this->sid.'&USR='.$this->sid.'&r= HTTP/1.1
Accept: */*
Referer: http://i.xiaoi.com/
Accept-Language: zh-cn
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1;  Embedded Web Browser from: http://bsalsa.com/; 56flvplayer 1.0; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; InfoPath.2)
Host: 61.172.205.36
Connection: Close

'); 

        $r = '';   
        while(!feof($fpr))   
        {   
            $r .= fgets($fpr, 512);   
        }   
        fclose($fpr);   
		
//		echo $r;
		
        if(preg_match('!"MSG":"(.*?)"!', str_replace(array("\r", "\n"), array(''), $r), $match))   
        {   
            return $match[1];   
        }   
        else  
        {   
            return false;   
        }   
    }   
}   
?>  
