php快捷登录全集成

/**
* 示例文件,以新浪微博为例,其他平台方法类似
*/
  
//生成登录链接
require_once('sina.php');
$app_key=''; //新浪微博应用App Key
$app_secret=''; //新浪微博应用App Secret
$callback_url='http://yoururl/sina_callback.php'; //回调网址,请根据自己的实际情况修改
  
$sina=new sinaPHP($app_key, $app_secret);
$login_url=$sina->login_url($callback_url); //生成登录链接,部分平台需要权限,格式请参考各平台api文档
echo '<a href="'.$login_url.'">点击进入授权页面</a>';
  
  
//授权回调页面,即生成登录链接时的$callback_url
require_once('sina.php');
$app_key=''; //新浪微博应用App Key
$app_secret=''; //新浪微博应用App Secret
$callback_url='http://yoururl/sina_callback.php'; //回调网址,必须和生成登录链接时相同
  
if(isset($_GET['code']) && $_GET['code']!=''){
    $sina=new sinaPHP($app_key, $app_secret);
    $result=$sina->access_token($callback_url, $_GET['code']); //获取access token
    /**
     * $result['access_token'],用户access token
     * $result['expires_in'],access token的有效期,单位:秒
     * 部分平台会有$result['refresh_token'],refresh token,access token到期后使用refresh token生成新的access token
     * 腾讯微博还需要保存$_GET['openid']
     */
}
  
  
//用户登录授权后操作api
require_once('sina.php');
$app_key=''; //新浪微博应用App Key
$app_secret=''; //新浪微博应用App Secret
$access_token=''; //授权回调页面生成的用户access token
  
$sina=new sinaPHP($app_key, $app_secret, $access_token); //腾讯微博还需要openid,授权回调页面保存的$_GET['openid']
  
$sina_uid=$sina->get_uid(); //登录用户uid
//其他功能请参考sina.php自行使用,或者根据api文档自行添加
//其他平台的使用方法和新浪微博类似,各种api的返回数据格式各有不同,请自行参考各平台的api文档
  
  
//支持refresh token的平台在access token到期后请使用access_token_refresh()生成新的access token

Comments : 0

有问题可在下面发表评论,当然没事也可以在下面吹吹牛皮、扯扯淡!

发表评论

*


Warning: Cannot modify header information - headers already sent by (output started at /www/wwwroot/blog/content/templates/Bitter/footer.php:40) in /www/wwwroot/blog/include/lib/view.php on line 23