php对接码云gitee登录 api

目录

    • 申请开发应用
      • API文档
      • 对接gitee登录 OAuth流程(注意是post请求还是get请求)
    • php对接(这里使用的是thinkphp5.1)
      • 配置设置
      • api文件(可能要自己改下命名空间)
      • 调用
      • 返回值
    • 已制作的插件地址

申请开发应用

码云第三方应用地址
https://gitee.com/oauth/applications

API文档

https://gitee.com/api/v5/swagger#/getV5ReposOwnerRepoStargazers?ex=no

对接gitee登录 OAuth流程(注意是post请求还是get请求)

1、带入response_type(参数为code)、client_id、redirect_uri、state(防止CSRF攻击)发起请求https://gitee.com/oauth/authorize(get请求)
2、同意授权
3、返回code进入回调地址
4、通过grant_type(参数为authorization_code)、client_id、redirect_uricode、client_secret、code请求
https://gitee.com/oauth/token获取accesstoken(post请求)
5、使用accesstoken请求https://graph.qq.com/oauth2.0/me获取用户信息(get请求)

php对接(这里使用的是thinkphp5.1)

配置设置

appid=Client ID
appkey=Client Secret
callback=码云上设置的回调地址
在这里插入图片描述

api文件(可能要自己改下命名空间)

链接:https://pan.baidu.com/s/1gckyOtJvBy29ipu6O4XFsg
提取码:pk6u

调用

//访问码云授权登录页面
public function qqLogin()
{
   $oauth = new \plugins\gitee_login\lib\Oauth();
   $oauth->login();
}

//回调函数
function callback()
{
    //请求accesstoken
    $oauth = new \plugins\gitee_login\lib\Oauth();
    $accesstoken = $oauth->callback();

    //设置有效时长(7天)
    // cookie('accesstoken', $accesstoken, 24 * 60 * 60 * 7);

    //根据accesstoken获取用户的基本信息
    $qc = new \plugins\gitee_login\lib\QC($accesstoken);
    $userinfo = $qc->get_user_info();

    //用户信息
    dump($userinfo);

    //自行处理业务逻辑 如加密等

}

返回值

array(29) {
   ["id"] => int(XXXXX)
   ["login"] => string(14) "XXXXXX"
   ["name"] => string(9) "XXXXX"
   ["avatar_url"] => string(40) "https://gitee.com/assets/no_portrait.png"
   ["url"] => string(45) "https://gitee.com/api/v5/users/XXXXX"
   ["html_url"] => string(32) "https://gitee.com/XXXXX"
   ["followers_url"] => string(55) "https://gitee.com/api/v5/users/XXXXX/followers"
   ["following_url"] => string(72) "https://gitee.com/api/v5/users/XXXXX/following_url{/other_user}"
   ["gists_url"] => string(61) "https://gitee.com/api/v5/users/XXXXX/gists{/gist_id}"
   ["starred_url"] => string(68) "https://gitee.com/api/v5/users/XXXXX/starred{/owner}{/repo}"
   ["subscriptions_url"] => string(59) "https://gitee.com/api/v5/users/XXXXX/subscriptions"
   ["organizations_url"] => string(50) "https://gitee.com/api/v5/users/XXXXX/orgs"
   ["repos_url"] => string(51) "https://gitee.com/api/v5/users/XXXXX/repos"
   ["events_url"] => string(62) "https://gitee.com/api/v5/users/XXXXX/events{/privacy}"
   ["received_events_url"] => string(61) "https://gitee.com/api/v5/users/XXXXX/received_events"
   ["type"] => string(4) "User"
   ["site_admin"] => bool(false)
   ["blog"] => string(0) ""
   ["weibo"] => string(0) ""
   ["bio"] => string(0) ""
   ["public_repos"] => int(1)
   ["public_gists"] => int(0)
   ["followers"] => int(0)
   ["following"] => int(1)
   ["stared"] => int(2)
   ["watched"] => int(7)
   ["created_at"] => string(25) "2018-05-23T15:25:20+08:00"
   ["updated_at"] => string(25) "2020-04-08T16:06:09+08:00"
   ["email"] => NULL
 }

已制作的插件地址

https://www.thinkcmf.com/appstore/plugins.html

你可能感兴趣的:(php对接码云gitee登录 api)