46 lines
1.3 KiB
PHP
46 lines
1.3 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace app\common\controller;
|
||
|
|
|
||
|
|
use think\Controller;
|
||
|
|
|
||
|
|
|
||
|
|
class BaseCom extends Controller
|
||
|
|
{
|
||
|
|
public $uid = 0;
|
||
|
|
public $redis = '';
|
||
|
|
//初始化
|
||
|
|
protected function _initialize()
|
||
|
|
{
|
||
|
|
//允许跨域
|
||
|
|
header("Access-Control-Allow-Origin: *"); // 允许所有域访问
|
||
|
|
header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS");
|
||
|
|
header("Access-Control-Allow-Headers: Content-Type, Authorization");
|
||
|
|
header("Access-Control-Max-Age: 3600");
|
||
|
|
|
||
|
|
//检测系统是否维护中
|
||
|
|
// $config = get_system_config();
|
||
|
|
$is_maintenance = get_system_config_value('is_maintenance');
|
||
|
|
if($is_maintenance == 2){
|
||
|
|
return V(203, '系统维护中');
|
||
|
|
}
|
||
|
|
$token = input('token', '');
|
||
|
|
if (empty($token)) {
|
||
|
|
$token = request()->header('token');
|
||
|
|
if(empty($token)){
|
||
|
|
return V(301, '登录失效');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
$reslut = model('UserToken')->check_login_token($token);
|
||
|
|
if($reslut['code'] != 1) {
|
||
|
|
model('UserToken')->where('token', $token)->update(['token' => 1]);
|
||
|
|
return V($reslut['code'], $reslut['msg'],$reslut['data']);
|
||
|
|
} else {
|
||
|
|
$this->uid = $reslut['data'];
|
||
|
|
//定义一个常量
|
||
|
|
define('UID', $this->uid);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|