header('Authori-zation'), 'Bearer')); $app_id = strtolower(trim($request->header('App-id', ''))); if (!$token) $token = trim(ltrim($request->header('Authorization'), 'Bearer'));//正式版,删除此行,某些服务器无法获取到token调整为 Authori-zation try { $authInfo = UserRepository::parseToken($token); } catch (AuthException $e) { if ($force) return app('json')->make($e->getCode(), $e->getMessage()); } if (!is_null($authInfo)) { if (!in_array($authInfo['user']->mer_id, [0, $request->mer_id()])) { if ($force) return app('json')->make(410000, '账号异常'); } Request::macro('user', function () use (&$authInfo) { return $authInfo['user']; }); Request::macro('tokenData', function () use (&$authInfo) { return $authInfo['tokenData']; }); } Request::macro('isLogin', function () use (&$authInfo) { return !is_null($authInfo); }); Request::macro('uid', function () use (&$authInfo) { return is_null($authInfo) ? 0 : $authInfo['user']->uid; }); return $next($request); } }