目錄
申請開發應用
碼雲第三方應用地址
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
}