getProperty('guards'); $reflProp->setAccessible(true); $reflProp->setValue($auth, []); $reflProp = $reflClass->getProperty('customCreators'); $reflProp->setAccessible(true); $reflProp->setValue($auth, []); $this->app['auth']->viaRequest('api', function ($request) { // checkRedisPing(); $token = $request->header('token'); if (empty($token)) { $token = $request->input('token'); } $apiToken = $request->header('api_token'); if(empty($apiToken)){ $apiToken = $request->input('api_token'); } if ($apiToken) { $data = ApiFacade::findUserInfoByApiToken($apiToken); if (!empty($data)) { //1天做一次缓存更新 $time=time(); $heartBeatTime= config('cache.heart_beat_time');//心跳时间 if (!empty($data['heart_beat_time'])&&($data['heart_beat_time']+$heartBeatTime) <$time) { $res= ApiSysUserFacade::heartBeat($data['sys_api_token']); if(!$res){ ApiFacade::forgotToken($apiToken); throw new ApiException('common.auth_fail', '认证失败'); } $data['heart_beat_time']=$time; } $data = ApiFacade::updateUserInfoCache($apiToken, $data); return $data; } } else if ($token) { $data = AdminUserFacade::getTokenData($token); if (!empty($data)) { $expires = $data['expiration_time']; //token时间是否过期 if ($expires && time() + (30 * 60) > $expires) { //快过期时,自动延长 $cacheTokenTimeMinute = config('cache.token'); $nowTime = time(); $expiration_time = $nowTime + $cacheTokenTimeMinute; $userInfo['expiration_time'] = $expiration_time;//过期时间 AdminUserFacade::setToken($token, $data); } } return $data; } return null; }); } }