Giter VIP home page Giter VIP logo

yurunoauthlogin's Introduction

YurunOAuthLogin

YurunOAuthLogin是一个PHP 第三方登录授权 SDK,集成了QQ、微信、微博、Github等常用接口。可以轻松嵌入支持 PHP >= 5.4 的任何系统中。

我们有完善的在线技术文档:http://doc.yurunsoft.com/YurunOAuthLogin

同时欢迎各位加入技术支持群:74401592 点击加群,如有问题可以及时解答和修复。

大家在开发中肯定会对接各种各样的第三方平台,我个人精力有限,欢迎各位来提交 PR (码云/Github),一起完善它,让它能够支持更多的平台,更加好用。

支持的登录平台

  • QQ
  • 微信网页扫码、微信内授权
  • 微博
  • 百度
  • Github
  • Gitee
  • Coding
  • 开源**(OSChina)
  • CSDN

后续将不断添加新的平台支持,也欢迎你来提交PR,一起完善!

安装

在您的composer.json中加入配置:

{
    "require": {
        "yurunsoft/yurun-oauth-login": "1.*"
    }
}

代码实例

自v1.2起所有方法统一参数调用,如果需要额外参数的可使用对象属性赋值,具体参考test目录下的测试代码。

下面代码以QQ接口举例,完全可以把QQ字样改为其它任意接口字样使用。

实例化

$qqOAuth = new \Yurun\OAuthLogin\QQ\OAuth2('appid', 'appkey', 'callbackUrl');

登录

$url = $qqOAuth->getAuthUrl();
$_SESSION['YURUN_QQ_STATE'] = $qqOAuth->state;
header('location:' . $url);

回调处理

// 获取accessToken
$accessToken = $qqOAuth->getAccessToken($_SESSION['YURUN_QQ_STATE']);

// 调用过getAccessToken方法后也可这么获取
// $accessToken = $qqOAuth->accessToken;
// 这是getAccessToken的api请求返回结果
// $result = $qqOAuth->result;

// 用户资料
$userInfo = $qqOAuth->getUserInfo();

// 这是getAccessToken的api请求返回结果
// $result = $qqOAuth->result;

// 用户唯一标识
$openid = $qqOAuth->openid;

解决第三方登录只能设置一个回调域名的问题

// 解决只能设置一个回调域名的问题,下面地址需要改成你项目中的地址,可以参考test/QQ/loginAgent.php写法
$qqOAuth->loginAgentUrl = 'http://localhost/test/QQ/loginAgent.php';

$url = $qqOAuth->getAuthUrl();
$_SESSION['YURUN_QQ_STATE'] = $qqOAuth->state;
header('location:' . $url);

特别鸣谢

yurunoauthlogin's People

Contributors

yurunsoft avatar gchehe avatar wei98k avatar

Watchers

James Cloos avatar Ziper avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.