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


Posted in PHP onSeptember 09, 2009
<!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"> 
<head> 
<title>MSN 测试</title> 
<meta name="generator" content="Bluefish 1.0.6"/> 
<meta name="keywords" content="MSN"/> 
<meta name="description" content="MSN test"/> 
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/> 
<style type="text/css"> 
<!-- 
div { 
font-family: arial, helvetica, sans-serif; 
font-size : 13px ; 
margin: 10px; 
padding: 2px 10px 1px; 
background-color: #C60; 
color: #FFFFFF; 
border-top: 1px solid #C90; 
border-left: 1px solid #C90; 
border-bottom: 1px solid #333; 
border-right: 1px solid #333; 
} 
a:link { 
color: #00FFBE; 
} 
--></style> 
</head> 
<body> 
<div> <?php 
# filename: fm.php 
# purpose: get MSN contact list 
# author: http://qartis.com/?qmsn modified by Druggo 
$username = $_POST['username']; 
$password = $_POST['password']; 
$debug = 0; 
$trid = 0; 
$proto = "MSNP10"; 
# start here 
echo "通讯协议 $proto<br/>"; 
echo "开始登录<br/>"; 
# login now 
$sbconn = fsockopen("messenger.hotmail.com",1863) or die("Can't connect to MSN server"); 
flush(); 
data_out("VER $trid $proto CVR0"); 
data_in(); 
data_out("CVR $trid 0x0409 winnt 5.1 i386 MSNMSGR 8.0.0812 MSMSGS $username"); 
data_in(); 
data_out("USR $trid TWN I $username"); 
$temp = data_in(); 
if (!stristr($temp,":")){ 
if (substr($temp,0,3)==601){ 
#echo "Error: The MSN servers are currently unavailable."; 
echo "很不幸,MSN的服务器又挂了 >.<<br/>"; 
die(); 
} else { 
echo "连接失败!<br/>"; 
fclose($sbconn); 
die(); 
} 
} 
@fclose($sbconn); 
$temp_array = explode(" ",$temp); 
$temp_array = explode(":",$temp_array[3]); 
flush(); 
$sbconn = fsockopen($temp_array[0],$temp_array[1]) or die("error -_-#"); 
data_out("VER $trid $proto CVR0"); 
data_in(); 
flush(); 
data_out("CVR $trid 0x0409 winnt 5.1 i386 MSNMSGR 8.0.0812 MSMSGS $username"); 
data_in(); 
data_out("USR $trid TWN I $username"); 
$temp = data_in(); 
$temp_array = explode(" ",$temp); 
flush(); 
$TOKENSTRING = trim(end($temp_array)); 
#echo "authenticating"; 
echo "身份验证中……<br/>"; 
flush(); 
$nexus_socket = fsockopen("ssl://nexus.passport.com",443); 
fputs($nexus_socket,"GET /rdr/pprdr.asp HTTP/1.0\r\n\r\n"); 
while ($temp != "\r\n"){ 
$temp = fgets($nexus_socket,1024); 
if (substr($temp,0,12)=="PassportURLs"){ 
$urls = substr($temp,14); 
} 
} 
$temp_array = explode(",",$urls); 
$temp = $temp_array[1]; 
$temp = substr($temp,8); 
$temp_array = explode("/",$temp); 
@fclose($nexus_socket); 
$ssl_conn = fsockopen("ssl://".$temp_array[0],443); 
fputs($ssl_conn,"GET /{$temp_array[1]} HTTP/1.1\r\n"); 
fputs($ssl_conn,"Authorization: Passport1.4 OrgVerb=GET,OrgURL=http%3A%2F%2Fmessenger%2Emsn%2Ecom,sign-in=".urlencode($username).",pwd=$password,$TOKENSTRING\r\n"); 
fputs($ssl_conn,"User-Agent: MSMSGS\r\n"); 
fputs($ssl_conn,"Host: {$temp_array[0]}\r\n"); 
fputs($ssl_conn,"Connection: Keep-Alive\r\n"); 
fputs($ssl_conn,"Cache-Control: no-cache\r\n\r\n"); 
$temp = fgets($ssl_conn,512); 
if (rtrim($temp) == "HTTP/1.1 302 Found"){ 
#echo "redirection"; 
echo "开始重定向<br/>"; 
flush(); 
while ($temp != "\r\n"){ 
$temp = fgets($ssl_conn,256); 
if (substr($temp,0,9)=="Location:"){ 
$temp_array = explode(":",$temp); 
$temp_array = explode("/",trim(end($temp_array))); 
break; 
} 
} 
@fclose($ssl_conn); 
$ssl_conn = fsockopen("ssl://".$temp_array[2],443); 
fputs($ssl_conn,"GET /{$temp_array[3]} HTTP/1.1\r\n"); 
fputs($ssl_conn,"Authorization: Passport1.4 OrgVerb=GET,OrgURL=http%3A%2F%2Fmessenger%2Emsn%2Ecom,sign-in=".urlencode($username).",pwd=$password,$TOKENSTRING\r\n"); 
fputs($ssl_conn,"User-Agent: MSMSGS\r\n"); 
fputs($ssl_conn,"Host: {$temp_array[2]}\r\n"); 
fputs($ssl_conn,"Connection: Keep-Alive\r\n"); 
fputs($ssl_conn,"Cache-Control: no-cache\r\n\r\n"); 
} elseif (rtrim($temp)=="HTTP/1.1 401 Unauthorized"){ 
#echo "invalidcreds"; 
echo "验证失败!<br/>"; 
@fclose($ssl_conn); 
die(); 
} else { 
if (rtrim($temp) != "HTTP/1.1 200 OK"){ 
#echo "Unknown HTTP status code: $temp<br>"; 
echo "未知状态码 $temp<br/>"; 
flush(); 
die(); 
} else { 
#echo "set_bar_len30?"; 
} 
} 
while ($temp != "\r\n"){ 
$temp = fgets($ssl_conn,1024); 
if (substr($temp,0,19)=="Authentication-Info"){ 
$auth_info = $temp; 
$temp = fgets($ssl_conn,1024); 
if (substr($temp,0,14)!="Content-Length"){ 
$auth_info.= fgets($ssl_conn,1024); 
} 
break; 
} 
} 
@fclose($ssl_conn); 
$temp_array = explode("'",$auth_info); 
flush(); 
data_out("USR $trid TWN S {$temp_array[1]}"); 
flush(); 
$temp=data_in(); 
flush(); 
$time_since_initmsg = time(); 
while(!strstr($temp,"ABCHMigrated") && is_string(trim($temp))){ 
if (substr($temp,0,3)=="sid"){ 
$sid = trim(substr($temp,5)); 
} 
if (substr($temp,0,2)=="kv"){ 
$kv = trim(substr($temp,4)); 
} 
if (substr($temp,0,7)=="MSPAuth"){ 
$mspauth = trim(substr($temp,9)); 
flush(); 
} 
$temp = data_in(); 
} 
$temp = data_in(); 
#echo "authenticated<br />"; 
echo "验证通过!<br/>"; 
flush(); 
#data_out("LST 9 RL"); 
#data_in(); 
data_out("SYN $trid 0 0"); 
#echo "retreiving_contact_list<br />"; 
echo "正在获取好友列表……<br/><br/>"; 
flush(); 
stream_set_timeout($sbconn,0,125000); 
/* a lazy man doing this :D */ 
for($i=0;$i<160;$i++) # some say max is 150 
{ 
$temp = data_in(); 
switch (substr($temp, 0, 3)) 
{ 
case "LST": 
$temp_array = explode(" ",$temp); 
$un = substr($temp_array[1], 2); 
$nn = substr($temp_array[2], 2); 
$nn1 = substr($temp_array[2], 0, 1); 
if($nn1 == "F") 
{ 
echo "<a href=\"mailto:$un\">$nn</a><br/>"; 
} 
else 
{ 
echo "曾经的好友: $un<br/>"; 
} 
#echo $temp."<br/>"; 
break; 
default: 
# no nothing 
break; 
} 
} 
echo "列表结束"; 
@fclose($sbconn); 
# end here 
# functions 
function data_out($data){ 
global $sbconn,$debug,$trid; 
fputs($sbconn,$data."\r\n"); 
$trid++; 
if ($debug && !empty($data)){ echo "> ".$data."<br>\r\n";} 
} 
function data_in(){ 
global $sbconn,$debug; 
$temp = fgets($sbconn,256); 
if ($debug && !empty($temp)){echo "< ".$temp."<br>\r\n";} 
return $temp; 
} 
?> 
</div> 
</body> 
</html>

