12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- <?php
- namespace app\api\controller\base;
- use app\common\service\WebService;
- use think\Controller;
- use think\exception\HttpResponseException;
- use think\Request;
- class Base extends Controller
- {
- const ERR_CODE_LOGIN = 1;
- protected function _initialize()
- {
- (new WebService())->checkInstalled();
- header('Access-Control-Allow-Origin: *');
- header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, x-token');
- }
-
- protected function json_success($msg = "success", $data = null, $err_code = 0)
- {
-
-
- $result = [
- 'code' => 1,
- 'err_code' => $err_code,
- 'msg' => $msg,
- 'time' => Request::instance()->server('REQUEST_TIME'),
- 'data' => $data,
- ];
- throw new HttpResponseException(json($result));
- }
-
- protected function json_error($msg = "error", $data = null, $err_code = 0)
- {
- $result = [
- 'code' => 0,
- 'err_code' => $err_code,
- 'msg' => $msg,
- 'time' => Request::instance()->server('REQUEST_TIME'),
- 'data' => $data,
- ];
- throw new HttpResponseException(json($result));
- }
- }
|