mergeConfigFrom( __DIR__ . '/../Config/thirdparty.php', 'thirdparty' ); // 注册服务 $this->registerServices(); } /** * 启动服务 * * @return void */ public function boot() { // 注册路由 $this->registerRoutes(); // 注册视图 $this->registerViews(); // 注册命令 $this->registerCommands(); // 注册事件监听器 $this->registerEventListeners(); // 发布资源 $this->publishResources(); } /** * 注册服务 * * @return void */ protected function registerServices() { // 注册第三方服务核心服务 $this->app->singleton('thirdparty.service', function () { return new \App\Module\ThirdParty\Services\ThirdPartyService(); }); // 注册凭证管理服务 $this->app->singleton('thirdparty.credential', function () { return new \App\Module\ThirdParty\Services\CredentialService(); }); // 注册监控服务 $this->app->singleton('thirdparty.monitor', function () { return new \App\Module\ThirdParty\Services\MonitorService(); }); // 注册日志服务 $this->app->singleton('thirdparty.log', function () { return new \App\Module\ThirdParty\Services\LogService(); }); // 注册配额管理服务 $this->app->singleton('thirdparty.quota', function () { return new \App\Module\ThirdParty\Services\QuotaService(); }); // 注册Webhook分发服务 $this->app->singleton('thirdparty.webhook', function () { return new \App\Module\ThirdParty\Services\WebhookDispatchService(); }); // 注册验证器 $this->app->singleton(\App\Module\ThirdParty\Validators\ServiceValidator::class); $this->app->singleton(\App\Module\ThirdParty\Validators\CredentialValidator::class); } /** * 注册路由 * * @return void */ protected function registerRoutes() { // 注册后台管理路由 if (file_exists($adminRoutes = __DIR__ . '/../Routes/admin.php')) { Route::middleware(['web', 'admin']) ->prefix(config('admin.route.prefix', 'admin') . '/thirdparty') ->group($adminRoutes); } // 注册Webhook路由 if (file_exists($webhookRoutes = __DIR__ . '/../Routes/webhook.php')) { Route::middleware(['api']) ->prefix('thirdParty/webhook') ->name('thirdparty.webhook.') ->group($webhookRoutes); } // 注册API路由(如果需要) if (file_exists($apiRoutes = __DIR__ . '/../Routes/api.php')) { Route::middleware(['api']) ->prefix('api/thirdparty') ->group($apiRoutes); } } /** * 注册视图 * * @return void */ protected function registerViews() { // 注册视图命名空间 $this->loadViewsFrom(__DIR__ . '/../Views', 'thirdparty'); } /** * 注册命令 * * @return void */ protected function registerCommands() { if ($this->app->runningInConsole()) { $this->commands([ \App\Module\ThirdParty\Commands\InsertThirdPartyAdminMenu::class, \App\Module\ThirdParty\Commands\RestructureExternalManagementMenu::class, \App\Module\ThirdParty\Commands\HealthCheckCommand::class, \App\Module\ThirdParty\Commands\QuotaResetCommand::class, \App\Module\ThirdParty\Commands\CleanupLogsCommand::class, \App\Module\ThirdParty\Commands\SyncServicesCommand::class, \App\Module\ThirdParty\Commands\TestServiceCommand::class, \App\Module\ThirdParty\Commands\TestBaseArchitectureCommand::class, \App\Module\ThirdParty\Commands\WebhookMappingCommand::class, \App\Module\ThirdParty\Commands\TestUrsRequestCommand::class, ]); } } /** * 注册事件监听器 * * @return void */ protected function registerEventListeners() { // 注册事件监听器 $events = [ // API调用事件监听器 \App\Module\ThirdParty\Events\ApiCallEvent::class => [ \App\Module\ThirdParty\Listeners\ApiCallLogListener::class, \App\Module\ThirdParty\Listeners\QuotaManagementListener::class, ], // 服务状态变更事件监听器 \App\Module\ThirdParty\Events\ServiceStatusChangedEvent::class => [ \App\Module\ThirdParty\Listeners\ServiceStatusMonitorListener::class, \App\Module\ThirdParty\Listeners\AlertNotificationListener::class . '@handleServiceStatusChanged', ], // 配额告警事件监听器 \App\Module\ThirdParty\Events\QuotaAlertEvent::class => [ \App\Module\ThirdParty\Listeners\AlertNotificationListener::class . '@handleQuotaAlert', ], // 监控告警事件监听器 \App\Module\ThirdParty\Events\MonitorAlertEvent::class => [ \App\Module\ThirdParty\Listeners\AlertNotificationListener::class . '@handleMonitorAlert', ], ]; foreach ($events as $event => $listeners) { foreach ($listeners as $listener) { \Illuminate\Support\Facades\Event::listen($event, $listener); } } } /** * 发布资源 * * @return void */ protected function publishResources() { if ($this->app->runningInConsole()) { // 发布配置文件 $this->publishes([ __DIR__ . '/../Config/thirdparty.php' => config_path('thirdparty.php'), ], 'thirdparty-config'); // 发布数据库迁移文件 $this->publishes([ __DIR__ . '/../Databases/GenerateSql/thirdparty_tables.sql' => database_path('sql/thirdparty_tables.sql'), ], 'thirdparty-migrations'); // 发布视图文件(如果有) if (is_dir(__DIR__ . '/../Resources/views')) { $this->publishes([ __DIR__ . '/../Resources/views' => resource_path('views/vendor/thirdparty'), ], 'thirdparty-views'); } // 发布前端资源(如果有) if (is_dir(__DIR__ . '/../Resources/assets')) { $this->publishes([ __DIR__ . '/../Resources/assets' => public_path('vendor/thirdparty'), ], 'thirdparty-assets'); } } } /** * 获取提供的服务 * * @return array */ public function provides() { return [ 'thirdparty.service', 'thirdparty.credential', 'thirdparty.monitor', 'thirdparty.log', 'thirdparty.quota', 'thirdparty.webhook', ]; } }