Feature: New frps api server

合并老的 API,将部分函数集成到 Utils 类中
This commit is contained in:
Akkariin Meiko 2020-01-21 11:10:44 +08:00 committed by GitHub
parent 5a26258cde
commit 96e960a417
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -100,4 +100,77 @@ class Utils {
exit("Invalid CSRF Token"); exit("Invalid CSRF Token");
} }
} }
// 输出禁止错误 Header
public static function sendServerForbidden($msg)
{
Header("HTTP/1.1 403 {$msg}");
Header("Content-type: text/plain", true);
echo json_encode(Array(
'status' => 403,
'message' => $msg
), JSON_UNESCAPED_UNICODE);
exit;
}
// 输出未找到错误 Header
public static function sendServerNotFound($msg)
{
Header("HTTP/1.1 404 {$msg}");
Header("Content-type: text/plain", true);
echo json_encode(Array(
'status' => 404,
'message' => $msg
), JSON_UNESCAPED_UNICODE);
exit;
}
// 输出未找到错误 Header
public static function sendServerBadRequest($msg)
{
Header("HTTP/1.1 400 {$msg}");
Header("Content-type: text/plain", true);
echo json_encode(Array(
'status' => 400,
'message' => $msg
), JSON_UNESCAPED_UNICODE);
exit;
}
// 输出正常消息
public static function sendLoginSuccessful($msg)
{
Header("Content-type: text/plain", true, 200);
echo json_encode(Array(
'status' => 200,
'success' => true,
'message' => $msg
), JSON_UNESCAPED_UNICODE);
exit;
}
// 输出正常消息
public static function sendCheckSuccessful($msg)
{
Header("Content-type: text/plain", true, 200);
echo json_encode(Array(
'status' => 200,
'success' => true,
'message' => $msg
), JSON_UNESCAPED_UNICODE);
exit;
}
// Json 格式消息输出
public static function sendJson($data)
{
Header("Content-type: text/plain", true, 200);
echo json_encode($data, JSON_UNESCAPED_UNICODE);
exit;
}
public static function getBoolean($str)
{
return $str == "true";
}
} }