简单的qq第三方登录

$redirect_uri = urlencode('https://graph.qq.com/index.php');//申请的回掉地址    这个是我的


?>










// 另一个页面
$code = $_GET['code'];
$appID = '';
$appKEY = '';
$redirect_uri = urlencode('');//回调地址


$url = 'https://graph.qq.com/oauth2.0/token?grant_type=authorization_code&client_id=' . $appID . '&client_secret=' . $appKEY . '&code=' . $code . '&redirect_uri=' . $redirect_uri;


$access_token = file_get_contents($url);
//echo $access_token;
parse_str($access_token,$token_arr);
//print_r($token_arr);die;
$token = $token_arr['access_token'];//获取token值
$get_openid_url = 'https://graph.qq.com/oauth2.0/me?access_token=' . $token;
$result_open_data = file_get_contents($get_openid_url);


preg_match('#(\{.*\})#',$result_open_data,$open_json);
//print_r($open_json);die;
$open_arr = json_decode($open_json[1],true);
$open_id = $open_arr['openid'];//获取openid
//echo $open_id;die;


$get_info_url = 'https://graph.qq.com/user/get_user_info?access_token=' . $token  . '&oauth_consumer_key=' . $appID . '&openid=' . $open_id;
$user_info = file_get_contents($get_info_url);
print_r(json_decode($user_info,true));die;//展示对方qq信息
?>




你可能感兴趣的:(简单的qq第三方登录)