有需要的朋友可以参考下,大约要延迟几秒。
PHP 相关文章推荐
关于UEditor编辑器远程图片上传失败的解决办法
Aug 31 PHP
如何使用PHP获取指定日期所在月的开始日期与结束日期
Aug 01 PHP
PHP 正则表达式常用函数
Aug 17 PHP
使用Composer安装Yii框架的方法
Mar 15 PHP
php 如何获取文件的后缀名
Jun 05 PHP
php实现连接access数据库并转txt写入的方法
Feb 08 PHP
PHP实现蛇形矩阵,回环矩阵及数字螺旋矩阵的方法分析
May 29 PHP
PHP设计模式之装饰器模式实例详解
Feb 07 PHP
Laravel框架路由和控制器的绑定操作方法
Jun 12 PHP
php基于协程实现异步的方法分析
Jul 17 PHP
thinkphp5.1框架模板布局与模板继承用法分析
Jul 19 PHP
ThinkPHP 5 AJAX跨域请求头设置实现过程解析
Oct 28 PHP
PHP 危险函数全解析
Sep 09 #PHP
php 获取远程网页内容的函数
Sep 08 #PHP
php 遍历数据表数据并列表横向排列的代码
Sep 05 #PHP
不要轻信 PHP_SELF的安全问题
Sep 05 #PHP
php中$_SERVER[PHP_SELF] 和 $_SERVER[SCRIPT_NAME]之间的区别
Sep 05 #PHP
php getsiteurl()函数
Sep 05 #PHP
PHP 内存缓存加速功能memcached安装与用法
Sep 03 #PHP
You might like
提升PHP执行速度全攻略(下)
2006/10/09 PHP
php的header和asp中的redirect比较
2006/10/09 PHP
php生成随机字符串可指定纯数字、纯字母或者混合的
2014/04/18 PHP
windows下配置apache+php+mysql时出现问题的处理方法
2014/06/20 PHP
php实现的支持imagemagick及gd库两种处理的缩略图生成类
2014/09/23 PHP
JavaScript 函数式编程的原理
2009/10/16 Javascript
javascript 添加和移除函数的通用方法
2009/10/20 Javascript
鼠标选择动态改变网页背景颜色的JS代码
2013/12/10 Javascript
JavaScript中document对象使用详解
2015/01/06 Javascript
详解JavaScript中的客户端消息框架设计原理
2015/06/24 Javascript
jquery实现实时改变网页字体大小、字体背景色和颜色的方法
2015/08/05 Javascript
JS显示日历和天气的方法
2016/03/01 Javascript
Bootstrap Table使用整理(五)之分页组合查询
2017/06/09 Javascript
浅谈vue中数据双向绑定的实现原理
2017/09/14 Javascript
JS 实现分页打印功能
2018/05/16 Javascript
解决vscode进行vue格式化,会自动补分号和双引号的问题
2020/10/26 Javascript
uni-app实现获取验证码倒计时功能
2020/11/01 Javascript
Vue使用Proxy代理后仍无法生效的解决
2020/11/13 Javascript
[08:02]DOTA2牵红线 zhou神抱得美人归
2014/03/22 DOTA
[46:38]完美世界DOTA2联赛PWL S2 Magma vs PXG 第三场 11.28
2020/12/02 DOTA
Python多线程编程(一):threading模块综述
2015/04/05 Python
python处理按钮消息的实例详解
2017/07/11 Python
Python如何生成树形图案
2018/01/03 Python
tensorflow1.0学习之模型的保存与恢复(Saver)
2018/04/23 Python
Python合并多个Excel数据的方法
2018/07/16 Python
Python 获取主机ip与hostname的方法
2018/12/17 Python
在python 中实现运行多条shell命令
2019/01/07 Python
基于TensorFlow常量、序列以及随机值生成实例
2020/01/04 Python
解决tensorflow添加ptb库的问题
2020/02/10 Python
2014年预备党员学习新党章思想汇报
2014/09/15 职场文书
公司领导九九重阳节发言稿2014
2014/09/25 职场文书
考研英语复习计划
2015/01/19 职场文书
个人工作年终总结
2015/03/09 职场文书
2016教师廉洁从教心得体会
2016/01/13 职场文书
解决Navicat for Mysql连接报错1251的问题(连接失败)
2021/05/27 MySQL
Redis过期数据是否会被立马删除
2022/07/23 Redis