PHP获取MSN好友列表类的实现代码

代码如下:

<?php
error_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]);
        }
        $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);
        //echo $buffer;
    }
    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;
    }
}

$msn = new MSN;
$msn->set_account('xx@hotmail.com', 'xxxxx');
$msn->msn_connect("messenger.hotmail.com",1863);
$data = $msn->getStatus();
print_r($data);
?>

(0)

相关推荐

  • php从数据库查询结果生成树形列表的方法

    本文实例讲述了php从数据库查询结果生成树形列表的方法.分享给大家供大家参考.具体分析如下: 本代码可以从数据库读取数据生成一个类似于windows的资源管理器的树形列表 <?php /* Here are the database definitions (for Solid) that i use in this code. * It should not be hard to adapt it to another database. */ /* CREATE TABLE dirent_t

  • PHP与javascript对多项选择的处理

    我们经常要给用户作出多项选择进行处理,例如允许用户对列表项选择多项后删除选定项等.今天举个例子说明PHP和JavaScript分别是怎样处理多项选择的.今天我们做的是一个投票系统,对MySQL数据库itemtable表里的项目进行投票,且每个别IP能且只能投两票. 表itemtable是通过以下MySQL语句建立的: CREATE TABLE `itemtable` (`id` TINYINT( 4 ) NOT NULL AUTO_INCREMENT,`name` VARCHAR( 50 ) N

  • php输出全球各个时区列表的方法

    本文实例讲述了php输出全球各个时区列表的方法.分享给大家供大家参考.具体实现方法如下: <?php $timezones = array ( '(GMT-12:00) International Date Line West' => 'Pacific/Wake', '(GMT-11:00) Midway Island' => 'Pacific/Apia', '(GMT-11:00) Samoa' => 'Pacific/Apia', '(GMT-10:00) Hawaii' =&

  • php select,radio和checkbox默认选择的实现方法

    这是扩展yibing的select默认选择的实现方法 复制代码 代码如下: <select name="wuyeleixing" size="1"> <option <?php if($myrow[wuyeleixing]==1) echo("selected");?> value="1">住宅</option> <option <?php if($myrow[wuy

  • php实现的美国50个州选择列表实例

    本文实例讲述了php实现的美国50个州选择列表.分享给大家供大家参考.具体如下: 这里展示的是php生成的美国50个州的选择列表,自动选择当前州 <select name="state" id="state"> <option value="AL" <?PHP if($state=="AL") echo "selected";?>>Alabama</option&g

  • php使用数组填充下拉列表框的方法

    本文实例讲述了php使用数组填充下拉列表框的方法.分享给大家供大家参考.具体实现方法如下: <?php $data = array( (object)array("titulo"=>"Ford", "valor"=>"opcion1"), (object)array("titulo"=>"Peugeot", "valor"=>"

  • php实现首页自动选择语言转跳

    很多网站在首页上做一些链接,让用户来选择将要访问的各自的语言页面,让中国人选择"中文",韩国人选择"朝鲜语",等等.那么能不能做程序来自动帮助选择呢? 答案是肯定的,大家都在用google,你用中文系统打开google的首页,打开的自然是中文首页,而不会是其他语言.因为google会自动判断用户系统使用的首选语言是什么. 怎样才能做到像google那样呢,其实很简单, 在浏览器发给web服务器的 HTTP Headers Information 中包含了这样一个信息

  • PHP自动选择 连接本地还是远程数据库

    Mysql.class.php 文件见 http://www.jb51.net/article/25496.htm 复制代码 代码如下: <?php // 包含Mysql操作类 include_once 'Mysql.class.php'; // 本地mysql数据 $mysql_local_data = array('db_host'=>'localhost', 'db_user'=>'root', 'db_pass'=>'root', 'db_name'=>'test')

  • php简单获取目录列表的方法

    本文实例讲述了php简单获取目录列表的方法.分享给大家供大家参考.具体实现方法如下: <?php function list_directory_content($dir){ if(is_dir($dir)){ if($handle = opendir($dir)){ while(($file = readdir($handle)) !== false){ if($file != '.' && $file != '..' && $file != '.htaccess'

  • php简单实现无限分类树形列表的方法

    本文实例讲述了php简单实现无限分类树形列表的方法.分享给大家供大家参考.具体如下: $items = array( 1 => array('id' => 1, 'pid' => 0, 'name' => '江西省'), 2 => array('id' => 2, 'pid' => 0, 'name' => '黑龙江省'), 3 => array('id' => 3, 'pid' => 1, 'name' => '南昌市'), 4 =

随机推荐