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 相关文章推荐
vBulletin HACK----关于排版的两个HACK
Oct 09 PHP
如何在symfony中导出为CSV文件中的数据
Oct 06 PHP
使用php+apc实现上传进度条且在IE7下不显示的问题解决方法
Apr 25 PHP
一个PHP的ZIP压缩类分享
May 04 PHP
php清空(删除)指定目录下的文件,不删除目录文件夹的实现代码
Sep 04 PHP
PHP生成RSS文件类实例
Dec 05 PHP
php堆排序实现原理与应用方法
Jan 03 PHP
php ImageMagick windows下安装教程
Jan 26 PHP
PHP使用内置函数file_put_contents写入文件及追加内容的方法
Dec 07 PHP
PHP时间类完整实例(非常实用)
Dec 25 PHP
php获取指定数量随机字符串的方法
Feb 06 PHP
PHP 对象继承原理与简单用法示例
Apr 21 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提示无法加载或mcrypt没有找到 PHP 扩展 mbstring解决办法
2012/03/27 PHP
JavaScript实现删除电脑的关机键
2016/07/26 PHP
php处理单文件、多文件上传代码分享
2016/08/24 PHP
prototype.js的Ajax对象
2006/09/23 Javascript
JavaScript的parseInt 进制问题
2009/05/07 Javascript
慎用 somefunction.prototype 分析
2009/06/02 Javascript
jquery单击事件和双击事件冲突解决方案
2016/03/02 Javascript
bootstrap timepicker在angular中取值并转化为时间戳
2017/06/13 Javascript
基于casperjs和resemble.js实现一个像素对比服务详解
2018/01/10 Javascript
Vue2.0系列之过滤器的使用
2018/03/01 Javascript
javascript实现文本框标签验证的实例代码
2018/10/14 Javascript
Vue中使用方法、计算属性或观察者的方法实例详解
2018/10/31 Javascript
Layui之table中的radio在切换分页时无法记住选中状态的解决方法
2019/09/02 Javascript
vue中使用百度脑图kityminder-core二次开发的实现
2019/09/26 Javascript
JS检索下拉列表框中被选项目的索引号(selectedIndex)
2019/12/17 Javascript
在js文件中引入(调用)另一个js文件的三种方法
2020/09/11 Javascript
[02:49]2018DOTA2亚洲邀请赛主赛事决赛日战况回顾 Mineski鏖战5局夺得辉耀
2018/04/10 DOTA
Python中字典的基本知识初步介绍
2015/05/21 Python
python 顺时针打印矩阵的超简洁代码
2018/11/14 Python
python3 pathlib库Path类方法总结
2019/12/26 Python
Python基于进程池实现多进程过程解析
2020/04/30 Python
python爬取网易云音乐热歌榜实例代码
2020/08/07 Python
python 解决Windows平台上路径有空格的问题
2020/11/10 Python
基于ccs3的timeline时间线实现方法
2020/04/30 HTML / CSS
设计师家具购买和委托在线市场:Viyet
2016/11/16 全球购物
英国设计的甲板鞋和船鞋:Chatham
2018/12/06 全球购物
三星新西兰官网:Samsung新西兰
2019/03/05 全球购物
艺术家策划的室内设计:Curious Egg
2019/03/06 全球购物
文化活动实施方案
2014/03/28 职场文书
公司授权委托书范本
2014/04/03 职场文书
教师党的群众路线对照检查材料
2014/09/24 职场文书
2014院党委领导班子对照检查材料思想汇报
2014/09/24 职场文书
投资意向协议书
2015/01/29 职场文书
付款证明模板
2015/06/19 职场文书
教师教育教学随笔
2015/08/15 职场文书
大学迎新生欢迎词
2015/09/29 职场文书