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 相关文章推荐
PHP Ajax中文乱码问题解决方法
Feb 27 PHP
PHP中MVC模式的模板引擎开发经验分享
Mar 23 PHP
PHP发明人谈MVC和网站设计架构 貌似他不支持php用mvc
Jun 04 PHP
php截取字符串之截取utf8或gbk编码的中英文字符串示例
Mar 12 PHP
php使用递归计算文件夹大小
Dec 24 PHP
php实现的IMEI限制的短信验证码发送类
May 05 PHP
php实现压缩合并js的方法【附demo源码下载】
Sep 22 PHP
PHP面向对象之事务脚本模式(详解)
Jun 07 PHP
php调用云片网接口发送短信的实现方法
Oct 25 PHP
PHP基于rabbitmq操作类的生产者和消费者功能示例
Jun 16 PHP
如何在PHP环境中使用ProtoBuf数据格式
Jun 19 PHP
PHP中多字节字符串操作实例详解
Aug 23 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实现的服务器一致性hash分布算法示例
2018/08/09 PHP
YII框架关联查询操作示例
2019/04/29 PHP
jQuery 学习第七课 扩展jQuery的功能 插件开发
2010/05/17 Javascript
JavaScript获取/更改文本框的值的实例代码
2013/08/02 Javascript
XMLHttpRequest处理xml格式的返回数据(示例代码)
2013/11/21 Javascript
js用typeof方法判断undefined类型
2014/07/15 Javascript
JScript中的条件注释详解
2015/04/24 Javascript
JavaScript中字符串拼接的基本方法
2015/07/07 Javascript
第二章之Bootstrap 页面排版样式
2016/04/25 Javascript
Angular 通过注入 $location 获取与修改当前页面URL的实例
2017/05/31 Javascript
利用Jasmine对Angular进行单元测试的方法详解
2017/06/12 Javascript
vue.js学习之vue-cli定制脚手架详解
2017/07/02 Javascript
node实现定时发送邮件的示例代码
2017/08/26 Javascript
基于 Immutable.js 实现撤销重做功能的实例代码
2018/03/01 Javascript
深入理解Vue.js轻量高效的前端组件化方案
2018/12/10 Javascript
详解Vue 项目中的几个实用组件(ts)
2019/10/29 Javascript
JavaScript对象原型链原理详解
2020/02/05 Javascript
JS浏览器BOM常见操作实例详解
2020/04/27 Javascript
JavaScript文档加载模式以及元素获取
2020/07/28 Javascript
python实现简单温度转换的方法
2015/03/13 Python
python使用post提交数据到远程url的方法
2015/04/29 Python
python scipy求解非线性方程的方法(fsolve/root)
2018/11/12 Python
值得收藏,Python 开发中的高级技巧
2018/11/23 Python
Python设计模式之原型模式实例详解
2019/01/18 Python
使用pandas的box_plot去除异常值
2019/12/10 Python
基于python 将列表作为参数传入函数时的测试与理解
2020/06/05 Python
纯CSS3实现自定义Tooltip边框涂鸦风格的教程
2014/11/05 HTML / CSS
写出程序把一个链表中的接点顺序倒排
2014/04/28 面试题
IMPORT的选项IGNORE有什么作用?缺省是什么设置?
2015/09/17 面试题
应届生如何写自荐信
2014/01/05 职场文书
酒鬼酒广告词
2014/03/21 职场文书
党员干部承诺书
2014/03/25 职场文书
环保项目建议书
2014/08/26 职场文书
法人代表授权委托书范文
2014/09/10 职场文书
2016新年慰问信范文
2015/03/25 职场文书
煤矿安全学习心得体会
2016/01/18 职场文书