QQ登陆
QQ第三方登陆调用接口实现
1 <?php 2 $appid="101353491"; 3 session_start(); 4 $appkey="df4e46ba7da52f787c6e3336d30526e4"; 5 6 $url="http://www.iwebshop.com/index.php"; 7 $urls=URLEncode($url); 8 9 10 $code=$_GET['code']; 11 //获取code值 12 $token="https://graph.qq.com/oauth2.0/token?grant_type=authorization_code&client_id={$appid}&client_secret={$appkey}&code={$code}&redirect_uri={$url}"; 13 $tok=file_get_contents($token); 14 //字符串转为数组 15 $toke=explode("&",$tok); 16 $to=explode("=",$toke[0]); 17 //字符串转为数组 18 $tokenn=$to[1]; 19 //获取openid 20 $open="https://graph.qq.com/oauth2.0/me?access_token={$tokenn}"; 21 $openi=file_get_contents($open); 22 //截取字符串 23 $openid=substr($openi,-38,32); 24 $info="https://graph.qq.com/user/get_user_info?access_token={$tokenn}&oauth_consumer_key={$appid}&openid={$openid}"; 25 $userinfo=file_get_contents($info); 26 //转换为数组 27 $arrinfo=json_decode($userinfo,true); 28 $_SESSION['name']=$arrinfo['nickname']; 29 30 if(empty($arrinfo['nickname'])){ 31 32 echo "<a>登陆失败</a>"; 33 }else{ 34 echo $_SESSION['name']."<a href='show.php'>登陆成功</a>"; 35 }