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 在线翻译函数代码
May 07 PHP
PHP初学者常见问题集合 修正版(21问答)
Mar 23 PHP
PHP编程最快明白(第一讲 软件环境和准备工作)
Oct 25 PHP
使用XDebug调试及单元测试覆盖率分析
Jan 27 PHP
PHPMailer使用教程(PHPMailer发送邮件实例分析)
Dec 06 PHP
php 生成唯一id的几种解决方法
Mar 08 PHP
Destoon模板制作简明教程
Jun 20 PHP
php中判断数组相等的方法以及数组运算符介绍
Mar 30 PHP
将PHP从5.3.28升级到5.3.29时Nginx出现502错误
May 09 PHP
php类中的$this,static,final,const,self这几个关键字使用方法
Dec 14 PHP
PHP获取指定时间段之间的 年,月,天,时,分,秒
Jun 05 PHP
laravel实现图片上传预览,及编辑时可更换图片,并实时变化的例子
Nov 14 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学习之PHP运算符
2006/10/09 PHP
php设计模式之单例模式使用示例
2014/01/20 PHP
PHP的Laravel框架结合MySQL与Redis数据库的使用部署
2016/03/21 PHP
Mac系统下安装PHP Xdebug
2018/03/30 PHP
JQuery浮动DIV提示信息并自动隐藏的代码
2010/08/29 Javascript
JavaScript中检测变量是否存在遇到的一些问题
2013/11/11 Javascript
鼠标选择动态改变网页背景颜色的JS代码
2013/12/10 Javascript
绑定回车enter事件代码
2014/05/18 Javascript
jQuery遍历json中多个map的方法
2015/02/12 Javascript
jQuery向后台传入json格式数据的方法
2015/02/13 Javascript
AngualrJS中每次$http请求时的一个遮罩层Directive
2016/01/26 Javascript
Node.js返回JSONP详解
2016/05/18 Javascript
jstree创建无限分级树的方法【基于ajax动态创建子节点】
2016/10/25 Javascript
ES6中新增的Object.assign()方法详解
2017/09/22 Javascript
js实现鼠标单击Tab表单切换效果
2018/05/16 Javascript
快速对接payjq的个人微信支付接口过程解析
2019/08/15 Javascript
Nuxt页面级缓存的实现
2020/03/09 Javascript
全面解析JavaScript Module模式
2020/07/24 Javascript
简单谈谈python中的多进程
2016/11/06 Python
详谈Python高阶函数与函数装饰器(推荐)
2017/09/30 Python
用python处理图片实现图像中的像素访问
2018/05/04 Python
Python QQBot库的QQ聊天机器人
2019/06/19 Python
python与js主要区别点总结
2020/09/13 Python
三星法国官方网站:Samsung法国
2019/10/31 全球购物
护理实习自我鉴定
2013/12/14 职场文书
高三地理教学反思
2014/01/11 职场文书
入学生会自荐书范文
2014/02/05 职场文书
倡议书范文格式
2014/05/12 职场文书
干部作风建设工作总结
2014/10/29 职场文书
2015年安全生产目标责任书
2015/01/29 职场文书
中国世界遗产导游词
2015/02/13 职场文书
悬崖上的金鱼姬观后感
2015/06/15 职场文书
《画家和牧童》教学反思
2016/02/17 职场文书
大学校园餐饮创业计划书
2019/08/07 职场文书
jQuery实现影院选座订座效果
2021/04/13 jQuery
Java 在线考试云平台的实现
2021/11/23 Java/Android