diff --git a/linuxdo.php b/linuxdo.php index 7b436a8..b915cda 100644 --- a/linuxdo.php +++ b/linuxdo.php @@ -6,54 +6,55 @@ include 'function.php'; $act = input('act'); $mySQLi = new mysqli($_CONFIG_DB['db_host'], $_CONFIG_DB['db_user'], $_CONFIG_DB['db_password'], $_CONFIG_DB['db_name'], $_CONFIG_DB['db_port']); -if($mySQLi->connect_errno) exit($mySQLi->connect_error); +if ($mySQLi->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; + case 'bind': + $stmt1 = $mySQLi->prepare('insert into `player_connect_threeparty` (player_id, type, connect_id) values(?, `linuxdo`, ?)'); + $stmt1->bind_param('ssisiissis', input('account'), input('connect_id')); + $stmt1->execute(); + $stmt1->close(); + $stmt2 = $mySQLi->prepare('select password from player where username=?'); + $stmt2->bind_param('s', input('account')); + $stmt2->execute(); + $result = $stmt2->get_result(); + $data = $result->fetch_array(); + $result->free_result(); + $stmt2->close(); + exit(json_encode($data)); default: $code = $_GET['code']; - $key = base64_encode($_LINUXDO_CONNECT['client_id'].':'.$_LINUXDO_CONNECT['client_secret']); - + $key = base64_encode($_LINUXDO_CONNECT['client_id'] . ':' . $_LINUXDO_CONNECT['client_secret']); + $header = [ - 'Authorization: Basic '.$key + '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 + 'Authorization: Bearer ' . $access_token ]; - + $getUserRes = get_curl('https://connect.linux.do/api/user', 0, 0, 0, $header); - + $getUserArr = json_decode($getUserRes, true); - $userInfo = [] - + $userInfo = []; + if (isset($getUserArr['id'])) { // 保存每个用户数据项到 session 中 $userInfo['user_id'] = $getUserArr['id']; @@ -69,16 +70,15 @@ switch ($act) { $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 = $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)){ + if (!empty($row)) { $getPlayer = $mySQLi->prepare('select username,password from player where id=?'); $getPlayer->bind_param('s', $row['player_id']); $getPlayer->execute(); @@ -94,7 +94,7 @@ switch ($act) { } // cURL 函数 -function get_curl($url, $post=0, $referer=0, $cookie=0, $header=0, $ua=0, $nobaody=0, $addheader=0) +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); @@ -140,25 +140,59 @@ function get_curl($url, $post=0, $referer=0, $cookie=0, $header=0, $ua=0, $nobao ?> + - + + - + 当前尚未有你的游戏账号,请选择
- Linuxdo账号绑定
- 如果已有账号,请输入账号和密码 -
- - - -
- + Linuxdo账号绑定
+ + + 如果已有账号,请输入账号和密码
+ + + + - - + \ No newline at end of file