php读取msn上的用户信息类

 更新时间:2008年12月05日 00:01:07   作者:  
一个可以获取msn上用户信息的代码
<?php
$msn = new myMSN("h058@test.com", "123");
// MSNv9
class myMSN
{
private $server = "messenger.hotmail.com";
private $port = 1863;
private $nexus = "https://nexus.passport.com/rdr/pprdr.asp";
private $sshLogin = "login.live.com/login2.srf"; //loginnet.passport.com/login2.srf
private $getCode = null;
private $_ip = null;
private $_port = null;
private $connect = null;
private $trID = 1;
private $maxMessage = 4096;
private $userName = null;
private $passWord = null;
private $debug = true;
function myMSN($userName="", $passWord="")
{
if (!empty($userName) && !empty($passWord))
{
$this->userName = $userName;
//$this->passWord = urlencode($passWord);
$this->passWord = $passWord;
$this->startTalk();
}
}
function put($data)
{
if ($this->isConnect())
{
fputs($this->connect, $data);
$this->trID++;
if ($this->debug)
print("<div style='color:green;font-size:13px;'>&gt;&gt;&gt;{$data}</div>");
}
}
function get()
{
if ($data = @fgets($this->connect, $this->maxMessage))
{
if ($this->debug)
print("<div style='color:red;font-size:13px;'>&lt;&lt;&lt;{$data}</div>");
return $data;
}
else
{
return false;
}
}
function isConnect()
{
if (!is_null($this->connect))
return true;
else
return false;
}
function close()
{
@fclose($this->connect);
}
function startTalk()
{
if ($this->connect = fsockopen($this->server, $this->port, $errno, $errstr, 2))
$this->verTalk();
}
function verTalk() // MSN 协议协商
{
$this->put("VER {$this->trID} MSNP9 CVR0 rn");
$data = $this->get();
//echo $data;
if (false !== strripos($data, "VER"))
$this->envTalk();
}
function envTalk() // 环境协商
{
$this->put("CVR {$this->trID} 0x0409 winnt 5.0 i386 MSNMSGR 7.0.0816 MSMSGS {$this->userName} rn");
$data = $this->get();
//echo $data;
if (false !== strripos($data, "CVR"))
$this->reqTalk();
}
function reqTalk() // 请求确认
{
$this->put("USR {$this->trID} TWN I {$this->userName} rn");
$data = $this->get(); // XFR 3 NS 207.46.107.41:1863 0 65.54.239.210:1863 XFR 3 NS 207.46.107.25:1863 U D
//echo $data;
if (false !== strripos($data, "XFR"))
{
list(, , , $serv) = explode(" ", $data); // 分析服务器
list($ip, $port) = explode(":", $serv); // 分析IP和端口
$this->_ip = $ip;
$this->_port = $port;
$this->reLink($ip, $port);
}
else
{
//echo $data; // USR 3 TWN S ct=1205292058,rver=5.0.3270.0,wp=FS_40SEC_0_COMPACT,lc=1033,id=507,ru=http:%2F%2Fmessenger.msn.com,tw=0,kpp=1,kv=4,ver=2.1.6000.1,rn=1lgjBfIL,tpf=b0735e3a873dfb5e75054465196398e0
list(, , , , $this->getCode) = explode(" ", trim($data));
//echo $data;
if (empty($this->sshLogin))
$this->reLoginTalk(); // 重新获取登陆服务器地址
else
$this->getLoginCode($this->sshLogin);
}
}
function reLink($server, $port) // 重置连接
{
$this->connect = null;
$this->server = $server;
$this->port = $port;
$this->trID = 1;
$this->startTalk();
}
function reLoginTalk() // 重新获取服务器地址
{
$ch = curl_init($this->nexus);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_NOBODY, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$header = curl_exec($ch);
//print_r($header);
curl_close($ch);
preg_match ('/DALogin=(.*?),/', $header, $out); // 捕捉服务器登陆匹配
//print_r($out);
if (isset($out[1]))
{
$this->getLoginCode($out[1]);
}
else
{
//return false;
exit("无法捕捉到登陆服务器的URL");
}
}
function getLoginCode($slogin) // 获取登陆代码
{
//echo($this->getCode);
if (!is_null($this->getCode))
{
$ch = curl_init("https://" . $slogin);
$loginInfo = array(
"Authorization: Passport1.4 rgVerb=GET,OrgURL=http%3A%2F%2Fmessenger%2Emsn%2Ecom,sign-in=" . $this->userName . ",pwd=" . $this->passWord . "," . $this->getCode,
"Host: login.passport.com"
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $loginInfo);
//print_r($loginInfo);
//$this->getCode = null;
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_NOBODY, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$header = curl_exec($ch);
//print_r($header);
preg_match ("/from-PP='(.*?)'/", $header, $out);
//print_r($out);
if (isset($out[1]))
{
$this->loginAction($out[1]);
}
else
{
//return false;
exit("无法捕捉到登陆代码的信息");
}
}
else
{
return false;
}
}
function loginAction($loginCode) // 登陆工作
{
$this->put("USR {$this->trID} TWN S {$loginCode} rn"); // USR |trID| SSO S |t=code|
$data = $this->get();
//echo $data;
//print_r($data);
//$this->put("SYN {$this->trID} 0 rn");
//$this->put("CHG {$this->trID} NLN rn");
//print_r($this->get());
}
}
?>

