| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 | <?phpnamespace app\hander;class HelpHander{    public static function Response($code, $msg, $data = [])    {        $type = gettype($data);        if($type == 'object'){            $data = json_decode(json_encode($data),true);        }        if(is_array($data)){            $data = array_change_line_to_hump($data);        }        $json = [            'code' => $code,            'message' => $msg,            'data' => $data        ];        throw new \think\exception\HttpResponseException(json($json));        return;    }    public static function success($data = [], $msg = '')    {        $type = gettype($data);        if($type == 'object'){            $data = json_decode(json_encode($data),true);        }        if(is_array($data)){            $data = array_change_line_to_hump($data);        }        $json = [            'code' => 0,            'message' => $msg,            'data' => $data        ];        throw new \think\exception\HttpResponseException(json($json));        return;    }    public static function error($msg, $code = 1, $data =null)    {        $code = $code == 0 ? 1 : $code; // code不能等于0        $type = gettype($data);        if($type == 'object'){            $data = json_decode(json_encode($data),true);        }        if(is_array($data)){            $data = array_change_line_to_hump($data);        }        $json = [            'code' => $code,            'message' => $msg,            'data' => $data        ];        throw new \think\exception\HttpResponseException(json($json));        return;    }}
 |