Home>Article>Backend Development> PHP simulates QQ web version authorized login

PHP simulates QQ web version authorized login

little bottle
little bottle forward
2019-04-20 10:05:23 5610browse

The editor of this article will take you to learn how to use PHP to simulate QQ web version authorization login. The code is attached, which has certain reference value. Let's learn it together!

Step one:

First log in to the QQ Internet homepagehttps://connect.qq.com/ for personal/enterprise authentication. The review time is approximately one week.

Create the application after passing the authentication:

The two parameters of the application,APP IDandAPP Key, are mainly used here.

You also need to fill in the callback address, which is to request the qq interface to obtain the code parameter callback address to you

Second step:

After the preparation work is completed, you can access the QQ authorization and directly upload the demo code:


 top.location.href='" . $dialog_url . "'"); } //获取qq回调时返回的code参数 $code = $_REQUEST["code"];//存放Authorization Code /* * NO.2 通过Authorization Code获取Access Token */ if($_REQUEST['state'] == $_SESSION['qq_state'] ) { //拼接URL获取access_token $token_url = "https://graph.qq.com/oauth2.0/token?grant_type=authorization_code&"."client_id=" . $app_id . "&redirect_uri=" . urlencode($my_url)."&client_secret=" . $app_secret . "&code=" . $code; $response = file_get_contents($token_url); } /* * NO.3:获取用户openID */ //把传回来的数据参数变量化 $params = array(); parse_str($response, $params); $graph_url = "https://graph.qq.com/oauth2.0/me?access_token=".$params['access_token']; $str = file_get_contents($graph_url); $user = json_decode($str);//存放返回的数据 client_id ,openid /* * NO.4:使用access_token来获取所接受的用户信息。 */ $user_data_url = "https://graph.qq.com/user/get_user_info?access_token={$params['access_token']}&oauth_consumer_key={$app_id}&openid={$user->openid}&format=json"; $user_data = file_get_contents($user_data_url);//此为获取到的user信息 $user_data = json_decode($user_data, true);

After obtaining the user information, you can make a series of logical judgments . It's that simple.

If you want to become an industry expert, you have to study hard and learn more PHP tutorials. Please pay attention to thePHP video tutorialon the PHP Chinese website!

The above is the detailed content of PHP simulates QQ web version authorized login. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete