新增API支持库

This commit is contained in:
筱锋xiao_lfeng 2022-09-10 15:58:18 +08:00
parent 8b2bf22a42
commit 4e8012e95b
7 changed files with 280 additions and 8 deletions

55
api/get_book/change.php Normal file
View File

@ -0,0 +1,55 @@
<?PHP
/*
* wxxy_class 项目组
* 代码均开源
*/
// 载入头
include($_SERVER['DOCUMENT_ROOT'].'/api/header-control.php');
// 载入组件
$key = htmlspecialchars($_GET['key']);
$student = htmlspecialchars($_GET['student']);
$time = date("Y-m-d H:i:s");
// 构建函数
if ($key == $setting['Key']) {
// 对数据表进行检查
// 对数据表进行写入操作
mysqli_query($conn,"LOCK TABLE ".$setting['SQL_DATA']['book']." WRITE");
$result_book_person = mysqli_query($conn,"SELECT * FROM ".$setting['SQL_DATA']['book']." WHERE s_ID='$student'");
$result_book_person_object = mysqli_fetch_object($result_book_person);
if (empty($result_book_person_object->s_ID)) {
if (mysqli_query($conn,"INSERT INTO ".$setting['SQL_DATA']['book']." (s_ID,getbook,time) VALUES ('$student','TRUE','$time')")) {
// 编译数据
$data = array(
'output'=>'SUCCESS',
'code'=>200,
'info'=>'操作已完成',
);
// 输出数据
echo json_encode($data,JSON_UNESCAPED_UNICODE);
}
} else {
// 编译数据
$data = array(
'output'=>'SQL_DENY',
'code'=>403,
'info'=>'操作拒绝!已经有数据了'
);
// 输出数据
echo json_encode($data,JSON_UNESCAPED_UNICODE);
}
mysqli_query($conn,"UNLOCK TABLE");
} else {
// 编译数据
$data = array(
'output'=>'KEY_ERROR',
'code'=>403,
'info'=>'密钥错误'
);
// 输出数据
echo json_encode($data,JSON_UNESCAPED_UNICODE);
header("HTTP/1.1 403 Forbidden");
}

44
api/get_book/index.php Normal file
View File

@ -0,0 +1,44 @@
<?PHP
/*
* wxxy_class 项目组
* 代码均开源
*/
// 载入头
include($_SERVER['DOCUMENT_ROOT'].'/api/header-control.php');
// 载入组件
$key = htmlspecialchars($_GET['key']);
// 构建函数
if ($key == $setting['Key']) {
// 数据库信息查询
$result_book = mysqli_query($conn,"SELECT a.studentID,a.name,a.get_book,b.getbook FROM ".$setting['SQL_DATA']['info']." a LEFT JOIN ".$setting['SQL_DATA']['book']." b ON a.studentID=b.s_ID");
while ($result_book_object = mysqli_fetch_object($result_book)) {
$array[$result_book_object->studentID] = array(
'studentID'=>$result_book_object->studentID,
'name'=>$result_book_object->name,
'need_book'=>$result_book_object->get_book,
'get_book'=>$result_book_object->getbook
);
}
// 编译数据
$data = array(
'output'=>'SUCCESS',
'code'=>200,
'info'=>'输出成功',
'data'=>$array,
);
// 输出数据
echo json_encode($data,JSON_UNESCAPED_UNICODE);
} else {
// 编译数据
$data = array(
'output'=>'KEY_ERROR',
'code'=>403,
'info'=>'密钥错误'
);
// 输出数据
echo json_encode($data,JSON_UNESCAPED_UNICODE);
header("HTTP/1.1 403 Forbidden");
}

18
api/header-control.php Normal file
View File

@ -0,0 +1,18 @@
<?PHP
/*
* wxxy_class 前置载入配置
* 开源
*/
// 设置请求头
header('Content-Type: application/json;charset=utf-8');
// 获取数据(获取数据库信息)
include($_SERVER['DOCUMENT_ROOT'].'/setting.inc.php');
include($_SERVER['DOCUMENT_ROOT'].'/plugins/sql_conn.php');
// 日志记录
// 日志记录时间
$logs_time = date("Y-m-d H:i:s");
// 日志记录用户使用的IP情况
$logs_ip = $_SERVER["REMOTE_ADDR"];

18
api/index.php Normal file
View File

@ -0,0 +1,18 @@
<?PHP
/*
* wxxy_class 项目组
* 代码均开源
*/
// 载入头
include($_SERVER['DOCUMENT_ROOT'].'/api/header-control.php');
// 编译数据
$data = array(
'output'=>'SUCCESS',
'code'=>200,
'info'=>'当看到此页面代表所有API项目正常运行'
);
// 输出数据
echo json_encode($data,JSON_UNESCAPED_UNICODE);

View File

