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新手谈谈我的学习心得
Feb 25 PHP
用mysql内存表来代替php session的类
Feb 01 PHP
php select,radio和checkbox默认选择的实现方法
May 15 PHP
PHP,ASP.JAVA,JAVA代码格式化工具整理
Jun 15 PHP
PHP防CC攻击实现代码
Dec 29 PHP
深入php list()函数的详解
Jun 05 PHP
php Calender(日历)代码分享
Jan 03 PHP
ThinkPHP验证码使用简明教程
Mar 05 PHP
PHP中的插件机制原理和实例
Jul 08 PHP
PHP封装CURL扩展类实例
Jul 28 PHP
php实现的数字验证码及数字运算验证码
Jul 30 PHP
Laravel 错误提示本地化的实现
Oct 22 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
zf框架db类的分页示例分享
2014/03/14 PHP
使用php语句将数据库*.sql文件导入数据库
2014/05/05 PHP
Symfony数据校验方法实例分析
2015/01/26 PHP
浅析PHP中Session可能会引起并发问题
2015/07/23 PHP
mouse_on_title.js
2006/08/25 Javascript
JObj预览一个JS的框架
2008/03/13 Javascript
使用闭包对setTimeout进行简单封装避免出错
2013/07/10 Javascript
jquery.cookie() 方法的使用(读取、写入、删除)
2013/12/05 Javascript
jQuery中Ajax的load方法详解
2015/01/14 Javascript
深入浅析JavaScript函数前面的加号和叹号
2016/07/09 Javascript
onmouseover事件和onmouseout事件全面理解
2016/08/15 Javascript
angular.JS实现网页禁用调试、复制和剪切
2017/03/31 Javascript
快速使用node.js进行web开发详解
2017/04/26 Javascript
node.js+jQuery实现用户登录注册AJAX交互
2017/04/28 jQuery
Angular5中提取公共组件之radio list的实例代码
2018/07/10 Javascript
微信小程序地图绘制线段并且测量(实例代码)
2020/01/02 Javascript
python selenium 对浏览器标签页进行关闭和切换的方法
2018/05/21 Python
详解python while 函数及while和for的区别
2018/09/07 Python
python 列表中[ ]中冒号‘:’的作用
2019/04/30 Python
Python实现京东秒杀功能代码
2019/05/16 Python
python多进程 主进程和子进程间共享和不共享全局变量实例
2020/04/25 Python
Python Matplotlib绘图基础知识代码解析
2020/08/31 Python
CSS3中利用animation属性创建雪花飘落特效
2014/05/14 HTML / CSS
html5应用缓存_动力节点Java学院整理
2017/07/13 HTML / CSS
H5页面适配iPhoneX(就是那么简单)
2019/12/02 HTML / CSS
英国最大的女士服装零售商:Bonmarché
2017/08/17 全球购物
英国户外服装、鞋类和设备的领先零售商:Millets
2020/10/12 全球购物
行政办公员自我评价分享
2013/12/14 职场文书
车间操作工岗位职责
2013/12/19 职场文书
社区消防工作实施方案
2014/03/21 职场文书
党支部活动策划方案
2014/08/18 职场文书
2015年毕业实习工作总结
2014/12/12 职场文书
2015年班长个人工作总结
2015/04/03 职场文书
诚实守信主题班会
2015/08/13 职场文书
2015小学新教师个人工作总结
2015/10/14 职场文书
2019最新企业员工考勤管理制度(通用版)!
2019/07/02 职场文书