首页 > php教程 > PHP开发 > 正文

PHP 模拟登陆MSN并获得用户信息

黄舟
发布: 2016-12-14 13:06:06
原创
1388人浏览过

/* 
* phphtm教程网,整体提供,测试通过 
*/ 
$msn = new mymsn(phphtm@phphtm.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("

>>>{$data}
"); 


function get() { 
if ($data = @fgets($this->connect, $this->maxmessage)) { 
if ($this->debug) 
print("
"); 
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 模拟登陆MSN并获得用户示例代码,更多相关内容请关注PHP中文网(www.php.cn)!

PHP速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号