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


Posted in PHP onJune 23, 2013
<?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);
?>
PHP 相关文章推荐
桌面中心(四)数据显示
Oct 09 PHP
PHP初学者最感迷茫的问题小结
Mar 27 PHP
php Static关键字实用方法
Jun 04 PHP
ThinkPHP CURD方法之limit方法详解
Jun 18 PHP
php实现四舍五入的方法小结
Mar 03 PHP
简单解析PHP程序的运行流程
Jun 23 PHP
AES加解密在php接口请求过程中的应用示例
Oct 26 PHP
thinkPHP中session()方法用法详解
Dec 08 PHP
php修改数组键名的方法示例
Apr 15 PHP
Thinkphp5行为使用方法汇总
Dec 21 PHP
thinkPHP和onethink微信支付插件分享
Aug 11 PHP
PHP safe_mode开启对于PHP系统函数有什么影响
Nov 10 PHP
使用php统计字符串中中英文字符的个数
Jun 23 #PHP
php 获取本地IP代码
Jun 23 #PHP
解析PHP提交后跳转
Jun 23 #PHP
解析PHP获取当前网址及域名的实现代码
Jun 23 #PHP
解析MySql与Java的时间类型
Jun 22 #PHP
解析mysql 表中的碎片产生原因以及清理
Jun 22 #PHP
解析thinkphp中的M()与D()方法的区别
Jun 22 #PHP
You might like
PHP中在数据库中保存Checkbox数据(1)
2006/10/09 PHP
如何解决CI框架的Disallowed Key Characters错误提示
2013/07/05 PHP
php中fgetcsv()函数用法实例
2014/11/28 PHP
Symfony模板的快捷变量用法实例
2016/03/17 PHP
php通过执行CutyCapt命令实现网页截图的方法
2016/09/30 PHP
Laravel构建即时应用的一种实现方法详解
2017/08/31 PHP
PHP addAttribute()函数讲解
2019/02/03 PHP
javascript天然的迭代器
2010/10/29 Javascript
javascript学习笔记(十七) 检测浏览器插件代码
2012/06/20 Javascript
有关json_decode乱码及NULL的问题
2015/10/13 Javascript
无缝滚动的简单实现代码(推荐)
2016/06/07 Javascript
input框中的name和id的区别
2016/11/16 Javascript
vue实现列表的添加点击
2016/12/29 Javascript
纯javaScript、jQuery实现个性化图片轮播【推荐】
2017/01/08 Javascript
JavaScript实现鼠标点击导航栏变色特效
2017/02/08 Javascript
javascript中this用法实例详解
2017/04/06 Javascript
详解vue-router 2.0 常用基础知识点之router.push()
2017/05/10 Javascript
vue.js-div滚动条隐藏但有滚动效果的实现方法
2018/03/03 Javascript
深入理解Node module模块
2018/03/26 Javascript
详解Vue CLI3 多页应用实践和源码设计
2018/08/30 Javascript
Node.js实现简单的爬取的示例代码
2019/06/25 Javascript
vue开发移动端底部导航条功能
2020/04/08 Javascript
Element Card 卡片的具体使用
2020/07/26 Javascript
element日历calendar组件上月、今天、下月、日历块点击事件及模板源码
2020/07/27 Javascript
[01:33:14]LGD vs VP Supermajor 败者组决赛 BO3 第二场 6.10
2018/07/04 DOTA
python和pyqt实现360的CLable控件
2014/02/21 Python
Python实现二维曲线拟合的方法
2018/12/29 Python
PyTorch在Windows环境搭建的方法步骤
2020/05/12 Python
python报错: 'list' object has no attribute 'shape'的解决
2020/07/15 Python
车间班长岗位职责
2013/11/30 职场文书
创业计划书如何编写
2014/02/06 职场文书
安全责任书怎么写
2014/07/28 职场文书
土木工程专业本科生求职信
2014/10/01 职场文书
2015年安全生产月活动总结
2015/03/26 职场文书
教师读书活动心得体会
2016/01/14 职场文书
nginx之内存池的实现
2022/06/28 Servers