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 相关文章推荐
在Windows中安装Apache2和PHP4的权威指南
Oct 09 PHP
php print EOF实现方法
May 21 PHP
修改PHP的memory_limit限制的方法分享
Feb 21 PHP
微信公众平台接口开发入门示例
Dec 24 PHP
smarty内置函数config_load用法实例
Jan 22 PHP
php的mail函数发送UTF-8编码中文邮件时标题乱码的解决办法
Oct 20 PHP
php实现中文转数字
Feb 18 PHP
php rsa 加密,解密,签名,验签详解
Dec 06 PHP
PHP面向对象程序设计方法实例详解
Dec 24 PHP
Json_decode 解析json字符串为NULL的解决方法(必看)
Feb 17 PHP
PHP Redis扩展无法加载的问题解决方法
Aug 22 PHP
php的命名空间与自动加载实现方法
Aug 25 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高自定义性安全验证码代码
2011/11/27 PHP
php操作XML、读取数据和写入数据的实现代码
2014/08/15 PHP
thinkPHP+LayUI 流加载实现功能
2019/09/27 PHP
Laravel Reponse响应客户端示例详解
2020/09/03 PHP
JS操作图片(增,删,改) 例子
2013/04/17 Javascript
JavaScript实现梯形乘法表的方法
2015/04/25 Javascript
javascript实现鼠标移到Image上方时显示文字效果的方法
2015/08/07 Javascript
利用jsonp跨域调用百度js实现搜索框智能提示
2016/08/24 Javascript
JS实现复选框的全选和批量删除功能
2017/04/05 Javascript
Angular.js中上传指令ng-upload的基本使用教程
2017/07/30 Javascript
vue项目每30秒刷新1次接口的实现方法
2018/12/04 Javascript
vue实现后台管理权限系统及顶栏三级菜单显示功能
2019/06/19 Javascript
jQuery表单校验插件validator使用方法详解
2020/02/18 jQuery
vue滑动吸顶及锚点定位的示例代码
2020/05/10 Javascript
Python中的二叉树查找算法模块使用指南
2014/07/04 Python
Python写入数据到MP3文件中的方法
2015/07/10 Python
Python内置模块logging用法实例分析
2018/02/12 Python
Python使用matplotlib实现的图像读取、切割裁剪功能示例
2018/04/28 Python
Python3爬楼梯算法示例
2019/03/04 Python
python全栈要学什么 python全栈学习路线
2019/06/28 Python
Django后端接收嵌套Json数据及解析详解
2019/07/17 Python
使用Python中tkinter库简单gui界面制作及打包成exe的操作方法(二)
2020/10/12 Python
CSS3正方体旋转示例代码
2013/08/08 HTML / CSS
Haglöfs瑞典官方网站:haglofs火柴棍,欧洲顶级户外品牌
2018/10/18 全球购物
建筑班组长岗位职责
2014/01/02 职场文书
大学新生欢迎词
2014/01/10 职场文书
宿舍违规用电检讨书
2014/02/16 职场文书
《散步》教学反思
2014/03/02 职场文书
工伤赔偿协议书范本
2014/04/15 职场文书
暑假家长评语大全
2014/04/17 职场文书
2014年新生军训方案
2014/05/01 职场文书
办理信用卡收入证明范例
2014/09/13 职场文书
毕业生的自我鉴定表范文
2019/05/16 职场文书
三好学生竞选稿范文
2019/08/21 职场文书
2019年图书室自查报告范本
2019/10/12 职场文书
解决Tkinter中button按钮未按却主动执行command函数的问题
2021/05/23 Python