39 lines
985 B
PHP
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);
|
|
?>
|