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数组函数序列之array_unique() - 去除数组中重复的元素值
Oct 29 PHP
php中的注释、变量、数组、常量、函数应用介绍
Nov 16 PHP
PHP与javascript实现变量交互的示例代码
Jul 23 PHP
smarty中英文多编码字符截取乱码问题解决方法
Oct 28 PHP
PHP中mysql_field_type()函数用法
Nov 24 PHP
PHP实现简单汉字验证码
Jul 28 PHP
在Mac OS的PHP环境下安装配置MemCache的全过程解析
Feb 15 PHP
PHP调试的强悍利器之PHPDBG
Feb 22 PHP
PHP 用session与gd库实现简单验证码生成与验证的类方法
Nov 15 PHP
Laravel中七个非常有用但很少人知道的Carbon方法
Sep 21 PHP
Laravel 加载第三方类库的方法
Apr 20 PHP
php基于协程实现异步的方法分析
Jul 17 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设计模式 Visitor 访问者模式
2011/06/28 PHP
PHP大小写问题:函数名和类名不区分,变量名区分
2013/06/17 PHP
如何使用PHP批量去除文件UTF8 BOM信息
2013/08/05 PHP
PHP获取redis里不存在的6位随机数应用示例【设置24小时过时】
2017/06/07 PHP
javascript 二维数组的实现与应用
2010/03/16 Javascript
js通过地址栏给action传值(中文乱码全是问号)
2013/05/02 Javascript
jQuery实现鼠标滑过Div层背景变颜色的方法
2015/02/17 Javascript
javascript巧用eval函数组装表单输入项为json对象的方法
2015/11/25 Javascript
JS作用域闭包、预解释和this关键字综合实例解析
2016/12/16 Javascript
angularjs+bootstrap菜单的使用示例代码
2017/03/07 Javascript
jquery对table做排序操作的实例演示
2017/08/10 jQuery
[02:43]DOTA2英雄基础教程 圣堂刺客
2013/12/09 DOTA
[28:07]完美世界DOTA2联赛PWL S3 Phoenix vs INK ICE 第二场 12.13
2020/12/17 DOTA
Python合并多个装饰器小技巧
2015/04/28 Python
在Python中使用__slots__方法的详细教程
2015/04/28 Python
Python如何实现文本转语音
2016/08/08 Python
Python学习入门之区块链详解
2017/07/25 Python
在java中如何定义一个抽象属性示例详解
2017/08/18 Python
tensorflow实现对图片的读取的示例代码
2018/02/12 Python
python plotly绘制直方图实例详解
2019/07/22 Python
pycharm编写spark程序,导入pyspark包的3中实现方法
2019/08/02 Python
python写一个随机点名软件的实例
2019/11/28 Python
python3爬取torrent种子链接实例
2020/01/16 Python
推荐8款常用的Python GUI图形界面开发框架
2020/02/23 Python
python入门之井字棋小游戏
2020/03/05 Python
英国虚拟主机服务商:eUKhost
2016/08/16 全球购物
印度最大的网上花店:Ferns N Petals(鲜花、礼品和蛋糕)
2017/10/16 全球购物
建龙钢铁面试总结
2014/04/15 面试题
保护环境建议书
2014/03/12 职场文书
英语感谢信范文
2015/01/20 职场文书
考勤制度通知
2015/04/25 职场文书
转学证明范本
2015/06/19 职场文书
温馨祝福晨语:美丽的一天从我的问候开始
2019/11/28 职场文书
浅谈Python中的函数(def)及参数传递操作
2021/05/25 Python
详解MindSpore自定义模型损失函数
2021/06/30 Python
python 详解turtle画爱心代码
2022/02/15 Python