2021-11-18 09:57:04 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace app\controller\api;
|
|
|
|
|
|
|
|
use app\controller\BaseController;
|
2021-11-29 05:59:29 +00:00
|
|
|
use think\response\Json;
|
2021-11-18 09:57:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* API控制器基础类
|
|
|
|
*/
|
|
|
|
class Base extends BaseController
|
|
|
|
{
|
|
|
|
// 布尔值数字关系
|
|
|
|
public const BOOL_FALSE = 0;
|
|
|
|
public const BOOL_TRUE = 1;
|
|
|
|
|
|
|
|
protected function initialize()
|
|
|
|
{
|
|
|
|
parent::initialize();
|
|
|
|
|
|
|
|
$this->middleware = [
|
|
|
|
'jwt',
|
|
|
|
'apiLogin' => ['except' => $this->noNeedLogin]
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function __call($method, $args)
|
|
|
|
{
|
|
|
|
return $this->json(4004, 'error request!');
|
|
|
|
}
|
2021-11-29 05:59:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 返回封装后的API数据到客户端(对返回内容进行null转空字符串过滤)
|
|
|
|
* 以json格式抛出异常
|
|
|
|
* @access protected
|
|
|
|
* @param integer $code 返回的code
|
|
|
|
* @param mixed $msg 提示信息
|
|
|
|
* @param mixed $data 要返回的数据
|
|
|
|
* @return Json
|
|
|
|
*/
|
|
|
|
protected function json(int $code = 0, $msg = '操作成功', $data = []): Json
|
|
|
|
{
|
|
|
|
$result = [
|
|
|
|
'code' => $code,
|
|
|
|
'msg' => $msg,
|
|
|
|
'data' => arrayNullToString($data)
|
|
|
|
];
|
|
|
|
return json($result);
|
|
|
|
}
|
|
|
|
|
2021-11-18 09:57:04 +00:00
|
|
|
}
|