


Friends.com's PHP code related to QQ (excellent information for studying QQ), php is excellent_PHP tutorial
Friends Network’s PHP code related to QQ (excellent information for studying QQ), php is excellent
/***************************************
****************************************/
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()
{
//Get friends list
//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 successfully
return $this->split_str($return['UN']);
}
else
{
//Return failed
return QQ_RETURN_FAILED;
}
}
function getOnlineList()
{
//Get the list of online friends
//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)
{
//Return successfully
If($return['SN'] > 0)
{
//Number of online friends>0
$uns = $this->split_str($return['UN']);
$nks = $this->split_str($return['NK']); // Nickname list
$sts = $this->split_str($return['ST']); //Status list
$fcs = $this->split_str($return['FC']); //Avatar list
$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
{
//Number of online friends
Return QQ_LIST_NONE;
}
}
else
{
//Return failed
return QQ_RETURN_FAILED;
}
}
function getInfo($uin)
{
//Get friend information
//AD is the contact address, AG is the age, EM is the MAIL, FC is the avatar, HP is the website, JB is the occupation, PC is the zip code, PH is the contact number, PR is the profile, PV is the province, RN is the real name, SC is the graduating school, SX is the gender, UN is the QQ number, and NK is the QQ nickname
//Research on the following annotations by Hackfan
//BT is the blood type, CO is the constellation, CT is the city, CY is the country, MO is the mobile phone, SH zodiac sign
//LV is the number to be queried (1 is simplified query, 2 is normal query, 3 is detailed query)
//CV is unknown, ID is unknown (ID card?), MT is unknown, MV is unknown,
//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)
{
//Return successfully
$arr = array
(
'Ad' = & gt; $ this- & gt; UTF8_TO_GB2312 ($ Return ['Ad']), // Contact address
'Ag' = & gt; $ this- & gt; UTF8_TO_GB2312 ($ Return ['ag']), // age
'Bt' = & gt; $ Return ['bt'], // blood type
'Co' = & gt; $ Return ['Co'], // Constellation
'Ct' = & gt; $ this- & gt; UTF8_TO_GB2312 ($ Return ['ct']), // City
'Cy' = & gt; $ this-& gt; UTF8_TO_GB2312 ($ Return ['cy']), // National
'Em' = & gt; $ this-& gt; UTF8_TO_GB2312 ($ Return ['em']), // email
'Fc' = & gt; $ Return ['fc'], // avatars
'Hp' = & gt; $ this-& gt; UTF8_TO_GB2312 ($ Return ['hp']), // website
'Jb' = & gt; $ this-& gt; UTF8_TO_GB2312 ($ Return ['jb']), // Occupation
'MO' =>
'Pc' = & gt; $ this-& gt; UTF8_TO_GB2312 ($ Return ['pc']), // Postcode
'PH' = & gt; $ this- & gt; UTF8_TO_GB2312 ($ Return ['ph']), // contact phone number
'PR' = & gt; $ this- & gt; UTF8_TO_GB2312 ($ Return ['PR']), // Introduction
'Pv' = & gt; $ this- & gt; UTF8_TO_GB2312 ($ Return ['pv']), // provincial
'Rn' = & gt; $ this-& gt; UTF8_TO_GB2312 ($ Return ['rn']), // The real name
'SC' = & GT; $ this- & gt; UTF8_TO_GB2312 ($ Return ['SC']), // Graduate college
'Sh' = & gt; $ return ['sh'], // zodiac
'SX' =>
'Un' = & gt; $ Return [' un'], // QQ number
'Nk' = & gt; $ this- & gt; UTF8_TO_GB2312 ($ Return ['nk']) // Nickname
);
return $arr;
}
else
{
//Return failed
return QQ_RETURN_FAILED;
}
}
function addFriend($uin)
{
//Add new friend
//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)
{
//Return successfully
switch($return['CD'])
{
case 0 :
//The other party allows anyone to add as a friend
Return QQ_ADDTOLIST_SUCCESS;
break;
case 1:
Return QQ_ADDTOLIST_NEEDAUTH;
break;
case 3:
//No one is allowed to be added as a friend
Return QQ_ADDTOLIST_REFUSE;
break;
to being
//Unknown code
Return QQ_ADDTOLIST_UNKNOWN;
break;
}
}
else
{
//Return failed
return QQ_RETURN_FAILED;
}
}
function replyAdd($uin,$type,$msg)
{
//Respond to add friends
//VER=1.1&CMD=Ack_AddToList&SEQ=&UIN=&UN=&CD=&RS=
//CD is the response status, and CD 0 means “passed verification”. A CD of 1 means "refuse to add the other party as a friend". A CD of 2 means "requesting the other party to be added as a friend". RS is the reason for your request
$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)
{
//The server successfully obtained the information
return QQ_RETURN_SUCCESS;
}
else
{
//Failed
return QQ_RETURN_FAILED;
}
}
{
//Delete friends
//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)
{
//The server successfully obtained the information
return QQ_RETURN_SUCCESS;
}
else
{
//Failed
return QQ_RETURN_FAILED;
}
}
{
//Change status
//VER=1.1&CMD=Change_Stat&SEQ=&UIN=&ST=
//ST is the status to be changed, 10 is online, 20 is offline, and 30 is busy.
$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)
{
//The server successfully obtained the information
return QQ_RETURN_SUCCESS;
}
else
{
//Failed
return QQ_RETURN_FAILED;
}
}
function logout()
{
//Log out
//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)
{
//The server successfully obtained the information
return QQ_RETURN_SUCCESS;
}
else
{
//Failed
return QQ_RETURN_FAILED;
}
}
function getMsg()
{
//Get news
//VER=1.1&CMD=GetMsgEx&SEQ=&UIN=
//MT represents the message type, 99 represents the system message, and 9 represents the user message. UN represents the user from whom the message is sent, MG represents the message sent, and the MG message can represent some specific system meaning
//When MT=99: MG=10 means the user is online, MG=20 means the user is offline, MG=30 means the user is busy
$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)
{
//The server successfully obtained the information
If($return['MN'] > 0)
{
//Number of messages>0
$mts = $this->split_str($return['MT']);
$uns = $this->split_str($return['UN']); //Sender number
$mgs = $this->split_str($return['MG']); //Message content
$error = 0;
(count($mts)==count($uns))==(count($uns)==count($mgs))?
$num = count($uns)
:
$error = 1;
;
If($error == 1) return QQ_GETMSG_ERROR; //Something went wrong
$arr = array();
for($i=0;$i
{
$arr[] = array(
"MT" => $mts[$i] ,
"UN" => $uns[$i] ,
"MG" => $this->utf8_to_gb2312($mgs[$i])
);
}
return ($arr);
}
else
{
//Number of online friends
Return QQ_GETMSG_NONE;
}
}
else
{
//Failed
return QQ_RETURN_FAILED;
}
}
function sendMsg($uin,$msg)
{
//Send message
//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)
{
//The server successfully obtained the information
return QQ_RETURN_SUCCESS;
}
else
{
//Failed
return QQ_RETURN_FAILED;
}
}
}
?>

