欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2023-11-26 12:44:52
复制代码 代码如下:
复制代码 代码如下:

<!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>

有需要的朋友可以参考下,大约要延迟几秒。