2021-11-18 09:57:04 +00:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace app\controller\api;
|
|
|
|
|
|
|
|
|
|
use app\controller\BaseController;
|
2021-12-09 05:36:47 +00:00
|
|
|
|
use think\facade\Config;
|
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]
|
|
|
|
|
];
|
2021-12-09 05:36:47 +00:00
|
|
|
|
Config::load("extra/wechat","wechat");
|
2021-11-18 09:57:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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-30 10:52:02 +00:00
|
|
|
|
/**
|
|
|
|
|
* 取消程序运行时间和内存限制
|
|
|
|
|
* max_execution_time PHP程序最大执行时间限制(单位:秒)
|
|
|
|
|
* memory_limit 此次的最大运行内存 (单位:字节Byte)
|
|
|
|
|
* set_time_limit 当前操作最长执行时间限制(单位:秒)
|
|
|
|
|
*/
|
|
|
|
|
protected function cancelTimeLimit(int $maxExecTime = 0, int $memory = -1, int $timeOut = 0)
|
|
|
|
|
{
|
|
|
|
|
ini_set('max_execution_time', $maxExecTime);
|
|
|
|
|
ini_set("memory_limit", $memory);
|
|
|
|
|
set_time_limit($timeOut);
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-18 09:57:04 +00:00
|
|
|
|
}
|