PHPidentifiesauser'ssessionusingsessioncookiesandsessionIDs.1)Whensession_start()iscalled,PHPgeneratesauniquesessionIDstoredinacookienamedPHPSESSIDontheuser'sbrowser.2)ThisIDallowsPHPtoretrievesessiondatafromtheserver.

The security of PHP sessions can be achieved through the following measures: 1. Use session_regenerate_id() to regenerate the session ID when the user logs in or is an important operation. 2. Encrypt the transmission session ID through the HTTPS protocol. 3. Use session_save_path() to specify the secure directory to store session data and set permissions correctly.

PHPsessionfilesarestoredinthedirectoryspecifiedbysession.save_path,typically/tmponUnix-likesystemsorC:\Windows\TemponWindows.Tocustomizethis:1)Usesession_save_path()tosetacustomdirectory,ensuringit'swritable;2)Verifythecustomdirectoryexistsandiswrita

ToretrievedatafromaPHPsession,startthesessionwithsession_start()andaccessvariablesinthe$_SESSIONarray.Forexample:1)Startthesession:session_start().2)Retrievedata:$username=$_SESSION['username'];echo"Welcome,".$username;.Sessionsareserver-si

The steps to build an efficient shopping cart system using sessions include: 1) Understand the definition and function of the session. The session is a server-side storage mechanism used to maintain user status across requests; 2) Implement basic session management, such as adding products to the shopping cart; 3) Expand to advanced usage, supporting product quantity management and deletion; 4) Optimize performance and security, by persisting session data and using secure session identifiers.

The article explains how to create, implement, and use interfaces in PHP, focusing on their benefits for code organization and maintainability.

The article discusses the differences between crypt() and password_hash() in PHP for password hashing, focusing on their implementation, security, and suitability for modern web applications.

Article discusses preventing Cross-Site Scripting (XSS) in PHP through input validation, output encoding, and using tools like OWASP ESAPI and HTML Purifier.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

WebStorm Mac version
Useful JavaScript development tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Zend Studio 13.0.1
Powerful PHP integrated development environment
