PHP 模拟登陆MSN并获得用户信息
程序员文章站
2023-11-14 20:55:22
复制代码 代码如下:
<?php
/*
* php100中文网,整体提供,测试通过
*/
$msn = new mymsn(php100@php100.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;'>>>>{$data}</div>");
}
}
function get() {
if ($data = @fgets($this->connect, $this->maxmessage)) {
if ($this->debug)
print("<div style='color:red;font-size:13px;'><<<{$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://messenger.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://messenger.msn.com,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());
}
}
?>
复制代码 代码如下:
<?php
/*
* php100中文网,整体提供,测试通过
*/
$msn = new mymsn(php100@php100.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;'>>>>{$data}</div>");
}
}
function get() {
if ($data = @fgets($this->connect, $this->maxmessage)) {
if ($this->debug)
print("<div style='color:red;font-size:13px;'><<<{$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://messenger.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://messenger.msn.com,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());
}
}
?>