12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <?php
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- namespace app\common\server;
-
-
- use think\exception\HttpResponseException;
- use think\Response;
- use think\response\Json;
-
-
- class JsonServer
- {
- private static $SUCCESS = 1;
- private static $Error = 0;
-
-
-
- private static function result(int $code, int $show, string $msg='OK', array $data=[], int $httpStatus=200) :Json
- {
- $result = array(
- 'code' => $code,
- 'show' => $show,
- 'msg' => $msg,
- 'data' => $data
- );
- return json($result, $httpStatus);
- }
-
-
-
- public static function success(string $msg='OK', array $data=[], int $code = 1, int $show = 0) : Json
- {
- return self::result($code, $show, $msg, $data);
- }
-
-
-
- public static function error(string $msg='Error', array $data=[],int $code = 0, int $show = 1) : Json
- {
- return self::result($code, $show, $msg, $data);
- }
-
-
-
- public static function throw(string $msg='Error', array $data=[], int $code=0, int $show = 1)
- {
- $data = array('code'=>$code, 'show'=>$show, 'msg'=>$msg, 'data'=>$data);
- $response = Response::create($data, 'json', 200);
- throw new HttpResponseException($response);
- }
- }
|