, \Psr\Log\LogLevel::*> */ protected $levels = [ // ]; /** * A list of the exception types that are not reported. * * @var array> */ protected $dontReport = [ // ]; /** * A list of the inputs that are never flashed to the session on validation exceptions. * * @var array */ protected $dontFlash = [ 'current_password', 'password', 'password_confirmation', ]; /** * Register the exception handling callbacks for the application. * * @return void */ public function register() { $this->reportable(function (Throwable $e) { DB::rollBack(); $this->getError($e); $msg = $e->getMessage(); // Log::info($msg); if (strstr($msg, 'access_token is invalid or not latest')) { Log::info("刷新access_token"); $this->refreshToken(); } return false; }); $this->renderable(function (AuthenticationException $e) { $msg = $e->getMessage(); Log::error('AuthenticationException msg:'.$msg); return $this->authFail(); }); $this->renderable(function (Throwable $e) { if (method_exists($e, 'getStatusCode')) { if ($e->getStatusCode() == 405) { return $this->failure("没有对应的路由方法"); }elseif ($e->getStatusCode() == 404) { return $this->failure("没有对应的路由"); } } $msg = $e->getMessage(); if ($e->getCode() == 5000) { return $this->failure($e->getMessage()); } $this->getError($e); Log::error('Throwable msg:'.$msg); if ($msg == 'Route [login] not defined.') return $this->authFail(); if (config('app.env') != 'production') return; $msg = trans('auth.server_error')??'服务器休息,请稍后重试'; return $this->failure($msg); }); } public function refreshToken() { $app = WechatService::app(); $accessToken = $app->getAccessToken(); $token = $accessToken->refresh(); // Log::info($token); $app = WechatService::officialApp(); $accessToken = $app->getAccessToken(); $token = $accessToken->refresh(); // Log::info($token); } }