true, // 认证开关 'auth_type' => 1, // 认证方式,1为实时认证;2为登录认证。 'auth_group' => 'auth_group', // 用户组数据表名 'auth_group_access' => 'auth_group_access', // 用户-用户组关系表 'auth_rule' => 'auth_rule' // 权限规则表 ]; /** * $prefix表前缀 */ public function __construct() { // 判断配置 if (config('AUTH_CONFIG')) { //可设置配置项 AUTH_CONFIG, 此配置项为数组。 $this->_config = array_merge($this->_config, config('AUTH_CONFIG')); } } /** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle(Request $request, Closure $next, EmployeeModel $EmployeeModel) { // 当前路径 $path = ltrim($request->getPathInfo(), '/'); // 判断是否需要验证登录 if (!in_array($path, $this->except)) { // 获取登录结果 $token = (string) $request->input('access_token_manager', ''); // 解码 $userInfo = AccessToken::decode($token); // 判断登录时效 if (isset($userInfo['error'])) return json_send(['code' => 'no_login', 'msg' => '请您登录', 'data' => $userInfo['error']]); if ($userInfo['type'] != 'manager' || $userInfo['expire'] < time()) return json_send(['code' => 'no_login', 'msg' => '请您登录', 'data' => '登录失效']); // 获取用户信息 if($userInfo['is_admin'] == 1){ $Employee = $EmployeeModel->where('id', $userInfo['uid'])->first(); if (!$Employee) return json_send(['code' => 'no_login', 'msg' => '记录不存在','data'=>'']); if ($Employee->status == 1) return json_send(['code' => 'no_login', 'msg' => '账号已被禁用','data'=>'']); } // 是否是超管 $userInfo['is_super'] = is_super($userInfo['uid'],$userInfo['is_admin'], 'manager') ? 1 : 0; // 追加入 $request['access_token'] = $userInfo; } // 返回下一个闭包 return $next($request); } }