This repository has been archived on 2025-01-09. You can view files and clone it, but cannot push or open issues or pull requests.
Files
luowei_exam/api_183_1.php
2025-01-09 11:57:41 +08:00

39 lines
985 B
PHP

<?php
// 获取参数
$student_id = $_GET['student_id'] ?? null;
$english = $_GET['english'] ?? null;
$math = $_GET['math'] ?? null;
$computer = $_GET['computer'] ?? null;
// 校验参数是否完整
if ($student_id === null || $english === null || $math === null || $computer === null) {
// 返回错误信息
echo json_encode([
"error" => "Missing required parameters: student_id, english, math, computer"
]);
exit;
}
// 验证分数是否为数字
if (!is_numeric($english) || !is_numeric($math) || !is_numeric($computer)) {
// 返回错误信息
echo json_encode([
"error" => "Parameters english, math, and computer must be numeric"
]);
exit;
}
// 计算总分
$sum = $english + $math + $computer;
// 封装为 JSON 格式
$response = [
"student_id" => $student_id,
"sum" => (string)$sum // 转为字符串以匹配返回格式
];
// 输出 JSON
header('Content-Type: application/json');
echo json_encode($response);
?>