朋友网关于QQ相关的PHP代码(研究QQ的绝佳资料),php绝佳
朋友网关于QQ相关的PHP代码(研究QQ的绝佳资料),php绝佳
复制代码 代码如下:
/***************************************
****************************************/
error_reporting(E_ALL ^ E_NOTICE);
require_once( 'http.inc.php' );
require_once( 'class.Chinese.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 );
//警告3xx
define( 'QQ_ADDTOLIST_NEEDAUTH',300 );
define( 'QQ_ADDTOLIST_REFUSE', 301 );
define( 'QQ_ADDTOLIST_UNKNOWN', 302 );
//失败4xx
define( 'QQ_RETURN_FAILED', 400 );
define( 'QQ_LIST_ERROR', 401 );
define( 'QQ_GETMSG_ERROR', 402 );
//在线状态
define( 'QQ_STATUS_ONLINE', 10);
define( 'QQ_STATUS_OFFLINE', 20);
define( 'QQ_STATUS_BUSY', 30);
//血型
$QQ_DATA_BT = array
(
=> '',
=> 'A型',
=> 'B型',
=> 'O型',
=> 'AB型',
=> '其他'
);
//星座
$QQ_DATA_CO = array
(
=> '',
=> '水瓶座',
=> '双鱼座',
=> '牡羊座',
=> '金牛座',
=> '双子座',
=> '巨蟹座',
=> '狮子座',
=> '处女座',
=> '天秤座',
=> '天蝎座',
=> '射手座',
=> '摩羯座'
);
//生肖
$QQ_DATA_SH = array
(
=> '',
=> '鼠',
=> '牛',
=> '虎',
=> '兔',
=> '龙',
=> '蛇',
=> '马',
=> '羊',
=> '猴',
=> '鸡',
=> '狗',
=> '猪'
);
//性别
$QQ_DATA_SX = array
(
=> '男',
=> '女'
);
class QQClient
{
var $uin;
var $pwd;
var $server = 'kconn.tencent.com';
//备用:219.133.51.11
var $port = 21001;
//备用:8000
var $httpclient;
var $chs = NULL;
function QQClient($uin,$pwd)
{
$this->uin = $uin;
$this->pwd = $pwd;
}
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;
}
function utf8_to_gb2312($str)
{
$this->chs = new Chinese("UTF8","GB2312", $str );
return $this->chs->ConvertIT();
}
function gb2312_to_utf8($str)
{
$this->chs = new Chinese("GB2312","UTF8", $str );
return $this->chs->ConvertIT();
}
function query($str)
{
$this->httpclient = new http( HTTP_V11, true );
$this->httpclient->host = 'kconn.tencent.com';
$this->httpcilent->port = 21001;
$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);
}
function split_str($str)
{
$arr = explode("," , $str);
if($arr[count($arr)-1] == NULL)
{
unset($arr[count($arr)-1]);
}
return $arr;
}
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;
}
}
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;
}
}
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
{
$arr[] = array(
"UN" => $uns[$i] ,
"NK" => $this->utf8_to_gb2312($nks[$i]) ,
"ST" => $sts[$i] ,
"FC" => $fcs[$i]
);
}
return ($arr);
}
else
{
//在线好友数
return QQ_LIST_NONE;
}
}
else
{
//返回失败
return QQ_RETURN_FAILED;
}
}
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;
}
}
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;
}
}
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;
}
}
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;
}
}
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;
}
}
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;
}
}
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
{
$arr[] = array(
"MT" => $mts[$i] ,
"UN" => $uns[$i] ,
"MG" => $this->utf8_to_gb2312($mgs[$i])
);
}
return ($arr);
}
else
{
//在线好友数
return QQ_GETMSG_NONE;
}
}
else
{
//失败
return QQ_RETURN_FAILED;
}
}
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;
}
}
}
?>

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

JWT是一種基於JSON的開放標準,用於在各方之間安全地傳輸信息,主要用於身份驗證和信息交換。 1.JWT由Header、Payload和Signature三部分組成。 2.JWT的工作原理包括生成JWT、驗證JWT和解析Payload三個步驟。 3.在PHP中使用JWT進行身份驗證時,可以生成和驗證JWT,並在高級用法中包含用戶角色和權限信息。 4.常見錯誤包括簽名驗證失敗、令牌過期和Payload過大,調試技巧包括使用調試工具和日誌記錄。 5.性能優化和最佳實踐包括使用合適的簽名算法、合理設置有效期、

靜態綁定(static::)在PHP中實現晚期靜態綁定(LSB),允許在靜態上下文中引用調用類而非定義類。 1)解析過程在運行時進行,2)在繼承關係中向上查找調用類,3)可能帶來性能開銷。

PHP的魔法方法有哪些? PHP的魔法方法包括:1.\_\_construct,用於初始化對象;2.\_\_destruct,用於清理資源;3.\_\_call,處理不存在的方法調用;4.\_\_get,實現動態屬性訪問;5.\_\_set,實現動態屬性設置。這些方法在特定情況下自動調用,提升代碼的靈活性和效率。

PHP和Python各有優勢,選擇依據項目需求。 1.PHP適合web開發,尤其快速開發和維護網站。 2.Python適用於數據科學、機器學習和人工智能,語法簡潔,適合初學者。

PHP是一種廣泛應用於服務器端的腳本語言,特別適合web開發。 1.PHP可以嵌入HTML,處理HTTP請求和響應,支持多種數據庫。 2.PHP用於生成動態網頁內容,處理表單數據,訪問數據庫等,具有強大的社區支持和開源資源。 3.PHP是解釋型語言,執行過程包括詞法分析、語法分析、編譯和執行。 4.PHP可以與MySQL結合用於用戶註冊系統等高級應用。 5.調試PHP時,可使用error_reporting()和var_dump()等函數。 6.優化PHP代碼可通過緩存機制、優化數據庫查詢和使用內置函數。 7

在PHP8 中,match表達式是一種新的控制結構,用於根據表達式的值返回不同的結果。 1)它類似於switch語句,但返回值而非執行語句塊。 2)match表達式使用嚴格比較(===),提升了安全性。 3)它避免了switch語句中可能的break遺漏問題,增強了代碼的簡潔性和可讀性。

在PHP中可以通過使用不可預測的令牌來有效防範CSRF攻擊。具體方法包括:1.生成並在表單中嵌入CSRF令牌;2.在處理請求時驗證令牌的有效性。

PHP在電子商務、內容管理系統和API開發中廣泛應用。 1)電子商務:用於購物車功能和支付處理。 2)內容管理系統:用於動態內容生成和用戶管理。 3)API開發:用於RESTfulAPI開發和API安全性。通過性能優化和最佳實踐,PHP應用的效率和可維護性得以提升。
