From 5b0873b4d48b1938632c413eefa59fb760207199 Mon Sep 17 00:00:00 2001 From: Kubbo <390378816@qq.com> Date: Sun, 22 Dec 2024 15:48:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96API=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=EF=BC=8C=E5=A2=9E=E5=BC=BA=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E8=BF=9E=E6=8E=A5=E5=AE=89=E5=85=A8=E6=80=A7=E4=B8=8E?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E5=8F=AF=E8=AF=BB=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api.php | 45 +++++++++++++++++++++++++++++---------------- linuxdo.php | 8 +++----- 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/api.php b/api.php index 9620096..3eed81b 100644 --- a/api.php +++ b/api.php @@ -962,38 +962,51 @@ switch ($act) { 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(); + $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) + returnJson(['code' => 1, 'msg' => $mySQLi->connect_error]); + $mySQLi->set_charset($_CONFIG_DB['db_charset']); + $stmt = $mySQLi->prepare('insert into `player_connect_threeparty` (username, type, connect_id) values(?, `linuxdo`, ?)'); + $stmt->bind_param('ss', input('account'), input('connect_id')); + $stmt->execute(); + $stmt->close(); + $stmt = $mySQLi->prepare('select password from player where username=?'); + $stmt->bind_param('s', input('account')); + $stmt->execute(); + $result = $stmt->get_result(); $data = $result->fetch_array(); $result->free_result(); - $stmt2->close(); returnJson($data); + $stmt->close(); + $mySQLi->close(); break; case 'link': - $stmt = $mySQLi->prepare('select player_id from player_connect_threeparty where type=`linuxdo` and connect_id=?'); - $stmt->bind_param('s', input('connect_id')); + $connectId = input('connect_id'); + $tpType = 'linuxdo'; + $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) + returnJson(['code' => 1, 'msg' => $mySQLi->connect_error]); + $mySQLi->set_charset($_CONFIG_DB['db_charset']); + $stmt = $mySQLi->prepare('select username from player_connect_threeparty where type=? and connect_id=? limit 1'); + $stmt->bind_param('ss', $tpType , $connectId); $stmt->execute(); $result = $stmt->get_result(); $row = $result->fetch_array(); - $stmt->close(); - if (!empty($row)) { - $getPlayer = $mySQLi->prepare('select username,password from player where id=? limit 1'); - $getPlayer->bind_param('ass', $row['player_id']); + $getPlayer = $mySQLi->prepare('select username,password from `player` where id=? limit 1'); + $getPlayer->bind_param('s', $row['username']); $getPlayer->execute(); $res = $getPlayer->get_result(); $account = $res->fetch_array(); returnJson(['code' => 0, 'data' => $res]); + $res->free_result(); + $getPlayer->close(); } else { returnJson(['code' => '1']); } + $stmt->close(); + $mySQLi->close(); break; default: echo 'success'; -} \ No newline at end of file +} diff --git a/linuxdo.php b/linuxdo.php index 48d6c30..09ed55f 100644 --- a/linuxdo.php +++ b/linuxdo.php @@ -83,13 +83,11 @@ if (isset($getTokenArr['access_token'])) { $checkLink = get_curl("/api?act=check&connect_id=" . $getUserArr['username']); $getCheckLink = json_decode($checkLink, true); + } else { $err = json_encode($getTokenArr); } - - - ?> @@ -157,7 +155,7 @@ if (isset($getTokenArr['access_token'])) { 授权发生异常: - +
当前尚未有你的游戏账号,请选择
@@ -174,4 +172,4 @@ if (isset($getTokenArr['access_token'])) { - \ No newline at end of file +