PHPackages                             sujun/oauthsdk - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. sujun/oauthsdk

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

sujun/oauthsdk
==============

史上最方便集成第三方登录插件

v1.0.1(9y ago)33721MITPHPPHP &gt;=5.6.0

Since Jun 6Pushed 8y ago1 watchersCompare

[ Source](https://github.com/351699382/OauthSDK)[ Packagist](https://packagist.org/packages/sujun/oauthsdk)[ RSS](/packages/sujun-oauthsdk/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependenciesVersions (4)Used By (0)

OauthSDK,简易集成第三方登录
==================

[](#oauthsdk简易集成第三方登录)

[![Software license](https://camo.githubusercontent.com/3b83d6d1b3b377ba8f41c1e4ac197ad0dc056a760ec10c1f6484aa7b617fcc5a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f68656c6569313132672f7061796d656e742e737667)](LICENSE)[![Latest development](https://camo.githubusercontent.com/fbd0d64a834c65c0454f037d9012c00c63a4c836819b10a576b9273deac8923d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f767072652f7269766572736c65692f7061796d656e742e737667)](https://packagist.org/packages/sujun/oauthsdk)

OauthSDK是什么？
============

[](#oauthsdk是什么)

是第三方登录SDK。︿(￣︶￣)︿

安装
--

[](#安装)

通过composer，这是推荐的方式，可以使用composer.json 声明依赖，或者直接运行下面的命令。

```
    composer require "sujun/oauthsdk": "v1.0.1"
```

放入composer.json文件中

```
    "require": {
         "sujun/oauthsdk": "v1.0.1"
    }
```

然后运行

```
composer update

```

使用方式
====

[](#使用方式)

分三步走。

1、登录处放置第三方登录入口
==============

[](#1登录处放置第三方登录入口)

传type变量，根据此变量判断是QQ、微博、还是微信登录。 如下：login.html 页面

```
QQ登录
微信登录
新浪登录

```

2、生成第三方登录授权地址
=============

[](#2生成第三方登录授权地址)

如下：login.php 页面

```

use OauthSDK\Oauth;

try {

    if (!in_array($_GET['type'], ['qq', 'wechat', 'sina'])) {
        throw new \Exception("暂不支持{$_GET['type']}方式登录", 500);
    }
    $sns = Oauth::getInstance($_GET['type'], array(
        //腾讯QQ登录配置
        'QQ' => array(
            'APP_KEY' => '***', //应用注册成功后分配的 APP ID
            'APP_SECRET' => '***', //应用注册成功后分配的KEY
            'CALLBACK' => '/callback.php?type=qq', //回调URL
        ),
        //新浪微博配置
        'SINA' => array(
            'APP_KEY' => '***',
            'APP_SECRET' => '***',
            'CALLBACK' => '/callback.php?type=sina',
        ),
        //腾讯微信配置
        'WECHAT' => array(
            'APP_KEY' => '***',
            'APP_SECRET' => '***',
            'CALLBACK' => '/callback.php?type=wechat',
        ),
    ));
    //跳转到授权页面
    header('Location: ' . $sns->getRequestCodeURL());

} catch (\Exception $e) {
    echo $e->getMessage();
    header('Location: /login' . );
}

```

3、设置回调地址
========

[](#3设置回调地址)

```
use OauthSDK\Oauth;

try {

    $type = $_GET['type'];
    $code = $_GET['code'];

    if (!in_array($type, ['qq', 'wechat', 'sina'])) {
        throw new \Exception("参数错误", 500);
    }
    if(empty($type) || empty($code)) {
    	throw new \Exception('参数错误~',500);
    }
    $sns = Oauth::getInstance($type, array(
        //腾讯QQ登录配置
        'QQ' => array(
            'APP_KEY' => '***', //应用注册成功后分配的 APP ID
            'APP_SECRET' => '***', //应用注册成功后分配的KEY
            'CALLBACK' => '/callback.php?type=qq', //回调URL
        ),
        //新浪微博配置
        'SINA' => array(
            'APP_KEY' => '***',
            'APP_SECRET' => '***',
            'CALLBACK' => '/callback.php?type=sina',
        ),
        //腾讯微信配置
        'WECHAT' => array(
            'APP_KEY' => '***',
            'APP_SECRET' => '***',
            'CALLBACK' => '/callback.php?type=wechat',
        ),
    ));
    $tokenArr = $sns->getAccessToken($code, []);

    $openid = $tokenArr['openid'];
    $token = $tokenArr['access_token'];

    /*
    $checkData = select * from where openid=$tokenArr['openid'] and type_name = $type;
	if ($_check_data) {
	    //之前绑定
	    //跳至登录
	} */

    //获取当前登录用户信息
    if ($openid) {
        $userinfo = $sns->getUserInfo();
        //处理......
    } else {
        throw new \Exception("系统出错,请稍后再试！", 500);
    }

} catch (\Exception $e) {
    echo $e->errorMessage();
    exit;
}

```

至此完成第三方登录。很多人做法是用绑定的形式，即必须要有本站账号，这时要建一个表存着Openid关系。 表设置可如下:

```
DROP TABLE IF EXISTS `oauth_login`;
CREATE TABLE `oauth_login` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `user_id` int(11) DEFAULT NULL COMMENT '本站用户',
  `openid` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '第三方用户id',
  `unionid` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '微信多平台唯一',
  `type_name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '类型:qq、wechat、sina,
  `access_token` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '访问令牌',
  `param` text COLLATE utf8_unicode_ci COMMENT '返回参数',
  `create_time` datetime DEFAULT NULL,
  `status` tinyint(1) NOT NULL COMMENT '0:正常，1：删除',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='第三方绑定登录用户表';

```

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

3310d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d0c20eff6102f25a31d136b16530787049fdcd4ba99892fae879a91b07797559?d=identicon)[tianlanjusi](/maintainers/tianlanjusi)

---

Top Contributors

[![351699382](https://avatars.githubusercontent.com/u/4371564?v=4)](https://github.com/351699382 "351699382 (14 commits)")

---

Tags

qq

### Embed Badge

![Health badge](/badges/sujun-oauthsdk/health.svg)

```
[![Health](https://phpackages.com/badges/sujun-oauthsdk/health.svg)](https://phpackages.com/packages/sujun-oauthsdk)
```

###  Alternatives

[hwi/oauth-bundle

Support for authenticating users using both OAuth1.0a and OAuth2 in Symfony.

2.4k22.0M77](/packages/hwi-oauth-bundle)[overtrue/socialite

A collection of OAuth 2 packages.

1.4k5.6M90](/packages/overtrue-socialite)[socialiteproviders/qq

Qq.com OAuth2 Provider for Laravel Socialite

50163.8k5](/packages/socialiteproviders-qq)[hehongyuanlove/flarum-auth-qq

Allow users to log in with QQ

111.0k](/packages/hehongyuanlove-flarum-auth-qq)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