@ -2,8 +2,19 @@
// 页面ID
$menu_page = 7;
// 载入组件
include($_SERVER['DOCUMENT_ROOT'].'/setting.inc.php');
include($_SERVER['DOCUMENT_ROOT'].'/module/head-check.php');
include($_SERVER['DOCUMENT_ROOT'].'/plugins/function.php');
// 配置信息
$key = htmlspecialchars($_GET['key']);
// 载入信息
$book_url = $setting['API']['Domain'].'/get_book/?key='.$setting['Key'];
$book_ch = curl_init($book_url);
curl_setopt($book_ch,CURLOPT_USERAGENT,$_SERVER['HTTP_USER_AGENT']);
curl_setopt($book_ch, CURLOPT_RETURNTRANSFER, true);
$book = curl_exec($book_ch);
$book = json_decode($book,true);
?>
<!doctype html>
<!--
@ -46,15 +57,86 @@ include($_SERVER['DOCUMENT_ROOT'].'/plugins/function.php');
<div class="card shadow rounded-3">
<div class="card-body">
<div class="row">
<div class="col-12 mb-2">
<div class="row text-center">
<div class="col-12"><font color="red">请勿重复提交数据,谢谢喵~</font></div>
<div class="col-12">手别太快了,上传对图片来</div>
</div>
</div>
<div class="col-12 fs-5 fw-bold mb-3"><i class="bi bi-journal-bookmark"></i> 书本领取登记</div>
<?PHP if ($_COOKIE['studentID'] == '22344233' and $key == $setting['Key']) {
?>
<div class="col-12">
<iframe src="https://wj.qq.com/s2/10750231/ed6b/" frameborder="0" class="container" height="600px"></iframe>
<form action="./get_book_upload.php" method="post">
<div class="row">
<div class="col-12 mb-3">
<select class="form-select form-select-sm" name="student">
<?PHP
$num = 22344201;
while (!empty($book['data'][$num]['studentID'])) {
if ($book['data'][$num]['need_book'] == "FALSE" or $book['data'][$num]['get_book'] == "TRUE") {
?><option value="<?PHP echo $book['data'][$num]['studentID'] ?>" disabled><?PHP echo $book['data'][$num]['name'] ?></option><?PHP
} else {
?><option value="<?PHP echo $book['data'][$num]['studentID'] ?>"><?PHP echo $book['data'][$num]['name'] ?></option><?PHP
}
$num ++;
}
?>
</select>
</div>
<div class="col-12 text-center">
<button class="btn btn-primary" type="submit">提交</button>
</div>
</div>
</form>
</div>
<?PHP
} else {
?>
<div class="col-12">
<table class="table table-striped">
<thead>
<tr>
<th scope="col">学号</th>
<th scope="col">姓名</th>
<th scope="col">需要书</th>
<th scope="col">已领取</th>
</tr>
</thead>
<tbody>
<?PHP
$nums = 22344201;
while (!empty($book['data'][$nums]['studentID'])) {
?>
<tr class="">
<th scope="row"><?PHP echo $book['data'][$nums]['studentID'] ?></th>
<td><?PHP echo $book['data'][$nums]['name'] ?></td>
<td>
<?PHP
if ($book['data'][$nums]['need_book'] == "TRUE") {
echo '需要';
} else {
echo '<font color="red">不需要</font>';
}
?>
</td>
<td>
<?PHP
if ($book['data'][$nums]['need_book'] == "FALSE") {
echo '';
} else {
if ($book['data'][$nums]['get_book'] == "TRUE") {
echo '<font color="green">已领取</font>';
} else {
echo '<font color="red">未领取</font>';
}
}
?>
</td>
</tr>
<?PHP
$nums ++;
}
?>
</tbody>
</table>
</div>
<?PHP
} ?>
</div>
</div>
</div>

55
get_book_upload.php Normal file
View File

@ -0,0 +1,55 @@
<?PHP
/*
* 筱锋xiao_lfeng 分享系统(插件)
* 登录组件
*/
// 定义请求头
header("Content-type:text/html;charset=utf-8");
// 获取组件
include($_SERVER['DOCUMENT_ROOT'].'/setting.inc.php');
include($_SERVER['DOCUMENT_ROOT'].'/plugins/sql_conn.php');
// 获取参数
$student = $_POST['student'];
// 函数构建
// 检查数据是否为空
if (!empty($student)) {
// 载入信息
$book_url = $setting['API']['Domain'].'/get_book/change.php?key='.$setting['Key'].'&student='.$student;
$book_ch = curl_init($book_url);
curl_setopt($book_ch,CURLOPT_USERAGENT,$_SERVER['HTTP_USER_AGENT']);
curl_setopt($book_ch, CURLOPT_RETURNTRANSFER, true);
$book = curl_exec($book_ch);
$book = json_decode($book,true);
if ($book['output'] == 'SUCCESS') {
echo <<<EOF
<script language="javascript">
alert( "已完成!" )
window.location.href = "/get_book.php?key=061823zcw"
</script>
EOF;
} elseif ($book['output'] == 'SQL_DNEY') {
echo <<<EOF
<script language="javascript">
alert( "操作拒绝!已经有数据了" )
window.history.go(-1);
</script>
EOF;
} else {
echo <<<EOF
<script language="javascript">
alert( "缺少密钥" )
window.history.go(-1);
</script>
EOF;
}
} else {
echo <<<EOF
<script language="javascript">
alert( "信息错误,你肯定有毛病" )
window.history.go(-1);
</script>
EOF;
}

View File

@ -21,7 +21,7 @@ function menu_color($menu_num) {
<div class="col-12 mb-1"><a href="/pan.php" class="text-decoration-none <?PHP menu_color(4) ?>"><i class="bi bi-device-hdd"></i> 班级网盘</a></div>
<div class="col-12 mb-1"><a href="/non-member-fty.php" class="text-decoration-none <?PHP menu_color(5) ?>"><i class="bi bi-chat"></i> 青年大学习(全员)</a></div>
<!-- <div class="col-12 mb-1"><a href="/member-ty.php" class="text-decoration-none <?PHP menu_color(6) ?>"><i class="bi bi-chat-dots"></i> 青年大学习(团员)</a></div> -->
<div class="col-12 mb-1"><a href="/non-member-fty.php" class="text-decoration-none <?PHP menu_color(7) ?>"><i class="bi bi-chat"></i> 书本领取登记</a></div>
<div class="col-12 mb-1"><a href="/get_book.php" class="text-decoration-none <?PHP menu_color(7) ?>"><i class="bi bi-journal-bookmark"></i> 书本领取登记</a></div>
</div>
</div>
</div>