Rumah > pembangunan bahagian belakang > tutorial php > 请问QQ互联的代码是怎么写的??

请问QQ互联的代码是怎么写的??

WBOY
Lepaskan: 2016-06-23 14:25:08
asal
860 orang telah melayarinya

<?php   //应用的APPID  $app_id = "xxxxx";  //应用的APPKEY  $app_secret = "xxxxxxx";  //成功授权后的回调地址  $my_url = "http://www.abc.com";   //Step1:获取Authorization Code  session_start();  $code = $_REQUEST["code"];  if(empty($code))   {     //state参数用于防止CSRF攻击,成功授权后回调时会原样带回     $_SESSION['state'] = md5(uniqid(rand(), TRUE));      //拼接URL          $dialog_url = "https://graph.qq.com/oauth2.0/authorize?response_type=code&client_id="         . $app_id . "&redirect_uri=" . urlencode($my_url) . "&state="        . $_SESSION['state'];     echo("<script> top.location.href='" . $dialog_url . "'</script>");  }   //Step2:通过Authorization Code获取Access Token  if($_REQUEST['state'] == $_SESSION['state'])   {     //拼接URL        $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);     if (strpos($response, "callback") !== false)     {        $lpos = strpos($response, "(");        $rpos = strrpos($response, ")");        $response  = substr($response, $lpos + 1, $rpos - $lpos -1);        $msg = json_decode($response);        if (isset($msg->error))        {           echo "<h3>error:</h3>" . $msg->error;           echo "<h3>msg  :</h3>" . $msg->error_description;           exit;        }     }      //Step3:使用Access Token来获取用户的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);     if (strpos($str, "callback") !== false)     {        $lpos = strpos($str, "(");        $rpos = strrpos($str, ")");        $str  = substr($str, $lpos + 1, $rpos - $lpos -1);     }     $user = json_decode($str);     if (isset($user->error))     {        echo "<h3>error:</h3>" . $user->error;        echo "<h3>msg  :</h3>" . $user->error_description;        exit;     }     echo("Hello " . $user->openid);  }  else   {     echo("The state does not match. You may be a victim of CSRF.");  }?>
Salin selepas log masuk

这是在官网弄下来的代码,
首先在网站上点击超链接,然后跳转到这个php文件,接下来怎么做呢,
云里雾里,一头雾水


回复讨论(解决方案)

QQ互联?你是要做啥呢,QQ开放平台做开发吗?

QQ互联?你是要做啥呢,QQ开放平台做开发吗?
用QQ号绑定网站用户

应该就是QQ开发平台,类似于腾讯微博开发。

sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan