这是 msn 类<?phperror_reporting(7);
 
class msn
 
{
 
    private $startcomm = 0;
 
    private $username = '';
 
    private $password = '';
 
    private $commend = '';
 
    private $domain = '';
 
    private $socket = '';
 
    private $challenge = '';
 
    private $status = array();
 
    private $data = array();
 
 
 
    function set_account($username, $password)
 
    {
 
        $this->username = $username;
 
        $this->password = $password;
 
    }
 
 
 
    function getData(){
 
        $buffer="";
 
        while (!feof($this->socket)) {
 
            $buffer .= fread($this->socket,1024);
 
            if (preg_match("/\r/",$buffer)) {
 
                break;
 
            }
 
        }
 
        $this->checkData($buffer);
 
    }
 
 
 
    function getData2() {
 
        $buffer="";
 
        while (!feof($this->socket)) {
 
            @$buffer .= fread($this->socket,1024);
 
            if (preg_match("/\r\n\r\n/",$buffer)) {
 
                break;
 
            }
 
        }
 
        $this->checkData($buffer);
 
    }
 
 
 
    function checkData($buffer) {
 
        if (preg_match("/lc\=(.+?)/Ui",$buffer,$matches)) {    
 
            $this->challenge = "lc=" . $matches[1];
 
        }
 
 
 
        if (preg_match("/(XFR 3 NS )([0-9\.\:]+?) (.*) ([0-9\.\:]+?)/is",$buffer,$matches)) {
 
            $split = explode(":",$matches[2]);
           
            $this->startcomm = 1;
 
            $this->msn_connect($split[0],$split[1]);
            
        }
 
 
 
        if (preg_match("/tpf\=([a-zA-Z0-9]+?)/Ui",$buffer,$matches)) {
 
            $this->nexus_connect($matches[1]);            return false;
 
        }
 
 
 
        $split = explode("\n",$buffer);
 
        for ($i=0;$i<count($split);$i++) {  
 
            $detail = explode(" ",$split[$i]);
 
            if ($detail[0] == "LST") {
 
                if(isset($detail[2])) $this->data[] = array($detail[1], urldecode($detail[2]));
 
            }
 
        }
 
        $this->status = array(200, $this->data);
 
    }
 
 
 
    function msn_connect($server,$port) {
 
        if ($this->socket) {
 
            fclose($this->socket);
 
        }
 
        $this->socket = @fsockopen($server,$port, $errno, $errstr, 20);
        
 
        if (!$this->socket) {
 
            $this->status = array(500,'MSN验证服务器无法连接');
 
            return false;
 
        } else {
        
            $this->startcomm++;
 
            $this->send_command("VER " . $this->startcomm . " MSNP8 CVR0",1);
 
            $this->send_command("CVR " . $this->startcomm . " 0x0409 win 4.10 i386 MSNMSGR 6.2 MSMSGS " . $this->username,1);
 
            $this->send_command("USR " . $this->startcomm . " TWN I " . $this->username,1);
            
        }
 
    }
 
 
 
    function send_command($command) {
 
        $this->commend = $command;
 
        $this->startcomm++;       
 
        fwrite($this->socket,$command . "\r\n");
 
        $this->getData();
 
    }
 
 
 
    function nexus_connect($tpf) {
 
        $arr[] = "GET /rdr/pprdr.asp HTTP/1.0\r\n\r\n";
 
        $curl = curl_init();
 
        curl_setopt($curl, CURLOPT_URL, "https://nexus.passport.com:443/rdr/pprdr.asp");
 
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
 
        curl_setopt($curl, CURLOPT_VERBOSE, 0);
 
        curl_setopt($curl, CURLOPT_HEADER,1);
 
        curl_setopt($curl, CURLOPT_HTTPHEADER, $arr);
 
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
 
        $data = curl_exec($curl);
 
        curl_close($curl);
 
        preg_match("/DALogin=(.+?),/",$data,$matches);
 
        if(!isset($matches[1])) return false;
 
        $split = explode("/",$matches[1]);
 
        $headers[0] = "GET /$split[1] HTTP/1.1\r\n";
 
        $headers[1] = "Authorization: Passport1.4 OrgVerb=GET,OrgURL=http%3A%2F%2Fmessenger%2Emsn%2Ecom,sign-in=" . $this->username . ",pwd=" . $this->password . ", " . trim($this->challenge) . "\r\n";
 
        $curl = curl_init();
 
        curl_setopt($curl, CURLOPT_URL, "https://" . $split[0] . ":443/". $split[1]);
 
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
 
        curl_setopt($curl, CURLOPT_VERBOSE, 0);
 
        curl_setopt($curl,CURLOPT_FOLLOWLOCATION,1);
 
        curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
 
        curl_setopt($curl, CURLOPT_HEADER,1);
 
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
 
        $data = curl_exec($curl);
 
        curl_close($curl);        preg_match("/t=(.+?)'/",$data,$matches);
 
        if(!isset($matches[1])){
        
            $this->status = array(404, '你输入的MSN帐号或者密码错误');
 
            return false;
 
        }
 
        $this->send_command("USR " . $this->startcomm . " TWN S t=" . trim($matches[1]) . "",2);
 
        $this->send_command("CHG " . $this->startcomm . " HDN",2);
 
        $this->send_command("SYN " . $this->startcomm . " 0",2);
 
        $this->getData2();
 
        $this->send_command("SYN " . $this->startcomm . " 1 46 2",2);
 
        $this->getData2();
 
        $this->send_command("CHG ". $this->startcomm . " BSY");
 
        $this->getData();     
 
    }
 
 
 
    public function getStatus()
 
    {
 
        return $this->status;
 
    }
 
}?> require(SITE_PATH.'/addons/libs/Msn.class.php');

$msn = new MSN;

$msn->set_account($name,$pass); $msn->msn_connect("messenger.hotmail.com",1863);
 
$data = $msn->getStatus();

$this->assign('msnlist',$data);帮忙看下 能获取好友列表 但是 获取不到 错误信息

解决方案 »

  1.   

     $this->socket = @fsockopen($server,$port, $errno, $errstr, 20);
    你用了错误抑制符,将错误屏蔽掉了, 你去掉再试试。
      

  2.   


    不是这个错误 是 MSN 返回的错误信息 
      

  3.   

    你测一下这句话
    $msg = $msn->set_account($name,$pass);
    var_dump($msg);
    exit();
    你输入一个错的密码,看输出的是什么
    一般来说,接口这儿应该返回一个约定的错误码,文档上应有说明
      

  4.   

    假如 我密码 错了 我应该得到这个 $this->status = array(404, '你输入的MSN帐号或者密码错误');
    返回但是我现在不管错不错都得到这个$this->status = array(200, $this->data);
      

  5.   

    echo 'aaa';
    if (preg_match("/tpf\=([a-zA-Z0-9]+?)/Ui",$buffer,$matches)) {
     echo 'bbbb';
                $this->nexus_connect($matches[1]);            return false;
     
     }
    看一下你有没有进入到if中。
    因为你想得到  $this->status = array(404, '你输入的MSN帐号或者密码错误'); 只有这一条路可走。
    而结果却是  $this->status = array(200, $this->data); 说明没有进入到if判断。
      

  6.   


    我调试在第5次 进了IF了 但是 在6次 不知道 为什么 又运行了一遍
    在第6次得时候 就没有进入 IF里面了然后 就还是返回$this->status = array(200, $this->data);
      

  7.   

    貌似这个是TS里面的~~LZ,这个功能修复好了么?