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+javascript的日历控件
Nov 19 PHP
shopex中集成的站长统计功能的代码简单分析
Aug 11 PHP
合并ThinkPHP配置文件以消除代码冗余的实现方法
Jul 22 PHP
php中count获取多维数组长度的方法
Nov 03 PHP
PHP+apc+ajax实现的ajax_upload上传进度条代码
Jan 25 PHP
Zend Framework实现具有基本功能的留言本(附demo源码下载)
Mar 22 PHP
CodeIgniter记录错误日志的方法全面总结
May 17 PHP
php车辆违章查询数据示例
Oct 14 PHP
php array_map使用自定义的函数处理数组中的每个值
Oct 26 PHP
php中strlen和mb_strlen用法实例分析
Nov 12 PHP
源码分析 Laravel 重复执行同一个队列任务的原因
Dec 25 PHP
Yii框架小部件(Widgets)用法实例详解
May 15 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
利用discuz实现PHP大文件上传应用实例代码
2008/11/14 PHP
解析posix与perl标准的正则表达式区别
2013/06/17 PHP
php的mail函数发送UTF-8编码中文邮件时标题乱码的解决办法
2015/10/20 PHP
删除PHP数组中头部、尾部、任意元素的实现代码
2017/04/10 PHP
PHP crc32()函数讲解
2019/02/14 PHP
JavaScript toFixed() 方法
2010/04/15 Javascript
jQuery实现div浮动层跟随页面滚动效果
2014/02/11 Javascript
javascript 闭包详解
2015/02/15 Javascript
js实现获取当前时间是本月第几周的方法
2015/08/11 Javascript
Node.js插件安装图文教程
2016/05/06 Javascript
如何用JS判断两个数字的大小
2016/07/21 Javascript
javascript 中的事件委托详解
2016/10/25 Javascript
vue弹窗消息组件的使用方法
2020/09/24 Javascript
vue项目中仿element-ui弹框效果的实例代码
2019/04/22 Javascript
解决vue-cli项目开发运行时内存暴涨卡死电脑问题
2019/10/29 Javascript
js实现贪吃蛇游戏 canvas绘制地图
2020/09/09 Javascript
Vue 使用iframe引用html页面实现vue和html页面方法的调用操作
2020/11/16 Javascript
[03:39]2015国际邀请赛主赛事首日精彩回顾
2015/08/05 DOTA
Python使用scrapy采集时伪装成HTTP/1.1的方法
2015/04/08 Python
浅谈python中字典append 到list 后值的改变问题
2018/05/04 Python
Django项目开发中cookies和session的常用操作分析
2018/07/03 Python
使用Scrapy爬取动态数据
2018/10/21 Python
Django使用中间键实现csrf认证详解
2019/07/22 Python
Python实现将蓝底照片转化为白底照片功能完整实例
2019/12/13 Python
Python利用Xpath选择器爬取京东网商品信息
2020/06/01 Python
Python执行时间的几种计算方法
2020/07/31 Python
GoPro摄像机美国官网:美国运动相机厂商
2018/07/03 全球购物
仓库主管岗位职责
2014/03/02 职场文书
工商干部先进事迹
2014/05/14 职场文书
征兵宣传标语
2014/06/20 职场文书
2014年售票员工作总结
2014/11/19 职场文书
2014年小学辅导员工作总结
2014/12/23 职场文书
Nginx 过滤静态资源文件的访问日志的实现
2021/03/31 Servers
vue项目多环境配置(.env)的实现
2021/07/21 Vue.js
vue打包时去掉所有的console.log
2022/04/10 Vue.js
vue使用localStorage持久性存储实现评论列表
2022/04/14 Vue.js