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数组函数序列之array_search()- 按元素值返回键名
Nov 04 PHP
测试php函数的方法
Nov 13 PHP
php中socket的用法详解
Oct 24 PHP
Laravel 4 初级教程之Pages、表单验证
Oct 30 PHP
PHP实现抓取HTTPS内容
Dec 01 PHP
PHP递归遍历指定目录的文件并统计文件数量的方法
Mar 24 PHP
php 问卷调查结果统计
Oct 08 PHP
Redis使用Eval多个键值自增的操作实例
Nov 04 PHP
PHP编辑器PhpStrom运行缓慢问题
Feb 21 PHP
php爬取天猫和淘宝商品数据
Feb 23 PHP
ThinkPHP框架中使用Memcached缓存数据的方法
Mar 31 PHP
PHP时间相关常用函数用法示例
Jun 03 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
基于initPHP的框架介绍
2013/04/18 PHP
thinkphp连贯操作实例分析
2014/11/22 PHP
session 加入redis的实现代码
2016/07/15 PHP
Yii2学习笔记之汉化yii设置表单的描述(属性标签attributeLabels)
2017/02/07 PHP
PHP简单获取随机数的常用方法小结
2017/06/07 PHP
JQuery 选择器、过滤器介绍
2011/02/14 Javascript
escape编码与unescape解码汉字出现乱码的解决方法
2014/07/02 Javascript
javascript实现仿腾讯游戏选择
2015/05/14 Javascript
javascript定义类和类的实现实例详解
2015/12/01 Javascript
jQuery选择器中的特殊符号处理方法
2017/09/08 jQuery
Vue项目数据动态过滤实践及实现思路
2018/09/11 Javascript
JavaScript设计模式之享元模式实例详解
2019/01/17 Javascript
Vue动态创建注册component的实例代码
2019/06/14 Javascript
Vue CLI项目 axios模块前后端交互的使用(类似ajax提交)
2019/09/01 Javascript
countUp.js实现数字动态变化效果
2019/10/17 Javascript
react的hooks的用法详解
2020/10/12 Javascript
[03:40]DOTA2英雄梦之声_第01期_炼金术士
2014/06/23 DOTA
python读取Android permission文件
2013/11/01 Python
matplotlib中legend位置调整解析
2017/12/19 Python
python3实现SMTP发送邮件详细教程
2018/06/19 Python
Python将多个list合并为1个list的方法
2018/06/27 Python
Python函数的参数常见分类与用法实例详解
2019/03/30 Python
tensorflow实现读取模型中保存的值 tf.train.NewCheckpointReader
2020/02/10 Python
Python-split()函数实例用法讲解
2020/12/18 Python
Html5 页面适配iPhoneX(就是那么简单)
2019/09/05 HTML / CSS
澳洲在线厨具商店:Kitchen Style
2018/05/05 全球购物
Seavenger官网:潜水服、浮潜、靴子和袜子
2020/03/05 全球购物
PHP两种查询函数array/row的区别
2013/06/03 面试题
公司合作意向书
2014/04/01 职场文书
园艺师求职信
2014/04/27 职场文书
我的教育故事演讲稿
2014/05/04 职场文书
社区优秀志愿者先进事迹
2014/05/09 职场文书
建筑施工安全责任书
2014/07/24 职场文书
小学向国旗敬礼活动方案
2014/09/27 职场文书
2015年乡镇信访工作总结
2015/04/07 职场文书
财务统计员岗位职责
2015/04/14 职场文书