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) { // 当前路径 $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') return json_send(['code' => 'no_login', 'msg' => '请您登录', 'data' => '登录失效']); if ($userInfo['expire'] < time()) return json_send(['code' => 'no_login', 'msg' => '登录失效,请您重新登录', 'data' => '登录失效']); // 获取就得令牌 // $oldToken = (new AdminUser())->getLogin($userInfo['uid'],'manager'); // 比对令牌 // if( $oldToken != md5($token) ) return json_send(['code'=>'no_login','msg'=>'登录失效,请重新登录']); // 是否是超管 $userInfo['is_super'] = is_super($userInfo['uid'], 'manager') ? 1 : 0; // 追加入 $request['access_token'] = $userInfo; } // 返回下一个闭包 return $next($request); } }