优化用户链接检查逻辑,使用fetch替代curl并增强错误提示
This commit is contained in:
22
linuxdo.php
22
linuxdo.php
@@ -79,16 +79,6 @@ if (isset($getTokenArr['access_token'])) {
|
||||
$getUserRes = get_curl('https://connect.linux.do/api/user', 0, 0, 0, $header);
|
||||
|
||||
$getUserArr = json_decode($getUserRes, true);
|
||||
|
||||
$checkLink = get_curl("/api?act=link&connect_id=" . $getUserArr['username']);
|
||||
|
||||
$getCheckLink = json_decode($checkLink, true);
|
||||
|
||||
if ($getCheckLink['code'] == '0') {
|
||||
$data = $getCheckLink['data'];
|
||||
exit('<script>location.href="/play?account=' . $data['username'] . '&token=' . $data['password'] . '"</script>');
|
||||
}
|
||||
|
||||
} else {
|
||||
$err = json_encode($getTokenArr);
|
||||
}
|
||||
@@ -158,6 +148,18 @@ if (isset($getTokenArr['access_token'])) {
|
||||
|
||||
<body oncontextmenu="return false" onselectstart="return false" ondragstart="return false">
|
||||
<input type="hidden" id="linuxdo" value="<?= $getUserArr['username'] ?>">
|
||||
<?php if (!empty($getUserArr['username'])) { ?>
|
||||
<script>
|
||||
const connectId = document.getElementById('linuxdo').value
|
||||
fetch("/api?act=link&connect_id" + connectId).then(res => {
|
||||
if (res.code == '0') {
|
||||
location.href = "/play?account=" + res.data.account + "&token=" + res.data.password;
|
||||
} else {
|
||||
showTips(res.msg, 6, 'error');
|
||||
}
|
||||
})
|
||||
</script>
|
||||
<?php } ?>
|
||||
<?php if (!empty($err)) { ?>
|
||||
授权发生异常:<?= $err ?>
|
||||
<?php } elseif ($getCheckLink['code'] == '1') { ?>
|
||||
|
||||
Reference in New Issue
Block a user