$msn = new myMSN("h058@test.com", "123");
// MSNv9
class myMSN
{
private $server = "messenger.hotmail.com";
private $port = 1863;
private $nexus = "https://nexus.passport.com/rdr/pprdr.asp";
private $sshLogin = "login.live.com/login2.srf"; //loginnet.passport.com/login2.srf
private $getCode = null;
private $_ip = null;
private $_port = null;
private $connect = null;
private $trID = 1;
private $maxMessage = 4096;
private $userName = null;
private $passWord = null;
private $debug = true;
function myMSN($userName="", $passWord="")
{
if (!empty($userName) && !empty($passWord))
{
$this->userName = $userName;
//$this->passWord = urlencode($passWord);
$this->passWord = $passWord;
$this->startTalk();
}
}
function put($data)
{
if ($this->isConnect())
{
fputs($this->connect, $data);
$this->trID++;
if ($this->debug)
print("
function get()
{
if ($data = @fgets($this->connect, $this->maxMessage))
{
if ($this->debug)
print("
関数はConnect()
{
if (!is_null($this->connect))
true を返します;
それ以外
false を返します;
}
関数close()
{
@fclose($this->connect);
}
関数 startTalk()
{
if ($this->connect = fsockopen($this->server, $this->port, $errno, $errstr, 2))
$this->verTalk();
}
function verTalk() // MSN 协议协商
{
$this->put("VER {$this->trID} MSNP9 CVR0 rn");
$data = $this->get();
// $data をエコー;
if (false !== strripos($data, "VER"))
$this->envTalk();
}
function envTalk() // 環境协商
{
$this->put("CVR {$this->trID} 0x0409 winnt 5.0 i386 MSNMSGR 7.0.0816 MSMSGS {$this->userName} rn");
$data = $this->get();
// $data をエコー;
if (false !== strripos($data, "CVR"))
$this->reqTalk();
}
function reqTalk() // 请求确认
{
$this->put("USR {$this->trID} TWN I {$this->userName} rn");
$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
// $data をエコー;
if (false !== strripos($data, "XFR"))
{
list(, , , $serv) =explode(" ", $data); // 分析服务器
list($ip, $port) =explode(":", $serv); // 分析IP和ポート
$this->_ip = $ip;
$this->_port = $port;
$this->reLink($ip, $port);
}
それ以外
{
// $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
list(, , , , $this->getCode) =explode(" ", trim($data));
// $data をエコー;
if (空($this->sshLogin))
$this->reLoginTalk(); // 重新获取登陆服务器地址
それ以外
$this->getLoginCode($this->sshLogin);
}
}
function reLink($server, $port) // 重置接続
{
$this->connect = null;
$this->server = $server;
$this->port = $port;
$this->trID = 1;
$this->startTalk();
}
function reLoginTalk() // 重新获取服务器地址
{
$ch =curl_init($this->nexus);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_NOBODY, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$header =curl_exec($ch);
//print_r($header);
curl_close($ch);
preg_match ('/DALogin=(.*?),/', $header, $out); // 捕捉服务器登陆適合
//print_r($out);
if (isset($out[1]))
{
$this->getLoginCode($out[1]);
}
それ以外
{
// false を返します;
exit("無法捕捉登陆サービス务器のURL");
}
}
function getLoginCode($slogin) // 获取登陆代码
{
//echo($this->getCode);
if (!is_null($this->getCode))
{
$ch =curl_init("https://" . $slogin);
$loginInfo = array(
「認証: Passport1.4 rgVerb=GET,OrgURL=http%3A%2F%2Fmessenger%2Emsn%2Ecom,sign-in=」 $this->userName 。 ",pwd=" 。 $this->passWord 。 「、」。 $this->getCode、
「ホスト:login.passport.com」
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $loginInfo);
//print_r($loginInfo);
//$this->getCode = null;
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_NOBODY, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$header =curl_exec($ch);
//print_r($header);
preg_match ("/from-PP='(.*?)'/", $header, $out);
//print_r($out);
if (isset($out[1]))
{
$this->loginAction($out[1]);
}
それ以外
{
// false を返します;
exit("無法捕獲登陆代码的情報");
}
}
それ以外
{
false を返します;
}
}
function loginAction($loginCode) // 登陆工作
{
$this->put("USR {$this->trID} TWN S {$loginCode} rn"); // USR |trID| SSO S |t=コード|
$data = $this->get();
// $data をエコー;
//print_r($data);
//$this->put("SYN {$this->trID} 0 rn");
//$this->put("CHG {$this->trID} NLN rn");
//print_r($this->get());
}
}
?>