PHP獲取MSN好友列表類的實(shí)現(xiàn)代碼
<?php
error_reporting(7);
class msn
{
private $startcomm = 0;
private $username = '';
private $password = '';
private $commend = '';
private $domain = '';
private $socket = '';
private $challenge = '';
private $status = array();
private $data = array();
function set_account($username, $password)
{
$this->username = $username;
$this->password = $password;
}
function getData(){
$buffer="";
while (!feof($this->socket)) {
$buffer .= fread($this->socket,1024);
if (preg_match("http://r/",$buffer)) {
break;
}
}
$this->checkData($buffer);
}
function getData2() {
$buffer="";
while (!feof($this->socket)) {
$buffer .= fread($this->socket,1024);
if (preg_match("http://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->startcomm = 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驗(yàn)證服務(wù)器無法連接');
return false;
} else {
$this->startcomm++;
$this->send_command("VER " . $this->startcomm . " MSNP8 CVR0",1);
$this->send_command("CVR " . $this->startcomm . " 0x0409 win 4.10 i386 MSNMSGR 6.2 MSMSGS " . $this->username,1);
$this->send_command("USR " . $this->startcomm . " TWN I " . $this->username,1);
}
}
function send_command($command) {
$this->commend = $command;
$this->startcomm++;
fwrite($this->socket,$command . "/r/n");
$this->getData();
}
function nexus_connect($tpf) {
$arr[] = "GET /rdr/pprdr.asp HTTP/1.0/r/n/r/n";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "https://nexus.passport.com:443/rdr/pprdr.asp");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_VERBOSE, 0);
curl_setopt($curl, CURLOPT_HEADER,1);
curl_setopt($curl, CURLOPT_HTTPHEADER, $arr);
curl_setopt($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%2Ecom,sign-in=" . $this->username . ",pwd=" . $this->password . ", " . trim($this->challenge) . "/r/n";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "https://" . $split[0] . ":443/". $split[1]);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_VERBOSE, 0);
curl_setopt($curl,CURLOPT_FOLLOWLOCATION,1);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_HEADER,1);
curl_setopt($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帳號或者密碼錯(cuò)誤');
return false;
}
$this->send_command("USR " . $this->startcomm . " TWN S t=" . trim($matches[1]) . "",2);
$this->send_command("CHG " . $this->startcomm . " HDN",2);
$this->send_command("SYN " . $this->startcomm . " 0",2);
$this->getData2();
$this->send_command("SYN " . $this->startcomm . " 1 46 2",2);
$this->getData2();
$this->send_command("CHG ". $this->startcomm . " BSY");
$this->getData();
}
public function getStatus()
{
return $this->status;
}
}
$msn = new MSN;
$msn->set_account('xx@hotmail.com', 'xxxxx');
$msn->msn_connect("messenger.hotmail.com",1863);
$data = $msn->getStatus();
print_r($data);
?>
- PHP自動(dòng)選擇 連接本地還是遠(yuǎn)程數(shù)據(jù)庫
- php select,radio和checkbox默認(rèn)選擇的實(shí)現(xiàn)方法
- PHP與javascript對多項(xiàng)選擇的處理
- php實(shí)現(xiàn)首頁自動(dòng)選擇語言轉(zhuǎn)跳
- php從數(shù)據(jù)庫查詢結(jié)果生成樹形列表的方法
- php輸出全球各個(gè)時(shí)區(qū)列表的方法
- php使用數(shù)組填充下拉列表框的方法
- php簡單實(shí)現(xiàn)無限分類樹形列表的方法
- php簡單獲取目錄列表的方法
- php實(shí)現(xiàn)的美國50個(gè)州選擇列表實(shí)例
相關(guān)文章
php如何實(shí)現(xiàn)不借助IDE快速定位行數(shù)或者方法定義的文件和位置
這篇文章主要介紹了php如何實(shí)現(xiàn)不借助IDE快速定位行數(shù)或者方法定義的文件和位置的相關(guān)資料,需要的朋友可以參考下2017-01-01PHP使用CURL實(shí)現(xiàn)下載文件功能示例
這篇文章主要介紹了PHP使用CURL實(shí)現(xiàn)下載文件功能,結(jié)合具體實(shí)例形式分析了php基于curl的文件下載實(shí)現(xiàn)技巧,代碼注釋有詳細(xì)的功能說明,并附帶了curl參數(shù)的功能講解,需要的朋友可以參考下2019-06-06Json_encode防止?jié)h字轉(zhuǎn)義成unicode的方法
json_encode通常會(huì)把json中的漢字轉(zhuǎn)義成unicode,但是有些時(shí)候不是我們想要的,下面小編給大家介紹json_encode防止?jié)h字轉(zhuǎn)義成unicode的方法,需要的朋友參考下吧2016-02-02老版本PHP轉(zhuǎn)義Json里的特殊字符的函數(shù)
本文給大家分享的是一則在老版本的php里使用的PHP轉(zhuǎn)義Json里的特殊字符的函數(shù),雖然不是很實(shí)用了,但還是記錄一下,有需要的小伙伴可以參考下。2015-06-06Laravel框架中實(shí)現(xiàn)使用阿里云ACE緩存服務(wù)
這篇文章主要介紹了Laravel框架中實(shí)現(xiàn)使用阿里云ACE緩存服務(wù),本文擴(kuò)展了一個(gè)ACE緩存驅(qū)動(dòng),以便使用阿里云ACE緩存服務(wù),需要的朋友可以參考下2015-02-02php的webservice的wsdl的XML無法顯示問題的解決方法
本篇文章是對php的webservice的wsdl的XML無法顯示問題的解決方法進(jìn)行了介紹,需要的朋友可以過來參考下,希望對大家有所幫助2014-03-03PHP+MySQL實(shí)現(xiàn)輸入頁碼跳轉(zhuǎn)到指定頁面功能示例
這篇文章主要介紹了PHP+MySQL實(shí)現(xiàn)輸入頁碼跳轉(zhuǎn)到指定頁面功能,結(jié)合實(shí)例形式分析了php連接mysql數(shù)據(jù)庫進(jìn)行數(shù)據(jù)查詢及分頁顯示、指定頁數(shù)跳轉(zhuǎn)顯示等相關(guān)操作技巧,需要的朋友可以參考下2018-06-06PHP實(shí)現(xiàn)獲取第一個(gè)中文首字母并進(jìn)行排序的方法
這篇文章主要介紹了PHP實(shí)現(xiàn)獲取第一個(gè)中文首字母并進(jìn)行排序的方法,涉及php數(shù)組遍歷、編碼轉(zhuǎn)換及數(shù)組排序相關(guān)操作技巧,需要的朋友可以參考下2017-05-05