From 96e960a41750a9a6ad2a5c1e6f4d23fad0aaf138 Mon Sep 17 00:00:00 2001 From: Akkariin Meiko Date: Tue, 21 Jan 2020 11:10:44 +0800 Subject: [PATCH] Feature: New frps api server MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 合并老的 API,将部分函数集成到 Utils 类中 --- core/Utils.php | 75 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 74 insertions(+), 1 deletion(-) diff --git a/core/Utils.php b/core/Utils.php index 11e45f4..0f52f44 100755 --- a/core/Utils.php +++ b/core/Utils.php @@ -100,4 +100,77 @@ class Utils { exit("Invalid CSRF Token"); } } -} \ No newline at end of file + + // 输出禁止错误 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"; + } +}