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 Memcached + APC + 文件缓存封装实现代码
Mar 11 PHP
php中inlcude()性能对比详解
Sep 16 PHP
利用phpExcel实现Excel数据的导入导出(全步骤详细解析)
Nov 26 PHP
PHP调试函数和日志记录函数分享
Jan 31 PHP
php使用COPY函数更新配置文件的方法
Jun 18 PHP
根据key删除数组中指定的元素实现方法
Mar 02 PHP
总结PHP代码规范、流程规范、git规范
Jun 18 PHP
Yii框架的redis命令使用方法简单示例
Oct 15 PHP
Laravel手动返回错误码示例
Oct 22 PHP
PHP如何开启Opcache功能提升程序处理效率
Apr 27 PHP
PHP设计模式概论【概念、分类、原则等】
May 01 PHP
PHP 数组操作详解【遍历、指针、函数等】
May 13 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 self与$this的详解
2013/06/08 PHP
php用正则表达式匹配URL的简单方法
2013/11/12 PHP
php的hash算法介绍
2014/02/13 PHP
PHP使用mysql与mysqli连接Mysql数据库用法示例
2016/07/07 PHP
thinkphp实现把数据库中的列的值存到下拉框中的方法
2017/01/20 PHP
PHP设计模式之装饰器(装饰者)模式(Decorator)入门与应用详解
2019/12/13 PHP
Prototype使用指南之form.js
2007/01/10 Javascript
js一组验证函数
2008/12/20 Javascript
SyntaxHighlighter语法高亮插件使用说明
2011/08/14 Javascript
js实现正方形颜色从下往上升的效果
2014/08/04 Javascript
修复bash漏洞的shell脚本分享
2014/12/31 Javascript
不同编码的页面表单数据乱码问题解决方法
2015/02/15 Javascript
Jquery实现弹性滑块滑动选择数值插件
2015/08/08 Javascript
jQuery实现HTML表格单元格的合并功能
2016/04/06 Javascript
DOM操作和jQuery实现选项移动操作的简单实例
2016/06/07 Javascript
AngularJs Understanding the Model Component
2016/09/02 Javascript
vue插件tab选项卡使用小结
2016/10/27 Javascript
使用Javascript判断浏览器终端设备(PC、IOS(iphone)、Android)
2017/01/04 Javascript
Vue.js教程之axios与网络传输的学习实践
2017/04/29 Javascript
Angular如何在应用初始化时运行代码详解
2018/06/11 Javascript
Angular异步变同步处理方法
2018/08/13 Javascript
Vue中 key keep-alive的实现原理
2018/09/18 Javascript
vue实现页面切换滑动效果
2020/06/29 Javascript
[03:42]2014DOTA2西雅图国际邀请赛 Navi战队巡礼
2014/07/07 DOTA
python自定义函数实现一个数的三次方计算方法
2019/01/20 Python
详解用Python为直方图绘制拟合曲线的两种方法
2019/08/21 Python
基于torch.where和布尔索引的速度比较
2020/01/02 Python
pycharm设置当前工作目录的操作(working directory)
2020/02/14 Python
python爬虫基础知识点整理
2020/06/02 Python
泰国演唱会订票网站:StubHub泰国
2018/02/26 全球购物
计算机开发个人求职信范文
2013/09/26 职场文书
软件工程专业推荐信
2013/10/28 职场文书
竞聘书模板
2014/03/31 职场文书
敬老院活动总结
2014/04/28 职场文书
我爱读书演讲稿
2014/05/07 职场文书
初中生毕业评语
2014/12/29 职场文书