Discuz教程网

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

[复制链接]
authicon dly 发表于 2011-9-3 19:33:30 | 显示全部楼层 |阅读模式
代码如下:

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
  3. <head>
  4. <title>MSN 测试</title>
  5. <meta name="generator" content="Bluefish 1.0.6"/>
  6. <meta name="keywords" content="MSN"/>
  7. <meta name="description" content="MSN test"/>
  8. <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
  9. <style type="text/css">
  10. <!--
  11. div {
  12. font-family: arial, helvetica, sans-serif;
  13. font-size : 13px ;
  14. margin: 10px;
  15. padding: 2px 10px 1px;
  16. background-color: #C60;
  17. color: #FFFFFF;
  18. border-top: 1px solid #C90;
  19. border-left: 1px solid #C90;
  20. border-bottom: 1px solid #333;
  21. border-right: 1px solid #333;
  22. }
  23. a:link {
  24. color: #00FFBE;
  25. }
  26. --></style>
  27. </head>
  28. <body>
  29. <div>

  30. <?php
  31. # filename: fm.php
  32. # purpose: get MSN contact list
  33. # author: http://qartis.com/?qmsn modified by Druggo

  34. $username = $_POST['username'];
  35. $password = $_POST['password'];
  36. $debug = 0;
  37. $trid = 0;
  38. $proto = "MSNP10";

  39. # start here
  40. echo "通讯协议 $proto<br/>";
  41. echo "开始登录<br/>";
  42. # login now
  43. $sbconn = fsockopen("messenger.hotmail.com",1863) or die("Can't connect to MSN server");
  44. flush();
  45. data_out("VER $trid $proto CVR0");
  46. data_in();
  47. data_out("CVR $trid 0x0409 winnt 5.1 i386 MSNMSGR 8.0.0812 MSMSGS $username");
  48. data_in();
  49. data_out("USR $trid TWN I $username");

  50. $temp = data_in();

  51. if (!stristr($temp,":")){
  52. if (substr($temp,0,3)==601){
  53. #echo "Error: The MSN servers are currently unavailable.";
  54. echo "很不幸,MSN的服务器又挂了 >.<<br/>";
  55. die();
  56. } else {
  57. echo "连接失败!<br/>";
  58. fclose($sbconn);
  59. die();
  60. }
  61. }

  62. @fclose($sbconn);
  63. $temp_array = explode(" ",$temp);
  64. $temp_array = explode(":",$temp_array[3]);
  65. flush();
  66. $sbconn = fsockopen($temp_array[0],$temp_array[1]) or die("error -_-#");
  67. data_out("VER $trid $proto CVR0");
  68. data_in();
  69. flush();
  70. data_out("CVR $trid 0x0409 winnt 5.1 i386 MSNMSGR 8.0.0812 MSMSGS $username");
  71. data_in();
  72. data_out("USR $trid TWN I $username");
  73. $temp = data_in();
  74. $temp_array = explode(" ",$temp);
  75. flush();
  76. $TOKENSTRING = trim(end($temp_array));
  77. #echo "authenticating";
  78. echo "身份验证中……<br/>";
  79. flush();

  80. $nexus_socket = fsockopen("ssl://nexus.passport.com",443);
  81. fputs($nexus_socket,"GET /rdr/pprdr.asp HTTP/1.0\r\n\r\n");

  82. while ($temp != "\r\n"){
  83. $temp = fgets($nexus_socket,1024);
  84. if (substr($temp,0,12)=="PassportURLs"){
  85. $urls = substr($temp,14);
  86. }
  87. }

  88. $temp_array = explode(",",$urls);
  89. $temp = $temp_array[1];
  90. $temp = substr($temp,8);

  91. $temp_array = explode("/",$temp);
  92. @fclose($nexus_socket);

  93. $ssl_conn = fsockopen("ssl://".$temp_array[0],443);
  94. fputs($ssl_conn,"GET /{$temp_array[1]} HTTP/1.1\r\n");
  95. fputs($ssl_conn,"Authorization: Passport1.4 OrgVerb=GET,OrgURL=http%3A%2F%2Fmessenger%2Emsn%2Ecom,sign-in=".urlencode($username).",pwd=$password,$TOKENSTRING\r\n");
  96. fputs($ssl_conn,"User-Agent: MSMSGS\r\n");
  97. fputs($ssl_conn,"Host: {$temp_array[0]}\r\n");
  98. fputs($ssl_conn,"Connection: Keep-Alive\r\n");
  99. fputs($ssl_conn,"Cache-Control: no-cache\r\n\r\n");
  100. $temp = fgets($ssl_conn,512);

  101. if (rtrim($temp) == "HTTP/1.1 302 Found"){
  102. #echo "redirection";
  103. echo "开始重定向<br/>";
  104. flush();
  105. while ($temp != "\r\n"){
  106. $temp = fgets($ssl_conn,256);
  107. if (substr($temp,0,9)=="Location:"){
  108. $temp_array = explode(":",$temp);
  109. $temp_array = explode("/",trim(end($temp_array)));
  110. break;
  111. }
  112. }
  113. @fclose($ssl_conn);
  114. $ssl_conn = fsockopen("ssl://".$temp_array[2],443);
  115. fputs($ssl_conn,"GET /{$temp_array[3]} HTTP/1.1\r\n");
  116. fputs($ssl_conn,"Authorization: Passport1.4 OrgVerb=GET,OrgURL=http%3A%2F%2Fmessenger%2Emsn%2Ecom,sign-in=".urlencode($username).",pwd=$password,$TOKENSTRING\r\n");
  117. fputs($ssl_conn,"User-Agent: MSMSGS\r\n");
  118. fputs($ssl_conn,"Host: {$temp_array[2]}\r\n");
  119. fputs($ssl_conn,"Connection: Keep-Alive\r\n");
  120. fputs($ssl_conn,"Cache-Control: no-cache\r\n\r\n");
  121. } elseif (rtrim($temp)=="HTTP/1.1 401 Unauthorized"){
  122. #echo "invalidcreds";
  123. echo "验证失败!<br/>";
  124. @fclose($ssl_conn);
  125. die();
  126. } else {
  127. if (rtrim($temp) != "HTTP/1.1 200 OK"){
  128. #echo "Unknown HTTP status code: $temp<br>";
  129. echo "未知状态码 $temp<br/>";
  130. flush();
  131. die();
  132. } else {
  133. #echo "set_bar_len30?";
  134. }
  135. }

  136. while ($temp != "\r\n"){
  137. $temp = fgets($ssl_conn,1024);
  138. if (substr($temp,0,19)=="Authentication-Info"){
  139. $auth_info = $temp;
  140. $temp = fgets($ssl_conn,1024);
  141. if (substr($temp,0,14)!="Content-Length"){
  142. $auth_info.= fgets($ssl_conn,1024);
  143. }
  144. break;
  145. }
  146. }
  147. @fclose($ssl_conn);

  148. $temp_array = explode("'",$auth_info);
  149. flush();

  150. data_out("USR $trid TWN S {$temp_array[1]}");
  151. flush();

  152. $temp=data_in();

  153. flush();
  154. $time_since_initmsg = time();
  155. while(!strstr($temp,"ABCHMigrated") && is_string(trim($temp))){
  156. if (substr($temp,0,3)=="sid"){
  157. $sid = trim(substr($temp,5));
  158. }
  159. if (substr($temp,0,2)=="kv"){
  160. $kv = trim(substr($temp,4));
  161. }
  162. if (substr($temp,0,7)=="MSPAuth"){
  163. $mspauth = trim(substr($temp,9));
  164. flush();
  165. }
  166. $temp = data_in();
  167. }
  168. $temp = data_in();
  169. #echo "authenticated<br />";
  170. echo "验证通过!<br/>";
  171. flush();

  172. #data_out("LST 9 RL");
  173. #data_in();

  174. data_out("SYN $trid 0 0");
  175. #echo "retreiving_contact_list<br />";
  176. echo "正在获取好友列表……<br/><br/>";
  177. flush();
  178. stream_set_timeout($sbconn,0,125000);

  179. /* a lazy man doing this :D */
  180. for($i=0;$i<160;$i++) # some say max is 150
  181. {
  182. $temp = data_in();
  183. switch (substr($temp, 0, 3))
  184. {
  185. case "LST":
  186. $temp_array = explode(" ",$temp);
  187. $un = substr($temp_array[1], 2);
  188. $nn = substr($temp_array[2], 2);
  189. $nn1 = substr($temp_array[2], 0, 1);
  190. if($nn1 == "F")
  191. {
  192. echo "<a href="mailto:$un">$nn</a><br/>";
  193. }
  194. else
  195. {
  196. echo "曾经的好友: $un<br/>";
  197. }
  198. #echo $temp."<br/>";
  199. break;
  200. default:
  201. # no nothing
  202. break;
  203. }
  204. }
  205. echo "列表结束";
  206. @fclose($sbconn);

  207. # end here

  208. # functions

  209. function data_out($data){
  210. global $sbconn,$debug,$trid;
  211. fputs($sbconn,$data."\r\n");
  212. $trid++;
  213. if ($debug && !empty($data)){ echo "> ".$data."<br>\r\n";}
  214. }

  215. function data_in(){
  216. global $sbconn,$debug;
  217. $temp = fgets($sbconn,256);
  218. if ($debug && !empty($temp)){echo "< ".$temp."<br>\r\n";}
  219. return $temp;
  220. }
  221. ?>

  222. </div>
  223. </body>
  224. </html>
复制代码

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





上一篇:frename PHP 灵活文件命名函数 frename
下一篇:PHP xml留言板 xml存储数据的简单例子
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

1314学习网 ( 浙ICP备10214163号 )

GMT+8, 2025-5-2 12:46

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表