《PHP教程:朋友網關于QQ相關的PHP代碼(研究QQ的絕佳資料)》要點:
本文介紹了PHP教程:朋友網關于QQ相關的PHP代碼(研究QQ的絕佳資料),希望對您有用。如果有疑問,可以聯系我們。
****************************************/
error_reporting(E_ALL ^ E_NOTICE);PHP進修
require_once( 'http.inc.php' );
require_once( 'class.Chinese.php');PHP進修
//勝利2xx
??? define( 'QQ_RETURN_SUCCESS',??? 200 );
??? define( 'QQ_LOGIN_SUCCESS',??? 201 );
??? define( 'QQ_LIST_NONE',??????? 202 );
??? define( 'QQ_ADDTOLIST_SUCCESS',??? 203 );
??? define( 'QQ_REPLYADD_SUCCESS',??? 204 );
??? define( 'QQ_GETMSG_NONE',??? 205 );PHP學習
//警告3xx
??? define( 'QQ_ADDTOLIST_NEEDAUTH',300 );
??? define( 'QQ_ADDTOLIST_REFUSE',??? 301 );
??? define( 'QQ_ADDTOLIST_UNKNOWN',??? 302 );PHP進修
//失敗4xx
??? define( 'QQ_RETURN_FAILED',??? 400 );
??? define( 'QQ_LIST_ERROR',??? 401 );
??? define( 'QQ_GETMSG_ERROR',??? 402 );PHP進修
//在線狀態
??? define( 'QQ_STATUS_ONLINE',??? 10);
??? define( 'QQ_STATUS_OFFLINE',??? 20);
??? define( 'QQ_STATUS_BUSY',??? 30);PHP進修
//血型
??? $QQ_DATA_BT = array
??????? (
=> '',
=> 'A型',
=> 'B型',
=> 'O型',
=> 'AB型',
=> '其他'
??????? );PHP進修
//星座
??? $QQ_DATA_CO = array
??????? (
=> '',
=> '水瓶座',
=> '雙魚座',
=> '牡羊座',
=> '金牛座',
=> '雙子座',
=> '巨蟹座',
=> '獅子座',
=> '童貞座',
=> '天秤座',
=> '天蝎座',
=> '射手座',
=> '摩羯座'
??????? );PHP學習
//生肖
??? $QQ_DATA_SH = array
??????? (
=> '',
=> '鼠',
=> '牛',
=> '虎',
=> '兔',
=> '龍',
=> '蛇',
=> '馬',
=> '羊',
=> '猴',
=> '雞',
=> '狗',
=> '豬'
??????? );PHP進修
//性別
??? $QQ_DATA_SX = array
??????? (
=> '男',
=> '女'
??????? );PHP進修
class QQClient
{
??? var $uin;
??? var $pwd;PHP進修
??? var $server??? =??? 'kconn.tencent.com';
??? //備用:219.133.51.11
??? var $port??? =??? 21001;
??? //備用:8000
??? var $httpclient;
??? var $chs??? =??? NULL;PHP進修
??? function QQClient($uin,$pwd)
??? {
??????? $this->uin = $uin;
??????? $this->pwd = $pwd;
??? }PHP進修
??? function encode($str)
??? /*
??????? 闡明:把KEY1=VAL1&KEY2=VAL2格式變為數組
??? */
??? {
??????? $arr = explode('&' , $str);
??????? $return = array();
??????? foreach($arr as $k=>$v)
??????? {
??????????? list($key,$val) = explode('=',$v);
??????????? $return[$key] = $val;
??????????? $this->chs = NULL;
??????? }
??????? return $return;
??? }PHP學習
??? function utf8_to_gb2312($str)
??? {
??????? $this->chs = new Chinese("UTF8","GB2312", $str );
??????? return $this->chs->ConvertIT();
??? }PHP進修
??? function gb2312_to_utf8($str)
??? {
??????? $this->chs = new Chinese("GB2312","UTF8", $str );
??????? return $this->chs->ConvertIT();
??? }PHP進修
??? function query($str)
??? {
??????? $this->httpclient = new http( HTTP_V11, true );
??????? $this->httpclient->host = 'kconn.tencent.com';
??????? $this->httpcilent->port = 21001;PHP進修
??????? $query = $this->encode($str);
??????? $status = $this->httpclient->post( '', $query, '' );
??????? if ( $status == HTTP_STATUS_OK ) {
??????????? return $this->httpclient->get_response_body();
??????? }
??????? else
??????? {
??????????? print_r($this->httpclient);
??????????? return false;
??????? }
??????? $this->httpclient->disconnect();
??????? unset($this->httpclient);
??? }PHP進修
??? function split_str($str)
??? {
??????? $arr = explode("," , $str);
??????? if($arr[count($arr)-1] == NULL)
??????? {
??????????? unset($arr[count($arr)-1]);
??????? }
??????? return $arr;
??? }PHP進修
??? function login()
??? {
??????? //登陸
??????? //VER=1.1&CMD=Login&SEQ=&UIN=&PS=&M5=1&LC=9326B87B234E7235
??????? $str = "VER=1.1&CMD=Login&SEQ=".rand(1000,9000)."&UIN=".$this->uin."&PS=".md5($this->pwd)."&M5=1&LC=9326B87B234E7235";
??????? $return = $this->encode($this->query($str));
??????? if($return['RES']==0 and $return['UIN'] == $this->uin)
??????? {
??????????? //返回勝利
??????????? if($return['RS']==0)
??????????? {
??????????????? //登陸勝利
??????????????? return QQ_LOGIN_SUCCESS;
??????????? }
??????????? else
??????????? {
??????????????? //登陸失敗
??????????????? $GLOBALS['QQ_ERROR_MSG'] = $this->utf8_to_gb2312($return['RA']);
??????????????? return QQ_LOGIN_FAILED;
??????????? }
??????? }
??????? else
??????? {
??????????? //返回失敗
??????????? return QQ_RETURN_FAILED;
???????????
??????? }
??? }PHP學習
??? function getFriendsList()
??? {
??????? //得到好友列表
??????? //VER=1.1&CMD=List&SEQ=&UIN=&TN=160&UN=0
??????? $str = "VER=1.1&CMD=List&SEQ=".rand(1000,9000)."&UIN=".$this->uin."&TN=160&UN=0";
??????? $return = $this->encode($this->query($str));
??????? if($return['RES']==0 and $return['UIN'] == $this->uin)
??????? {
??????????? //返回勝利
??????????? return $this->split_str($return['UN']);
??????? }
??????? else
??????? {
??????????? //返回失敗
??????????? return QQ_RETURN_FAILED;
???????????
??????? }
??? }PHP學習
??? function getOnlineList()
??? {
??????? //得到在線好友列表
??????? //VER=1.1&CMD=Query_Stat&SEQ=&UIN=&TN=50&UN=0
??????? $str = "VER=1.1&CMD=Query_Stat&SEQ=".rand(1000,9000)."&UIN=".$this->uin."&TN=50&UN=0";
??????? $return = $this->encode($this->query($str));
??????? if($return['RES']==0 and $return['UIN'] == $this->uin)
??????? {
??????????? //返回勝利
??????????? if($return['SN'] > 0)
??????????? {
??????????????? //在線好友數>0
??????????????? $uns = $this->split_str($return['UN']);??? //號碼列表
??????????????? $nks = $this->split_str($return['NK']); //昵稱列表
??????????????? $sts = $this->split_str($return['ST']); //狀態列表
??????????????? $fcs = $this->split_str($return['FC']); //頭像列表
??????????????? $error = 0;
??????????????? ((count($uns)==count($nks))==(count($sts)==count($fcs)))==(count($nks)==count($sts)) ?
??????????????????? $num = count($uns)
??????????????????? :
??????????????????? $error = 1;
??????????????? ;
??????????????? if($error == 1) return QQ_LIST_ERROR;
??????????????? $arr = array();
??????????????? for($i=0;$i<$num;$i++)
??????????????? {
??????????????????? $arr[] = array(
??????????????????????? "UN" => $uns[$i] ,
??????????????????????? "NK" => $this->utf8_to_gb2312($nks[$i]) ,
??????????????????????? "ST" => $sts[$i] ,
??????????????????????? "FC" => $fcs[$i]
??????????????????? );
??????????????? }
??????????????? return ($arr);
??????????? }
??????????? else
??????????? {
??????????????? //在線好友數<=0
??????????????? return QQ_LIST_NONE;
??????????? }
???????????
??????? }
??????? else
??????? {
??????????? //返回失敗
??????????? return QQ_RETURN_FAILED;
???????????????
??????? }
??? }PHP學習
??? function getInfo($uin)
??? {
??????? //得到好友信息
??????? //AD為聯系地址,AG為年齡,EM為MAIL,FC為頭像,HP為網站,JB為職業,PC為郵編,PH為聯系電話,PR為簡介,PV為省,RN為真實名稱,SC為卒業院校,SX為性別,UN為QQ號,NK為QQ昵稱
??????? //以下注釋研究 by Hackfan
??????? //BT為血型,CO為星座,CT為城市,CY為國家,MO為移動電話,SH生肖
??????? //LV為查詢的號碼(1為精簡查詢,2為普通查詢,3為詳細查詢)
??????? //CV未知,ID未知(身份證?),MT未知,MV未知,
??????? //VER=1.1&CMD=GetInfo&SEQ=&UIN=&LV=3&UN=
??????? $str = "VER=1.1&CMD=GetInfo&SEQ=".rand(1000,9000)."&UIN=".$this->uin."&LV=3&UN=".$uin;
??????? $return = $this->encode($this->query($str));
??????? if($return['RES']==0 and $return['UIN'] == $this->uin)
??????? {
??????????? //返回成功
??????????? $arr = array
??????????????? (
??????????????????? 'AD' => $this->utf8_to_gb2312($return['AD']),??????? //聯系地址
??????????????????? 'AG' => $this->utf8_to_gb2312($return['AG']),??????? //年齡
??????????????????? 'BT' => $return['BT'],??????? //血型
??????????????????? 'CO' => $return['CO'],??????? //星座
??????????????????? 'CT' => $this->utf8_to_gb2312($return['CT']),??????? //城市
??????????????????? 'CY' => $this->utf8_to_gb2312($return['CY']),??????? //國家
??????????????????? 'EM' => $this->utf8_to_gb2312($return['EM']),??????? //Email
??????????????????? 'FC' => $return['FC'],??????? //頭像
??????????????????? 'HP' => $this->utf8_to_gb2312($return['HP']),??????? //網站
??????????????????? 'JB' => $this->utf8_to_gb2312($return['JB']),??????? //職業
??????????????????? 'MO' => $return['MO'],??????? //移動電話
??????????????????? 'PC' => $this->utf8_to_gb2312($return['PC']),??????? //郵編
??????????????????? 'PH' => $this->utf8_to_gb2312($return['PH']),??????? //聯系電話
??????????????????? 'PR' => $this->utf8_to_gb2312($return['PR']),??????? //簡介
??????????????????? 'PV' => $this->utf8_to_gb2312($return['PV']),??????? //省
??????????????????? 'RN' => $this->utf8_to_gb2312($return['RN']),??????? //真實姓名
??????????????????? 'SC' => $this->utf8_to_gb2312($return['SC']),??????? //卒業院校
??????????????????? 'SH' => $return['SH'],??????? //生肖
??????????????????? 'SX' => $return['SX'],??????? //性別
??????????????????? 'UN' => $return['UN'],??????? //QQ號
??????????????????? 'NK' => $this->utf8_to_gb2312($return['NK'])??????? //昵稱
??????????????? );
??????????? return $arr;
??????? }
??????? else
??????? {
??????????? //返回失敗
??????????? return QQ_RETURN_FAILED;
???????????????
??????? }PHP學習
??? }PHP進修
??? function addFriend($uin)
??? {
??????? //添加新好友
??????? //VER=1.1&CMD=AddToList&SEQ=&UIN=&UN=
??????? $str = "VER=1.1&CMD=AddToList&SEQ=".rand(1000,9000)."&UIN=".$this->uin."&UN=".$uin;
??????? $return = $this->encode($this->query($str));
??????? if($return['RES']==0 and $return['UIN'] == $this->uin)
??????? {
??????????? //返回成功
??????????? switch($return['CD'])
??????????? {
??????????????? case 0 :
??????????????????? //對方允許任何人加為好友
??????????????????? return QQ_ADDTOLIST_SUCCESS;
??????????????????? break;
??????????????? case 1 :
??????????????????? //必要驗證
??????????????????? return QQ_ADDTOLIST_NEEDAUTH;
??????????????????? break;
??????????????? case 3 :
??????????????????? //不允許任何人加為好友
??????????????????? return QQ_ADDTOLIST_REFUSE;
??????????????????? break;
??????????????? default :
??????????????????? //未知的代碼
??????????????????? return QQ_ADDTOLIST_UNKNOWN;
??????????????????? break;
??????????? }
??????? }
??????? else
??????? {
??????????? //返回失敗
??????????? return QQ_RETURN_FAILED;
??????? }
??? }PHP學習
??? function replyAdd($uin,$type,$msg)
??? {
??????? //回應添加好友
??????? //VER=1.1&CMD=Ack_AddToList&SEQ=&UIN=&UN=&CD=&RS=
??????? //CD為響應狀態,CD為0表示“通過驗證”.CD為1表示“拒決加為對方為好友”.CD為2表示“為哀求對方加為好友”.RS為你要哀求的理由
??????? $str = "VER=1.2&CMD=Ack_AddToList&SEQ=".rand(1000,9000)."&UIN=".$this->uin."&UN=".$uin."&CD=".$type."&RS=".$this->gb2312_to_utf8($msg);
??????? $return = $this->encode($this->query($str));
???????
??????? if($return['RES']==0 and $return['UIN'] == $this->uin)
??????? {
??????????? //服務器成功得到信息
??????????? return QQ_RETURN_SUCCESS;
??????? }
??????? else
??????? {
??????????? //失敗
??????????? return QQ_RETURN_FAILED;???????????
??????? }
??? }PHP學習
??? function delFriend($uin)
??? {
??????? //刪除好友
??????? //VER=1.1&CMD=DelFromList&SEQ=&UIN=&UN=
??????? $str = "VER=1.1&CMD=DelFromList&SEQ=".rand(1000,9000)."&UIN=".$this->uin."&UN=$uin";
??????? $return = $this->encode($this->query($str));
??????? if($return['RES']==0 and $return['UIN'] == $this->uin)
??????? {
??????????? //服務器勝利得到信息
??????????? return QQ_RETURN_SUCCESS;
??????? }
??????? else
??????? {
??????????? //失敗
??????????? return QQ_RETURN_FAILED;
??????? }
??? }PHP學習
??? function changeStatus($status)
??? {
??????? //改變狀態
??????? //VER=1.1&CMD=Change_Stat&SEQ=&UIN=&ST=
??????? //ST為要改變的狀態,10為上線,20為離線,30為忙碌.
??????? $str = "VER=1.1&CMD=Change_stat&SEQ=".rand(1000,9000)."&UIN=".$this->uin."&ST=".$status;
??????? $return = $this->encode($this->query($str));
??????? if($return['RES']==0 and $return['UIN'] == $this->uin)
??????? {
??????????? //服務器勝利得到信息
??????????? return QQ_RETURN_SUCCESS;
??????? }
??????? else
??????? {
??????????? //失敗
??????????? return QQ_RETURN_FAILED;
??????? }
??? }PHP學習
??? function logout()
??? {
??????? //退出登陸
??????? //VER=1.1&CMD=Logout&SEQ=&UIN=
??????? $str = "VER=1.1&CMD=Logout&SEQ=".rand(1000,9000)."&UIN=".$this->uin;
??????? $return = $this->encode($this->query($str));
??????? if($return['RES']==0 and $return['UIN'] == $this->uin)
??????? {
??????????? //服務器勝利得到信息
??????????? return QQ_RETURN_SUCCESS;
??????? }
??????? else
??????? {
??????????? //失敗
??????????? return QQ_RETURN_FAILED;
??????? }
??? }PHP學習
??? function getMsg()
??? {
??????? //獲得消息
??????? //VER=1.1&CMD=GetMsgEx&SEQ=&UIN=
??????? //MT表現消息類型,99表現系統消息,9表現用戶消息.UN表現消息發送來源用戶,MG表現發送的消息,MG消息可以表現某些特定的系統含意
??????? //當MT=99時:MG=10表現用戶上線,MG=20表現用戶離線,MG=30表現用戶忙碌
??????? $str = "VER=1.1&CMD=GetMsgEx&SEQ=".rand(1000,9000)."&UIN=".$this->uin;
??????? $return = $this->encode($this->query($str));
??????? if($return['RES']==0 and $return['UIN'] == $this->uin)
??????? {
??????????? //服務器成功得到信息
??????????? if($return['MN'] > 0)
??????????? {
??????????????? //消息數>0
??????????????? $mts = $this->split_str($return['MT']);??? //消息類型
??????????????? $uns = $this->split_str($return['UN']); //發送者號碼
??????????????? $mgs = $this->split_str($return['MG']); //消息內容
??????????????? $error = 0;
??????????????? (count($mts)==count($uns))==(count($uns)==count($mgs))?
??????????????????? $num = count($uns)
??????????????????? :
??????????????????? $error = 1;
??????????????? ;
??????????????? if($error == 1) return QQ_GETMSG_ERROR;??? //出差錯了
??????????????? $arr = array();
??????????????? for($i=0;$i<$num;$i++)
??????????????? {
??????????????????? $arr[] = array(
??????????????????????? "MT" => $mts[$i] ,
??????????????????????? "UN" => $uns[$i] ,
??????????????????????? "MG" => $this->utf8_to_gb2312($mgs[$i])
??????????????????? );
??????????????? }
??????????????? return ($arr);
??????????? }
??????????? else
??????????? {
??????????????? //在線好友數<=0
??????????????? return QQ_GETMSG_NONE;
??????????? }
??????? }
??????? else
??????? {
??????????? //失敗
??????????? return QQ_RETURN_FAILED;
??????? }
??? }PHP學習
??? function sendMsg($uin,$msg)
??? {
??????? //發送消息
??????? //VER=1.1&CMD=CLTMSG&SEQ=&UIN=&UN=&MG=
??????? $str = "VER=1.1&CMD=CLTMSG&SEQ=".rand(1000,9000)."&UIN=".$this->uin."&UN=".$uin."&MG=".$this->gb2312_to_utf8($msg);
??????? $return = $this->encode($this->query($str));
??????? if($return['RES']==0 and $return['UIN'] == $this->uin)
??????? {
??????????? //服務器勝利得到信息
??????????? return QQ_RETURN_SUCCESS;
??????? }
??????? else
??????? {
??????????? //失敗
??????????? return QQ_RETURN_FAILED;
??????? }
??? }PHP學習
}
?>
PHP進修
《PHP教程:朋友網關于QQ相關的PHP代碼(研究QQ的絕佳資料)》是否對您有啟發,歡迎查看更多與《PHP教程:朋友網關于QQ相關的PHP代碼(研究QQ的絕佳資料)》相關教程,學精學透。維易PHP學院為您提供精彩教程。