相关文章

  • 浅谈使用 Yii2 AssetBundle 中 $publishOptions 的正确姿势

    浅谈使用 Yii2 AssetBundle 中 $publishOptions 的正确姿势

    本篇文章主要介绍了浅谈使用 Yii2 AssetBundle 中 $publishOptions 的正确姿势,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2017-11-11
  • PHP验证码语言包预警信息通知总结示例

    PHP验证码语言包预警信息通知总结示例

    这篇文章主要为大家介绍了PHP验证码语言包预警信息通知总结示例,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2023-08-08
  • PHP中的流(streams)浅析

    PHP中的流(streams)浅析

    这篇文章主要介绍了PHP中的流(streams)浅析,本文讲解了流的概述 、流基础知识、php://包装器、流上下文(Stream Contexts)等内容,需要的朋友可以参考下
    2015-07-07
  • php+mongodb判断坐标是否在指定多边形区域内的实例

    php+mongodb判断坐标是否在指定多边形区域内的实例

    本篇文章主要介绍了php+mongodb判断坐标是否在指定多边形区域内的实例,具有一定的参考价值,感兴趣的小伙伴们可以参考一下。
    2016-10-10
  • PHP实现用户异地登录提醒功能的方法【基于thinkPHP框架】

    PHP实现用户异地登录提醒功能的方法【基于thinkPHP框架】

    这篇文章主要介绍了PHP实现用户异地登录提醒功能的方法,基于thinkPHP框架结合用户session实现异地登陆的判定功能,非常具有实用价值,需要的朋友可以参考下
    2018-03-03
  • PHP实现无限极分类图文教程

    PHP实现无限极分类图文教程

    本文从数据库设计,代码编写到效果图详细介绍了php实现无限极分类的全过程,图文并茂,是篇值得推荐的文章,小伙伴们拿走参考下吧
    2014-11-11
  • PHP中使用curl入门教程

    PHP中使用curl入门教程

    这篇文章主要介绍了PHP中使用curl入门教程,本文讲解了curl概述 、安装curl、PHP中使用curl的步骤、一个简单的curl代码实例等内容,需要的朋友可以参考下
    2015-07-07
  • php生成微信红包数组的方法

    php生成微信红包数组的方法

    这篇文章主要介绍了php生成微信红包数组的方法,本文通过实例代码给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下
    2019-09-09
  • 使用ThinkPHP生成缩略图及显示

    使用ThinkPHP生成缩略图及显示

    这篇文章主要为大家详细介绍了使用ThinkPHP生成缩略图及显示的相关资料,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2017-04-04
  • php floor()函数案例详解

    php floor()函数案例详解

    这篇文章主要介绍了php floor()函数案例详解,本篇文章通过简要的案例,讲解了该项技术的了解与使用,以下就是详细内容,需要的朋友可以参考下
    2021-08-08

最新评论