Place button:
such as in the homepage index.php the following code (that is, the drop button)
<a href= "qq/index.php" >QQ login </a>
Then jump to the qq/index.php file with the following code:
$url = "https://graph.qq.com/oauth2.0/authorize?response_type=code&client_id=[your_appid]&redirect_uri=[ Your_redirect_uri]&scope=[the_scope] "
Header ("Location:".) $url);
Then jumps to the value specified in Redirect_uri=[your_redirect_uri] [Your_redirect_uri], such as qq/callback.php
With a value of code=value.
The qq/callback.php code is as follows:
$code = $_get[' code ');
$url = "Https://graph.qq.com/oauth2.0/token?grant_type=authorization_code&client_id=[your_appid]&client_ Secret=[app key]&code= ". $code. " &state=lin3615&redirect_uri= ". UrlEncode ("http://www.xxxx.net/qq/callback.php");
Get_contents ($url) used to get the returned data
function Get_contents ($url) {
if (Ini_get ("allow_url_fopen") = = "1") {
$response = file_get_contents ($url);
}else{
$ch = Curl_init ();
curl_setopt ($ch, Curlopt_ssl_verifypeer, FALSE);
curl_setopt ($ch, Curlopt_returntransfer, TRUE);
curl_setopt ($ch, Curlopt_url, $url);
$response = curl_exec ($ch);
Curl_close ($ch);
}
return $response;
}
$response = Get_contents ($url);
Parse the data with $access_token values
Parse_str ($response);
Callback ($STR) Convert JSON format to array form
function Callback ($STR)
{
Return Json_decode ($str, true);
}
$url = "https://graph.qq.com/oauth2.0/me?access_token=". $access _token;
$callback = Get_contents ($url);
$callback = Str_replace ("(", "('", $callback);
$callback = Str_replace (")", "')", $callback);
Eval (' $data = '. $callback);
Openid
$openid = $data [' OpenID '];
$url = "https://graph.qq.com/user/get_user_info?access_token= $access _token&oauth_consumer_key=[your_appid] &openid= ". $openid;
$DD = Get_contents ($url);
$DD = Json_decode ($dd, true);
Print_r ($DD);
Where $DD is the related QQ information array
Connect to the database as follows;
If the following data table
User: Users table, normal non-QQ login, fields are:
UID Self-increment
Name User name
Password Password
.....
QQCONNECT:QQ Connection table, QQ connection when used, the fields are:
Quid uid corresponds to UID in user table
OpenID $opendid
Access_token $access _token
......
Connecting to a database
$link = mysql_connect ();
$sql = "Select quid from Qqconnect where openid= ' {$openid} ' and Access_token = ' {$access _token} '";
$res = mysql_query ($sql, $link);
If it already exists,
if ($res && mysql_num_rows ($res))
{
$row = Mysql_fetch_assoc ($res);
$uid = $row [' Quid '];
$query = "SELECT * from user where uid = ' {$uid} '";
$RR = mysql_query ($query, $link);
$rrs = Mysql_fetch_assoc ($RR);
$_session[' uid '] = $rrs [' uid '];
$_session[' name '] = $rrs [' name '];
Header ("Location:".) Home);
}else
{
Does not exist, the binding form is displayed directly
echo "<from>";
Echo ';
echo "</from>";
}