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录入页面中动态从数据库中提取数据的实现
Oct 09 PHP
PHP 地址栏信息的获取代码
Jan 07 PHP
PHP mcrypt可逆加密算法分析
Jul 19 PHP
PHPMYADMIN导入数据最大为2M的解决方法
Apr 23 PHP
PHP数据流应用的一个简单实例
Sep 14 PHP
PHP递归算法的详细示例分析
Feb 19 PHP
PHP采用curl模仿用户登陆新浪微博发微博的方法
Nov 07 PHP
Thinkphp实现自动验证和自动完成
Dec 19 PHP
注意!PHP 7中不要做的10件事
Sep 18 PHP
PHP批量获取网页中所有固定种子链接的方法
Nov 18 PHP
Laravel (Lumen) 解决JWT-Auth刷新token的问题
Oct 24 PHP
gearman中任务的优先级和返回状态实例分析
Feb 27 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/02/26 PHP
域名和cookie问题(域名后缀)
2012/10/10 PHP
深入PHP curl参数的详解
2013/06/17 PHP
使用php批量删除数据库下所有前缀为prefix_的表
2014/06/09 PHP
PHP框架Laravel的小技巧两则
2015/02/10 PHP
利用laravel搭建一个迷你博客实战教程
2017/08/13 PHP
jquery实现兼容浏览器的图片上传本地预览功能
2013/10/14 Javascript
jquery中change()用法实例分析
2015/02/06 Javascript
Javascript基于对象三大特性(封装性、继承性、多态性)
2016/01/04 Javascript
JavaScript的Ext JS框架中的GridPanel组件使用指南
2016/05/21 Javascript
jquery做个日期选择适用于手机端示例
2017/01/10 Javascript
javascript高级模块化require.js的具体使用方法
2017/10/31 Javascript
JS实现的数组去除重复数据算法小结
2017/11/17 Javascript
解决循环中setTimeout执行顺序的问题
2018/06/20 Javascript
Vue-router 中hash模式和history模式的区别
2018/07/24 Javascript
Vue结合后台导入导出Excel问题详解
2019/02/19 Javascript
详解小程序用户登录状态检查与更新实例
2019/05/15 Javascript
vue 移动端记录页面浏览位置的方法
2020/03/11 Javascript
详解elementUI中input框无法输入的问题
2020/04/27 Javascript
python持久性管理pickle模块详细介绍
2015/02/18 Python
用Python代码来绘制彭罗斯点阵的教程
2015/04/03 Python
使用python3.5仿微软记事本notepad
2016/06/15 Python
Python基础语言学习笔记总结(精华)
2017/11/14 Python
python实现协同过滤推荐算法完整代码示例
2017/12/15 Python
python验证码识别实例代码
2018/02/03 Python
利用Python在一个文件的头部插入数据的实例
2018/05/02 Python
浅析Python pandas模块输出每行中间省略号问题
2018/07/03 Python
HTML5图片预览实例分享
2014/06/04 HTML / CSS
特罗佩亚包官方网站:Tropea
2017/01/03 全球购物
香港卓悦化妆品官网:BONJOUR
2017/09/21 全球购物
Crocs波兰官方商店:女鞋、男鞋、童鞋、洞洞鞋
2019/10/08 全球购物
CK加拿大官网:Calvin Klein加拿大
2020/03/14 全球购物
个人自荐信
2013/12/05 职场文书
计划生育工作总结2015
2015/04/03 职场文书
pytorch中Schedule与warmup_steps的用法说明
2021/05/24 Python
10大幻兽系恶魔果实 蝙蝠果实上榜,第一自愈能力强
2022/03/18 日漫