Discuz教程网

PHP读取msn上的用户信息类

[复制链接]
authicon dly 发表于 2011-9-12 14:45:05 | 显示全部楼层 |阅读模式
  1. <?php
  2. $msn = new myMSN("h058@test.com", "123");
  3. // MSNv9
  4. class myMSN
  5. {
  6. private $server = "messenger.hotmail.com";
  7. private $port = 1863;
  8. private $nexus = "https://nexus.passport.com/rdr/pprdr.asp";
  9. private $sshLogin = "login.live.com/login2.srf"; //loginnet.passport.com/login2.srf
  10. private $getCode = null;
  11. private $_ip = null;
  12. private $_port = null;
  13. private $connect = null;
  14. private $trID = 1;
  15. private $maxMessage = 4096;
  16. private $userName = null;
  17. private $passWord = null;
  18. private $debug = true;
  19. function myMSN($userName="", $passWord="")
  20. {
  21. if (!empty($userName) && !empty($passWord))
  22. {
  23. $this->userName = $userName;
  24. //$this->passWord = urlencode($passWord);
  25. $this->passWord = $passWord;
  26. $this->startTalk();
  27. }
  28. }
  29. function put($data)
  30. {
  31. if ($this->isConnect())
  32. {
  33. fputs($this->connect, $data);
  34. $this->trID++;
  35. if ($this->debug)
  36. print("<div style='color:green;font-size:13px;'>>>>{$data}</div>");
  37. }
  38. }
  39. function get()
  40. {
  41. if ($data = @fgets($this->connect, $this->maxMessage))
  42. {
  43. if ($this->debug)
  44. print("<div style='color:red;font-size:13px;'><<<{$data}</div>");
  45. return $data;
  46. }
  47. else
  48. {
  49. return false;
  50. }
  51. }
  52. function isConnect()
  53. {
  54. if (!is_null($this->connect))
  55. return true;
  56. else
  57. return false;
  58. }
  59. function close()
  60. {
  61. @fclose($this->connect);
  62. }
  63. function startTalk()
  64. {
  65. if ($this->connect = fsockopen($this->server, $this->port, $errno, $errstr, 2))
  66. $this->verTalk();
  67. }
  68. function verTalk() // MSN 协议协商
  69. {
  70. $this->put("VER {$this->trID} MSNP9 CVR0 rn");
  71. $data = $this->get();
  72. //echo $data;
  73. if (false !== strripos($data, "VER"))
  74. $this->envTalk();
  75. }
  76. function envTalk() // 环境协商
  77. {
  78. $this->put("CVR {$this->trID} 0x0409 winnt 5.0 i386 MSNMSGR 7.0.0816 MSMSGS {$this->userName} rn");
  79. $data = $this->get();
  80. //echo $data;
  81. if (false !== strripos($data, "CVR"))
  82. $this->reqTalk();
  83. }
  84. function reqTalk() // 请求确认
  85. {
  86. $this->put("USR {$this->trID} TWN I {$this->userName} rn");
  87. $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
  88. //echo $data;
  89. if (false !== strripos($data, "XFR"))
  90. {
  91. list(, , , $serv) = explode(" ", $data); // 分析服务器
  92. list($ip, $port) = explode(":", $serv); // 分析IP和端口
  93. $this->_ip = $ip;
  94. $this->_port = $port;
  95. $this->reLink($ip, $port);
  96. }
  97. else
  98. {
  99. //echo $data; // USR 3 TWN S ct=1205292058,rver=5.0.3270.0,wp=FS_40SEC_0_COMPACT,lc=1033,id=507,ru=http:%2F%2Fmessenger.msn.com,tw=0,kpp=1,kv=4,ver=2.1.6000.1,rn=1lgjBfIL,tpf=b0735e3a873dfb5e75054465196398e0
  100. list(, , , , $this->getCode) = explode(" ", trim($data));
  101. //echo $data;
  102. if (empty($this->sshLogin))
  103. $this->reLoginTalk(); // 重新获取登陆服务器地址
  104. else
  105. $this->getLoginCode($this->sshLogin);
  106. }
  107. }
  108. function reLink($server, $port) // 重置连接
  109. {
  110. $this->connect = null;
  111. $this->server = $server;
  112. $this->port = $port;
  113. $this->trID = 1;
  114. $this->startTalk();
  115. }
  116. function reLoginTalk() // 重新获取服务器地址
  117. {
  118. $ch = curl_init($this->nexus);
  119. curl_setopt($ch, CURLOPT_HEADER, 1);
  120. curl_setopt($ch, CURLOPT_NOBODY, 1);
  121. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  122. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  123. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  124. $header = curl_exec($ch);
  125. //print_r($header);
  126. curl_close($ch);
  127. preg_match ('/DALogin=(.*?),/', $header, $out); // 捕捉服务器登陆匹配
  128. //print_r($out);
  129. if (isset($out[1]))
  130. {
  131. $this->getLoginCode($out[1]);
  132. }
  133. else
  134. {
  135. //return false;
  136. exit("无法捕捉到登陆服务器的URL");
  137. }
  138. }
  139. function getLoginCode($slogin) // 获取登陆代码
  140. {
  141. //echo($this->getCode);
  142. if (!is_null($this->getCode))
  143. {
  144. $ch = curl_init("https://" . $slogin);
  145. $loginInfo = array(
  146. "Authorization: Passport1.4 rgVerb=GET,OrgURL=http%3A%2F%2Fmessenger%2Emsn%2Ecom,sign-in=" . $this->userName . ",pwd=" . $this->passWord . "," . $this->getCode,
  147. "Host: login.passport.com"
  148. );
  149. curl_setopt($ch, CURLOPT_HTTPHEADER, $loginInfo);
  150. //print_r($loginInfo);
  151. //$this->getCode = null;
  152. curl_setopt($ch, CURLOPT_HEADER, 1);
  153. curl_setopt($ch, CURLOPT_NOBODY, 1);
  154. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  155. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  156. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  157. $header = curl_exec($ch);
  158. //print_r($header);
  159. preg_match ("/from-PP='(.*?)'/", $header, $out);
  160. //print_r($out);
  161. if (isset($out[1]))
  162. {
  163. $this->loginAction($out[1]);
  164. }
  165. else
  166. {
  167. //return false;
  168. exit("无法捕捉到登陆代码的信息");
  169. }
  170. }
  171. else
  172. {
  173. return false;
  174. }
  175. }
  176. function loginAction($loginCode) // 登陆工作
  177. {
  178. $this->put("USR {$this->trID} TWN S {$loginCode} rn"); // USR |trID| SSO S |t=code|
  179. $data = $this->get();
  180. //echo $data;
  181. //print_r($data);
  182. //$this->put("SYN {$this->trID} 0 rn");
  183. //$this->put("CHG {$this->trID} NLN rn");
  184. //print_r($this->get());
  185. }
  186. }
  187. ?>
复制代码




上一篇:快速开发一个PHP扩展图文教程
下一篇:discuz论坛 用户登录 后台程序代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

1314学习网 ( 浙ICP备10214163号 )

GMT+8, 2025-5-2 07:02

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

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