From 6f461fa6b683c63429027ebf3635c2a6863fdb4f Mon Sep 17 00:00:00 2001 From: augushong Date: Wed, 24 Nov 2021 17:16:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=B0=81=E8=A3=85=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E5=87=BD=E6=95=B0;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/app/common.php b/app/common.php index 7c3c724..f9564b0 100644 --- a/app/common.php +++ b/app/common.php @@ -3,6 +3,7 @@ use app\common\service\AuthService; use think\facade\Cache; +use think\route\Url; if (!function_exists('__url')) { @@ -121,4 +122,32 @@ if (!function_exists('auth')) { return $check; } +} + + +function json_message($data = [], $code = 0, $msg = '') +{ + if (is_string($data)) { + + if (strpos($data, 'http') === 0 || strpos($data, '/') === 0) { + $data = [ + 'jump_to_url' => $data + ]; + } else { + + $code = $code === 0 ? 500 : $code; + $msg = $data; + $data = []; + } + } else if ($data instanceof Url) { + $data = [ + 'jump_to_url' => (string)$data + ]; + } + + return json([ + 'code' => $code, + 'msg' => $msg, + 'data' => $data + ]); } \ No newline at end of file