hug-code/oauth

第三方授权登陆 QQ登陆 新浪微博登陆 github登陆

1.0.0 2020-11-11 08:11 UTC

This package is not auto-updated.

Last update: 2024-10-25 01:01:55 UTC


README

安装

composer require HugCode/Oauth

Github 授权登陆

github API地址:https://developer.github.com/

登陆流程:http://www.hug-code.cn/article/1070.shtml

// 定义配置文件
$config = [
    'client_id'=>'xxxxxxxxxxx',
    'client_secret'=>'xxxxxxxxxxxxxxxxxxxxxxx'
];

// 引入包
use HugCode\Third\Login\GithubLogin;
use HugCode\Third\Exception\MessageException;

// 调用登陆方法
try{
    $oauth = new GithubLogin($config);
    $user_info = $oauth->login();
}catch (MessageException $e){
    var_dump($e->getErrorMessage());
}

新浪微博 授权登陆

新浪微博开放平台: https://open.weibo.com/

登陆流程:http://www.hug-code.cn/article/1081.shtml

// 定义配置文件
$config = [
    'app_key' => 'xxxxxxxxxxx',
    'app_secret' => 'xxxxxxxxxxxxxxxxxxx',
    'redirect_uri' => '新浪后台配置的回调地址'
];

// 引入包
use HugCode\Third\Login\SinaLogin;
use HugCode\Third\Exception\MessageException;

//调用登陆方法
try{
    $oauth = new SinaLogin($config);
    $user_info = $oauth->login();
}catch (MessageException $e){
    var_dump($e->getErrorMessage());
}

QQ 授权登陆

QQ 互联地址:https://connect.qq.com/index.html

登陆流程:http://www.hug-code.cn/article/1076.shtml

// 定义配置文件
$config = [
        'app_id' => 'xxxxxxxx',
        'app_key' => 'xxxxxxxxxxxxxxxxxxxxx',
        'redirect_uri' => 'QQ互联上配置的回调地址'
];


// 引入包
use HugCode\Third\Login\QqLogin;
use HugCode\Third\Exception\MessageException;

// 调用登陆方法
try{
    $oauth = new QqLogin($config);
    $user_info = $oauth->login();
}catch (MessageException $e){
    var_dump($e->getErrorMessage());
}