From b6dbe1ac822cd10350fab3271572ed3912bc1d34 Mon Sep 17 00:00:00 2001 From: XiaoLFeng Date: Sun, 11 Sep 2022 19:26:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=AF=B9=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E7=9A=84=E7=AD=9B=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/class/person.php | 127 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 api/class/person.php diff --git a/api/class/person.php b/api/class/person.php new file mode 100644 index 0000000..54b4d85 --- /dev/null +++ b/api/class/person.php @@ -0,0 +1,127 @@ +text; + +// 构建函数 +if ($key == $sql_key) { + if ($type == 'normal') { + if (!empty($name) and !empty($studentID)) { + // 编译数据 + $data = array( + 'output'=>'DATA_OUT', + 'code'=>403, + 'info'=>'数据多余' + ); + // 输出数据 + echo json_encode($data,JSON_UNESCAPED_UNICODE); + header("HTTP/1.1 403 Forbidden"); + } elseif (empty($name) and empty($studentID)) { + // 编译数据 + $data = array( + 'output'=>'DATA_IN', + 'code'=>403, + 'info'=>'数据缺失' + ); + // 输出数据 + echo json_encode($data,JSON_UNESCAPED_UNICODE); + header("HTTP/1.1 403 Forbidden"); + } else { + function name() { + global $studentID,$name; + if (empty($name)) { + return "studentID='".$studentID."'"; + } elseif (empty($studentID)) { + return "name='".$name."'"; + } + } + // 从数据库获取数据 + $result_person = mysqli_query($conn,"SELECT * FROM ".$setting['SQL_DATA']['info']." WHERE ".name()); + $result_person_object = mysqli_fetch_object($result_person); + if ($result_person_object->studentID !== NULL) { + // 编译数据 + $data = array( + 'output'=>'SUCCESS', + 'code'=>200, + 'info'=>'数据输出成功', + 'data'=>array( + 'studentID'=>$result_person_object->studentID, + 'name'=>$result_person_object->name, + 'dormitory'=>$result_person_object->dormitory, + 'op'=>$result_person_object->op, + 'office'=>$result_person_object->office, + 'gender'=>$result_person_object->gender, + ) + ); + // 输出数据 + echo json_encode($data,JSON_UNESCAPED_UNICODE); + } else { + // 编译数据 + $data = array( + 'output'=>'SELECT_NONE', + 'code'=>403, + 'info'=>'未查询到数据' + ); + // 输出数据 + echo json_encode($data,JSON_UNESCAPED_UNICODE); + header("HTTP/1.1 403 Forbidden"); + } + } + } elseif ($type == 'all') { + // 从数据库获取数据 + $result_person = mysqli_query($conn,"SELECT * FROM ".$setting['SQL_DATA']['info']); + while ($result_person_object = mysqli_fetch_object($result_person)) { + $array[$result_person_object->uid] = array( + 'studentID'=>$result_person_object->studentID, + 'name'=>$result_person_object->name, + 'dormitory'=>$result_person_object->dormitory, + 'op'=>$result_person_object->op, + 'office'=>$result_person_object->office, + 'gender'=>$result_person_object->gender, + ); + } + // 编译数据 + $data = array( + 'output'=>'SUCCESS', + 'code'=>200, + 'info'=>'数据输出成功', + 'data'=>$array, + ); + // 输出数据 + echo json_encode($data,JSON_UNESCAPED_UNICODE); + } else { + // 编译数据 + $data = array( + 'output'=>'TYPE_NONE', + 'code'=>403, + 'info'=>'类型缺失' + ); + // 输出数据 + echo json_encode($data,JSON_UNESCAPED_UNICODE); + header("HTTP/1.1 403 Forbidden"); + } +} else { + // 编译数据 + $data = array( + 'output'=>'KEY_ERROR', + 'code'=>403, + 'info'=>'密钥错误' + ); + // 输出数据 + echo json_encode($data,JSON_UNESCAPED_UNICODE); + header("HTTP/1.1 403 Forbidden"); +} \ No newline at end of file