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环境――Appserv
Dec 13 PHP
php MySQL与分页效率
Jun 04 PHP
php入门教程 精简版
Dec 13 PHP
php生成zip压缩文件的方法详解
Jun 09 PHP
浅析php与数据库代码开发规范
Aug 08 PHP
windows7下php开发环境搭建图文教程
Jan 06 PHP
PHP设置进度条的方法
Jul 08 PHP
浅谈PHP值mysql操作类
Jun 29 PHP
zen cart实现订单中增加paypal中预留电话的方法
Jul 12 PHP
Laravel5权限管理方法详解
Jul 26 PHP
laravel框架邮箱认证实现方法详解
Nov 22 PHP
解决Laravel使用验证时跳转到首页的问题
Nov 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获取表单textarea数据中的换行问题
2010/09/10 PHP
一个PHP验证码类代码分享(已封装成类)
2011/07/17 PHP
Linux下实现PHP多进程的方法分享
2012/08/16 PHP
PHP 代码简洁之道(小结)
2019/10/16 PHP
用javascript实现画板的代码
2007/09/05 Javascript
JavaScript 学习笔记 Black.Caffeine 09.11.28
2009/11/30 Javascript
javascript 仿QQ滑动菜单效果代码
2010/09/03 Javascript
js的写法基础分析
2011/01/17 Javascript
一个简单的JS鼠标悬停特效具体方法
2013/06/17 Javascript
js动态切换图片的方法
2015/01/20 Javascript
JavaScript动态修改网页元素内容的方法
2015/03/21 Javascript
JavaScript常用工具方法封装
2019/02/12 Javascript
[01:45]IMBATV TI4前线报道-选手到达
2014/07/07 DOTA
Python 搭建Web站点之Web服务器网关接口
2016/11/06 Python
python针对excel的操作技巧
2018/03/13 Python
python3判断url链接是否为404的方法
2018/08/10 Python
python利用thrift服务读取hbase数据的方法
2018/12/27 Python
pygame实现五子棋游戏
2019/10/29 Python
pytorch 归一化与反归一化实例
2019/12/31 Python
PyCharm第一次安装及使用教程
2020/01/08 Python
python 元组的使用方法
2020/06/09 Python
Python使用正则表达式实现爬虫数据抽取
2020/08/17 Python
CSS3中的5个有趣的新技术
2009/04/02 HTML / CSS
CSS3制作半透明边框(Facebox)类似渐变
2012/12/09 HTML / CSS
Tommy Hilfiger美国官网:美国高端休闲领导品牌
2019/01/14 全球购物
香港中原电器网上商店:Chung Yuen
2019/06/26 全球购物
Columbia Sportswear法国官网:全球户外品牌
2020/09/25 全球购物
英国银首饰公司:e&e Jewellery
2021/02/11 全球购物
如何查询Oracle数据库中已经创建的索引
2013/10/11 面试题
三年级数学教学反思
2014/01/31 职场文书
2014年健康教育实施方案
2014/02/17 职场文书
无偿献血倡议书
2014/04/14 职场文书
民主生活会整改措施(党员)
2014/09/18 职场文书
2014年教育实习工作总结
2014/11/22 职场文书
2014年信息技术工作总结
2014/12/16 职场文书
五年级学生期末评语
2014/12/26 职场文书