Friend web about QQ-related PHP code (study QQ excellent information), PHP excellent
Copy the Code code as follows:
<?
/***************************************
****************************************/
Error_reporting (e_all ^ e_notice);
Require_once (' http.inc.php ');
Require_once (' class. Chinese.php ');
Success 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);
Warning 3XX
Define (' Qq_addtolist_needauth ', 300);
Define (' Qq_addtolist_refuse ', 301);
Define (' Qq_addtolist_unknown ', 302);
Failure 4xx
Define (' qq_return_failed ', 400);
Define (' Qq_list_error ', 401);
Define (' Qq_getmsg_error ', 402);
Online status
Define (' Qq_status_online ', 10);
Define (' Qq_status_offline ', 20);
Define (' Qq_status_busy ', 30);
Blood
$QQ _DATA_BT = array
(
= ",
= = ' A type ',
= ' B type ',
= ' O ',
= ' AB type ',
= ' other '
);
Constellation
$QQ _data_co = array
(
= ",
= ' Aquarius ',
= ' Pisces ',
= ' Aries ',
= ' Taurus ',
= ' Gemini ',
= ' cancer ',
= ' Leo ',
= ' Virgo ',
= ' Libra ',
= ' Scorpio ',
= ' Sagittarius ',
= ' Capricorn '
);
Zodiac
$QQ _data_sh = array
(
= ",
= ' Rat ',
= ' ox ',
= ' Tiger ',
= ' Rabbit ',
= ' Dragon ',
= ' Snake ',
= ' Ma ',
= ' sheep ',
= ' Monkey ',
= ' chicken ',
= ' dog ',
= ' pig '
);
Gender
$QQ _data_sx = array
(
= ' Man ',
= ' Woman '
);
Class Qqclient
{
var $uin;
var $pwd;
var $server = ' kconn.tencent.com ';
Spare: 219.133.51.11
var $port = 21001;
Standby: 8000
var $httpclient;
var $chs = NULL;
function Qqclient ($uin, $pwd)
{
$this->uin = $uin;
$this->pwd = $pwd;
}
function encode ($STR)
/*
Description: Change the KEY1=VAL1&KEY2=VAL2 format to an array
*/
{
$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 ()
{
//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)
{
//Return Success
if ($return [' RS ']==0)
{
// Login succeeded
return qq_login_success;
}
Else
{
//Login failed
$GLOBALS [' qq_error_msg '] = $this->utf8_to_gb2312 ($return [' RA ']);
Return Qq_login _failed;
}
}
Else
{
//return failed
return qq_return_failed;
}
}
function Getfriendslist ()
{
Get a buddy 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 success
return $this->split_str ($return [' UN ']);
}
Else
{
return failure
return qq_return_failed;
}
}
function Getonlinelist ()
{
Get online friends List
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 success
if ($return [' SN '] > 0)
{
Number of friends online >0
$uns = $this->split_str ($return [' UN ']); List of numbers
$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 < $num; $i + +)
{
$arr [] = Array (
"UN" and $uns [$i],
"NK" = $this->utf8_to_gb2312 ($nks [$i]),
"ST" = $sts [$i],
"FC" = $fcs [$i]
);
}
return ($arr);
}
Else
{
Number of friends online <=0
return qq_list_none;
}
}
Else
{
return failure
return qq_return_failed;
}
}
function GetInfo ($uin)
{
Get Friends Info
Ad for the contact address, Ag for the age, the MAIL,FC for the Avatar, HP for the website, JB for the occupation, PC for the postcode, ph for contact telephone, PR for the introduction, PV for the province, RN for the real name, SC for the graduation school, SX for gender, UN for QQ, NK for QQ nickname
The following annotation studies by Hackfan
BT for blood type, CO for constellation, CT for City, CY for Country, MO for Mobile, sh zodiac
LV for the query number (1 for thin query, 2 for normal query, 3 for detailed query)
CV Unknown, id unknown (ID card?), MT Unknown, MV 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 success
$arr = array
(
' Ad ' = $this->utf8_to_gb2312 ($return [' ad ']),//contact address
' AG ' = $this->utf8_to_gb2312 ($return [' AG ']),//Age
' BT ' = $return [' BT '],//Blood type
' Co ' = $return [' Co '],//constellation
' ct ' = $this->utf8_to_gb2312 ($return [' CT ']),//City
' cy ' = $this->utf8_to_gb2312 ($return [' Cy ']),//Country
' em ' = $this->utf8_to_gb2312 ($return [' em ']),//email
' fc ' = $return [' FC '],//Avatar
' HP ' = $this->utf8_to_gb2312 ($return [' HP ']),//website
' JB ' = $this->utf8_to_gb2312 ($return [' JB ']),//Occupations
' Mo ' = $return [' Mo '],//Mobile phone
' PC ' = $this->utf8_to_gb2312 ($return [' pc ']),//ZIP code
' ph ' = $this->utf8_to_gb2312 ($return [' ph ']),//Contact phone
' PR ' = $this->utf8_to_gb2312 ($return [' PR ']),//Introduction
' PV ' = $this->utf8_to_gb2312 ($return [' PV ']),//province
' rn ' = $this->utf8_to_gb2312 ($return [' RN ']),//real name
' SC ' = $this->utf8_to_gb2312 ($return [' SC ']),//Graduate Schools
' sh ' = $return [' sh '],//Zodiac
' SX ' = $return [' SX '],//gender
' UN ' = $return [' un '],//QQ
' NK ' = $this->utf8_to_gb2312 ($return [' NK '])//Nickname
);
return $arr;
}
Else
{
return failure
return qq_return_failed;
}
}
function Addfriend ($uin)
{
Add new friends
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 success
Switch ($return [' CD '])
{
Case 0:
Allow anyone to add a friend
return qq_addtolist_success;
Break
Case 1:
Need to verify
return Qq_addtolist_needauth;
Break
Case 3:
Do not allow anyone to add to their friends
return qq_addtolist_refuse;
Break
Default:
Unknown code
return qq_addtolist_unknown;
Break
}
}
Else
{
return failure
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 in response status, and CD is 0 for "pass validation". A CD of 1 means "reject plus be a friend". A CD of 2 means "add a friend to the request." RS for the reason you want to 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)
{
//server successfully received information
return qq_return_success;< br>}
Else
{
//failed
return qq_return_failed;
}
}
function Delfriend ($uin)
{
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)
{
Server successfully received information
return qq_return_success;
}
Else
{
Failed
return qq_return_failed;
}
}
function Changestatus ($status)
{
Change state
ver=1.1&cmd=change_stat&seq=&uin=&st=
ST is the State to change, 10 is on-line, 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)
{
Server successfully received information
return qq_return_success;
}
Else
{
Failed
return qq_return_failed;
}
}
function logout ()
{
Exit Login
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)
{
Server successfully received information
return qq_return_success;
}
Else
{
Failed
return qq_return_failed;
}
}
function getmsg ()
{
Get the message
ver=1.1&cmd=getmsgex&seq=&uin=
The MT represents a message type, 99 represents a system message, and 9 represents a user message. UN means the message is sent from the user, MG indicates the message sent, MG message can represent some specific system implication
When mt=99: mg=10 indicates that the user is online, mg=20 indicates that the user is offline, mg=30 indicates that 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)
{
Server successfully received information
if ($return [' MN '] > 0)
{
Number of messages >0
$mts = $this->split_str ($return [' MT ']); Message type
$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; Wrong trip.
$arr = Array ();
for ($i =0; $i < $num; $i + +)
{
$arr [] = Array (
"MT" = $mts [$i],
"UN" and $uns [$i],
"MG" = $this->utf8_to_gb2312 ($mgs [$i])
);
}
return ($arr);
}
Else
{
Number of friends online <=0
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)
{
Server successfully received information
return qq_return_success;
}
Else
{
Failed
return qq_return_failed;
}
}
}
?>
http://www.bkjia.com/PHPjc/947916.html www.bkjia.com true http://www.bkjia.com/PHPjc/947916.html techarticle Friend net about QQ related PHP code (study QQ excellent information), PHP excellent copy code code as follows:/*************************************** ************************* **********...