From 88952cfb7a88cf78f6f924df04aab9b0fa1e1110 Mon Sep 17 00:00:00 2001 From: Kubbo <390378816@qq.com> Date: Sat, 21 Dec 2024 17:59:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20Linuxdo=20=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E4=B8=8E=E7=BB=91=E5=AE=9A=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- linuxdo.php | 164 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 164 insertions(+) create mode 100644 linuxdo.php diff --git a/linuxdo.php b/linuxdo.php new file mode 100644 index 0000000..7b436a8 --- /dev/null +++ b/linuxdo.php @@ -0,0 +1,164 @@ +connect_errno) exit($mySQLi->connect_error); +$mySQLi->set_charset($_CONFIG_DB['db_charset']); + +switch ($act) { + case 'reg': + $player = [ + 'username' => $userInfo['user_username'], + 'password' => $userInfo['user_api_key'], + 'email' => $userInfo['user_email'], + 'reg_ip' => '127.0.0.1', + 'reg_time' => time(), + 'reg_source' => 'linuxdo', + ] + $stmt = $mySQLi->prepare('select player_id from player_connect_threeparty where type='linuxdo' and connect_id=?'); + $stmt->bind_param('s', $userInfo['user_username']); + $stmt->execute(); + break; + default: + $code = $_GET['code']; + + $key = base64_encode($_LINUXDO_CONNECT['client_id'].':'.$_LINUXDO_CONNECT['client_secret']); + + $header = [ + 'Authorization: Basic '.$key + ]; + + $post = http_build_query([ + 'grant_type' => 'authorization_code', + 'code' => $code, + 'redirect_uri' => '' + ]); + + $getTokenRes = get_curl('https://connect.linux.do/oauth2/token', $post, 0, 0, $header); + + $getTokenArr = json_decode($getTokenRes, true); + + if (isset($getTokenArr['access_token'])) { + $access_token = $getTokenArr['access_token']; + + $header = [ + 'Authorization: Bearer '.$access_token + ]; + + $getUserRes = get_curl('https://connect.linux.do/api/user', 0, 0, 0, $header); + + $getUserArr = json_decode($getUserRes, true); + $userInfo = [] + + if (isset($getUserArr['id'])) { + // 保存每个用户数据项到 session 中 + $userInfo['user_id'] = $getUserArr['id']; + $userInfo['user_sub'] = $getUserArr['sub']; + $userInfo['user_username'] = $getUserArr['username']; + $userInfo['user_login'] = $getUserArr['login']; + $userInfo['user_name'] = $getUserArr['name']; + $userInfo['user_email'] = $getUserArr['email']; + $userInfo['user_avatar_template'] = $getUserArr['avatar_template']; + $userInfo['user_avatar_url'] = $getUserArr['avatar_url']; + $userInfo['user_active'] = $getUserArr['active']; + $userInfo['user_trust_level'] = $getUserArr['trust_level']; + $userInfo['user_silenced'] = $getUserArr['silenced']; + $userInfo['user_external_ids'] = $getUserArr['external_ids'] ?? 'null'; + $userInfo['user_api_key'] = $getUserArr['api_key']; + + } + + // 判断是否已经关联 + $stmt = $mySQLi->prepare('select player_id from player_connect_threeparty where type='linuxdo' and connect_id=?'); + $stmt->bind_param('s', $userInfo['user_username']); + $stmt->execute(); + $result = $stmt->get_result(); + $row = $result->fetch_array(); + if(!empty($row)){ + $getPlayer = $mySQLi->prepare('select username,password from player where id=?'); + $getPlayer->bind_param('s', $row['player_id']); + $getPlayer->execute(); + $res = $getPlayer->get_result(); + $account = $res->fetch_array(); + exit(""); + } + //echo json_encode($getUserArr); + } else { + echo json_encode($getTokenArr); + } + break; +} + +// cURL 函数 +function get_curl($url, $post=0, $referer=0, $cookie=0, $header=0, $ua=0, $nobaody=0, $addheader=0) +{ + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + $httpheader[] = "Accept: */*"; + $httpheader[] = "Accept-Encoding: gzip,deflate,sdch"; + $httpheader[] = "Accept-Language: zh-CN,zh;q=0.8"; + $httpheader[] = "Connection: close"; + if ($header) { + $httpheader = array_merge($httpheader, $header); + } + curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader); + if ($post) { + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, $post); + } + if ($header) { + curl_setopt($ch, CURLOPT_HEADER, false); + } + if ($cookie) { + curl_setopt($ch, CURLOPT_COOKIE, $cookie); + } + if ($referer) { + if ($referer == 1) { + curl_setopt($ch, CURLOPT_REFERER, ''); + } else { + curl_setopt($ch, CURLOPT_REFERER, $referer); + } + } + if ($ua) { + curl_setopt($ch, CURLOPT_USERAGENT, $ua); + } else { + curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36"); + } + if ($nobaody) { + curl_setopt($ch, CURLOPT_NOBODY, 1); + } + curl_setopt($ch, CURLOPT_ENCODING, "gzip"); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + $ret = curl_exec($ch); + curl_close($ch); + return $ret; +} + +?> + +
+ + + + + 当前尚未有你的游戏账号,请选择