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通用检测函数集合
Nov 25 PHP
PHP实现采集程序原理和简单示例代码
Mar 18 PHP
phpMyAdmin 链接表的附加功能尚未激活的问题
Aug 01 PHP
php中session_unset与session_destroy的区别分析
Jun 16 PHP
给初学者的30条PHP最佳实践(荒野无灯)
Aug 02 PHP
PHP对MongoDB[NoSQL]数据库的操作
Mar 01 PHP
深入PHP nl2br()格式化输出的详解
Jun 05 PHP
两千行代码的PHP学习笔记汇总
Oct 05 PHP
php获取系统变量方法小结
May 29 PHP
php实现通过ftp上传文件
Jun 19 PHP
Composer设置忽略版本匹配的方法
Apr 27 PHP
PHP实现倒计时功能
Nov 16 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实现判断访问来路是否为搜索引擎机器人的方法
2015/04/15 PHP
微信API接口大全
2015/04/15 PHP
php结合curl实现多线程抓取
2015/07/09 PHP
JS鼠标事件大全 推荐收藏
2011/11/01 Javascript
简洁Ajax函数处理(示例代码)
2013/11/15 Javascript
禁止IE用右键的JS代码
2013/12/30 Javascript
javascript中的__defineGetter__和__defineSetter__介绍
2014/08/15 Javascript
jquery实现手机号码选号的方法
2015/07/31 Javascript
原生JS京东轮播图代码
2017/03/22 Javascript
angularjs实现搜索的关键字在正文中高亮出来
2017/06/13 Javascript
详解.vue文件中监听input输入事件(oninput)
2017/09/19 Javascript
微信小程序实现下载进度条的方法
2017/12/08 Javascript
three.js实现3D影院的原理的代码分析
2017/12/18 Javascript
JS简单添加元素新节点的方法示例
2018/02/10 Javascript
详解Ubuntu安装angular-cli遇到的坑
2018/09/08 Javascript
详解CommonJS和ES6模块循环加载处理的区别
2018/12/26 Javascript
你了解vue3.0响应式数据怎么实现吗
2019/06/07 Javascript
VUE实现密码验证与提示功能
2019/10/18 Javascript
vue学习笔记之Vue中css动画原理简单示例
2020/02/29 Javascript
Python显示进度条的方法
2014/09/20 Python
python中的多重继承实例讲解
2014/09/28 Python
轻松实现TensorFlow微信跳一跳的AI
2018/01/05 Python
python实现简单日期工具类
2019/04/24 Python
Python QQBot库的QQ聊天机器人
2019/06/19 Python
python简单实现矩阵的乘,加,转置和逆运算示例
2019/07/10 Python
Python bytes string相互转换过程解析
2020/03/05 Python
CSS图片翻转动画技术详解(IE也实现了)
2014/04/03 HTML / CSS
美国最大的宠物药店:1-800-PetMeds
2016/10/02 全球购物
N.Peal官网:来自伦敦的高档羊绒品牌
2018/10/29 全球购物
人事专员岗位职责
2013/11/20 职场文书
接受捐赠答谢词
2014/01/27 职场文书
校园活动宣传方案
2014/03/28 职场文书
政府信息公开实施方案
2014/05/09 职场文书
遗愿清单观后感
2015/06/09 职场文书
初中教务主任竞聘演讲稿(范文)
2019/08/20 职场文书
MySQL8.0.18配置多主一从
2021/06/21 MySQL