PHP获取MSN好友列表类的实现代码_php技巧

复制代码 代码如下:

<?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);
?>

时间: 2024-07-31 10:21:27

PHP获取MSN好友列表类的实现代码_php技巧的相关文章

PHP 获取MSN好友列表的代码(2009-05-14测试通过)_php实例

复制代码 代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh&qu

php获取本机真实IP地址实例代码_php技巧

本文实例为大家分享了php获取本机真实IP地址实例代码,供大家参考. 主要是获取操作系统为win2000/xp.win7的本机IP真实地址,和获取操作系统为linux类型的本机IP真实地址,具体内容如下 function getLocalIP() { $preg = "/\A((([0-9]?[0-9])|(1[0-9]{2})|(2[0-4][0-9])|(25[0-5]))\.){3}(([0-9]?[0-9])|(1[0-9]{2})|(2[0-4][0-9])|(25[0-5]))\Z/

php 获取本机外网/公网IP的代码_php技巧

大家一般都是用$_SERVER['REMOTE_ADDR']来获取用户IP, 但是如果使用了反向代理的,HTTP头中REMOTE_ADDR就不是用户的地址,反而是上一级代理的地址了. 经过我的研究有两种方法来获取用户的真实外网IP. 方法一:curl 复制代码 代码如下: function get_onlineip() { $ch = curl_init('http://www.ip138.com/ip2city.asp'); curl_setopt($ch, CURLOPT_RETURNTRA

phpmail类发送邮件函数代码_php技巧

有了phpmail这个类,你就不用愁了.这是个外国人写的一个类,我们就只管"拿来主义"了.下面是基于这个类里面的send()方法写的一个函数: 复制代码 代码如下: function send_mail ($title,$content,$from,$to,$charset='gbk',$attachment ='') { include '/class/PHPMail.class.php'; header('Content-Type: text/html; charset='.$ch

php 获取百度的热词数据的代码_php技巧

复制代码 代码如下: <?php /** * 获取百度的热词 * @user 小杰 * @from http://www.isharey.com/?p=354 * @return array 返回百度的热词数据(数组返回) */ function getBaiduHotKeyWord() { $templateRss = file_get_contents('http://top.baidu.com/rss_xml.php?p=top10'); If (preg_match('/<table&

php获取用户IPv4或IPv6地址的代码_php技巧

其实这个很简单,只不过我一直想用 ipv6-test 的API做一个获取用户IP地址的东西--无奈JSON获取到的只是本机服务器的IP.算了,不研究了,何况人家提供的widget也挺好用的.谷歌了一下,找到这段代码,可以根据用户环境获取IP地址. 例如IPv6访问 www.shiwo.de 则获取到的是用户的IPv6地址 p.s 前提是网站做了A和AAAA解析 复制代码 代码如下: <?php function getIP() /*获取客户端IP*/ { if (@$_SERVER["HT

用PHP获取Google AJAX Search API 数据的代码_php技巧

http://code.google.com/apis/ajaxsearch/documentation/ 复制代码 代码如下: // This example request includes an optional API key which you will need to // remove or replace with your own key. // Read more about why it's useful to have an API key. // The request

PHP和JavaScrip分别获取关联数组的键值示例代码_php技巧

PHP版: 复制代码 代码如下: $o = array('x'=>1, 'y'=>2, 'z'=>3); $arr = array(); $i = 0; foreach( $o as $arr[$i++]=>$v )/*empty*/; var_dump($arr); //$arr = array('x', 'y', 'z'); JavaScrip版: 复制代码 代码如下: var o = {x:1, y:2, z:3}; var arr = [], i = 0; for ( ar

php 遍历数据表数据并列表横向排列的代码_php技巧

复制代码 代码如下: <?php $a = array (1,2,3,4,5,6,7,8,9,10,11); $i = 0; ?> <table border=1> <tr> <? foreach ($a as $k){ if($i%3==0) {//该处表示需要横向排列的列数. echo "</tr><tr>"; } echo "<td>",$k,"</td>&qu