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 simplexmlElement操作xml的命名空间实现代码
Jan 04 PHP
php学习笔记 PHP面向对象的程序设计
Jun 13 PHP
解析PHP 5.5 新特性
Jul 02 PHP
php面向对象中的魔术方法中文说明
Mar 04 PHP
PHP网页游戏学习之Xnova(ogame)源码解读(十四)
Jun 26 PHP
php生成shtml类用法实例
Dec 09 PHP
PHP中使用imagick生成PSD文件缩略图教程
Jan 26 PHP
php实现仿写CodeIgniter的购物车类
Jul 29 PHP
thinkPHP删除前弹出确认框的简单实现方法
May 16 PHP
php 魔术常量详解及实例代码
Dec 04 PHP
Thinkphp开发--集成极光推送
Sep 15 PHP
PHP基于curl模拟post提交json数据示例
Jun 22 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脚本的10个技巧(1)
2006/10/09 PHP
用php过滤危险html代码的函数
2008/07/22 PHP
php下防止单引号,双引号在接受页面转义的设置方法
2008/09/25 PHP
php中如何同时使用session和cookie来保存用户登录信息
2013/07/05 PHP
PHP中遇到BOM、编码导致json_decode函数无法解析问题
2014/07/02 PHP
php简单分页类实现方法
2015/02/26 PHP
PHP实现基于面向对象的mysqli扩展库增删改查操作工具类
2017/07/18 PHP
PHP文件系统管理(实例讲解)
2017/09/19 PHP
PhpStorm+xdebug+postman调试技巧分享
2020/09/15 PHP
一款JavaScript压缩工具:X2JSCompactor
2007/06/13 Javascript
浅析jQuery的链式调用之each函数
2010/12/03 Javascript
javascript四舍五入函数代码分享(保留后几位)
2013/12/10 Javascript
Bootstrap每天必学之附加导航(Affix)插件
2016/04/25 Javascript
BootStrap.css 在手机端滑动时右侧出现空白的原因及解决办法
2016/06/07 Javascript
JavaScript鼠标事件,点击鼠标右键,弹出div的简单实例
2016/08/03 Javascript
详解JavaScript 新语法之Class 的私有属性与私有方法
2019/04/23 Javascript
javascript面向对象程序设计实践常用知识点总结
2019/07/29 Javascript
js实现无限瀑布流实例方法
2019/09/16 Javascript
在vue中把含有html标签转为html渲染页面的实例
2019/10/28 Javascript
原生js实现日期选择插件
2020/05/21 Javascript
Django restframework 源码分析之认证详解
2019/02/22 Python
浅谈PYTHON 关于文件的操作
2019/03/19 Python
pyqt 实现QlineEdit 输入密码显示成圆点的方法
2019/06/24 Python
Python基于BeautifulSoup和requests实现的爬虫功能示例
2019/08/02 Python
python用requests实现http请求代码实例
2019/10/31 Python
Python 随机生成测试数据的模块:faker基本使用方法详解
2020/04/09 Python
python中for in的用法详解
2020/04/17 Python
Python中的With语句的使用及原理
2020/07/29 Python
Pytest如何使用skip跳过执行测试
2020/08/13 Python
python 获取剪切板内容的两种方法
2020/11/28 Python
会计毕业生求职简历的自我评价
2013/10/20 职场文书
关于上班时间调整的通知
2015/04/23 职场文书
教师外出学习心得体会
2016/01/18 职场文书
关于公司年会的开幕词
2016/03/04 职场文书
建国70周年的心得体会(2篇)
2019/09/20 职场文书
《哪吒之魔童降世》观后感:世上哪有随随便便的成功
2019/11/08 职场文书