PHP获取MSN好友列表类的实现代码
<?php
error_reporting(7);
class msn
{
private $startm = 0;
private $username = '';
private $password = '';
private $mend = '';
private $domain = '';
private $socket = '';
private $challenge = '';
private $status = array();
private $data = array();
function set_aount($username, $password)
{
$this->username = $username;
$this->password = $password;
}
function getData(){
$buffer="";
while (!feof($this->socket)) {
$buffer .= fread($this->socket,1024);
if (preg_match("//r/",$buffer)) {
break;
}
}
$this->checkData($buffer);
}
function getData2() {
$buffer="";
while (!feof($this->socket)) {
$buffer .= fread($this->socket,1024);
if (preg_match("//r/n/r/n/",$buffer)) {
break;
}
}
$this->checkData($buffer);
}
function checkData($buffer) {
if (preg_match("/lc/=(.+?)/Ui",$buffer,$matches)) {
$this->challenge = "lc=" . $matches[1];
}
if (preg_match("/(XFR 3 NS )([0-9/./:]+?) (.) ([0-9/./:]+?)/is",$buffer,$matches)) {
$split = explode(":",$matches[2]);
$this->startm = 1;
$this->msn_connect($split[0],$split[1]);
}
if (preg_match("/tpf/=([a-zA-Z0-9]+?)/Ui",$buffer,$matches)) {
$this->nexus_connect($matches[1]);
}
$split = explode("/n",$buffer);
for ($i=0;$i<count($split);$i++) {
$detail = explode(" ",$split[$i]);
if ($detail[0] == "LST") {
if(isset($detail[2])) $this->data[] = array($detail[1], urldecode($detail[2]));
}
}
$this->status = array(200, $this->data);
//echo $buffer;
}
function msn_connect($server,$port) {
if ($this->socket) {
fclose($this->socket);
}
$this->socket = @fsockopen($server,$port, $errno, $errstr, 20);
if (!$this->socket) {
$this->status = array(500,'MSN验证服务器无法连接');
return false;
} else {
$this->startm++;
$this->send_mand("VER " . $this->startm . " MSNP8 CVR0",1);
$this->send_mand("CVR " . $this->startm . " 0x0409 win 4.10 i386 MSNMSGR 6.2 MSMSGS " . $this->username,1);
$this->send_mand("USR " . $this->startm . " TWN I " . $this->username,1);
}
}
function send_mand($mand) {
$this->mend = $mand;
$this->startm++;
fwrite($this->socket,$mand . "/r/n");
$this->getData();
}
function nexus_connect($tpf) {
$arr[] = "GET /rdr/pprdr.asp HTTP/1.0/r/n/r/n";
$curl = curl_init();
curl_set($curl, CURLOPT_URL, "https://nexus.passport.:443/rdr/pprdr.asp");
curl_set($curl, CURLOPT_RETURNTRANSFER, 1);
curl_set($curl, CURLOPT_VERBOSE, 0);
curl_set($curl, CURLOPT_HEADER,1);
curl_set($curl, CURLOPT_HTTPHEADER, $arr);
curl_set($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
$data = curl_exec($curl);
curl_close($curl);
preg_match("/DALogin=(.+?),/",$data,$matches);
if(!isset($matches[1])) return false;
$split = explode("/",$matches[1]);
$headers[0] = "GET /$split[1] HTTP/1.1/r/n";
$headers[1] = "Authorization: Passport1.4 OrgVerb=GET,OrgURL=http%3A%2F%2Fmessenger%2Emsn%2E,sign-in=" . $this->username . ",pwd=" . $this->password . ", " . trim($this->challenge) . "/r/n";
$curl = curl_init();
curl_set($curl, CURLOPT_URL, "https://" . $split[0] . ":443/". $split[1]);
curl_set($curl, CURLOPT_RETURNTRANSFER, 1);
curl_set($curl, CURLOPT_VERBOSE, 0);
curl_set($curl,CURLOPT_FOLLOWLOCATION,1);
curl_set($curl, CURLOPT_HTTPHEADER, $headers);
curl_set($curl, CURLOPT_HEADER,1);
curl_set($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
$data = curl_exec($curl);
curl_close($curl);
preg_match("/t=(.+?)'/",$data,$matches);
if(!isset($matches[1])){
$this->status = array(404, '你输入的MSN帐号或者密码错误');
return false;
}
$this->send_mand("USR " . $this->startm . " TWN S t=" . trim($matches[1]) . "",2);
$this->send_mand("CHG " . $this->startm . " HDN",2);
$this->send_mand("SYN " . $this->startm . " 0",2);
$this->getData2();
$this->send_mand("SYN " . $this->startm . " 1 46 2",2);
$this->getData2();
$this->send_mand("CHG ". $this->startm . " BSY");
$this->getData();
}
public function getStatus()
{
return $this->status;
}
}
$msn = new MSN;
$msn->set_aount('xx@hotmail.', 'xxxxx');
$msn->msn_connect("messenger.hotmail.",1863);
$data = $msn->getStatus();
print_r($data);
?>
编程语言
- 如何快速学会编程 如何快速学会ug编程
- 免费学编程的app 推荐12个免费学编程的好网站
- 电脑怎么编程:电脑怎么编程网咯游戏菜单图标
- 如何写代码新手教学 如何写代码新手教学手机
- 基础编程入门教程视频 基础编程入门教程视频华
- 编程演示:编程演示浦丰投针过程
- 乐高编程加盟 乐高积木编程加盟
- 跟我学plc编程 plc编程自学入门视频教程
- ug编程成航林总 ug编程实战视频
- 孩子学编程的好处和坏处
- 初学者学编程该从哪里开始 新手学编程从哪里入
- 慢走丝编程 慢走丝编程难学吗
- 国内十强少儿编程机构 中国少儿编程机构十强有
- 成人计算机速成培训班 成人计算机速成培训班办
- 孩子学编程网上课程哪家好 儿童学编程比较好的
- 代码编程教学入门软件 代码编程教程