UrsServiceProvider.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace ThirdParty\Urs;
  3. use App\Module\ThirdParty\Services\WebhookDispatchService;
  4. use Illuminate\Support\ServiceProvider;
  5. use ThirdParty\Urs\Request\UrsRequest;
  6. use ThirdParty\Urs\Webhook\UrsCheckWebhook;
  7. use ThirdParty\Urs\Webhook\UrsDepositWebhook;
  8. use ThirdParty\Urs\Webhook\UrsRegisterWebhook;
  9. use ThirdParty\Urs\Webhook\UrsWithdrawWebhook;
  10. /**
  11. * URS包服务提供者
  12. *
  13. * 负责注册URS包的Webhook处理器到ThirdParty模块
  14. */
  15. class UrsServiceProvider extends ServiceProvider
  16. {
  17. /**
  18. * 注册服务
  19. *
  20. * @return void
  21. */
  22. public function register()
  23. {
  24. // 注册URS请求服务
  25. $this->app->singleton('thirdparty.urs.request', function () {
  26. return new UrsRequest();
  27. });
  28. }
  29. /**
  30. * 启动服务
  31. *
  32. * @return void
  33. */
  34. public function boot()
  35. {
  36. // 注册URS包的Webhook处理器
  37. $this->registerWebhookHandlers();
  38. }
  39. /**
  40. * 注册Webhook处理器
  41. *
  42. * @return void
  43. */
  44. protected function registerWebhookHandlers()
  45. {
  46. // 一对一映射:每个路由对应一个专门的处理器
  47. // 每个处理器只处理一种特定的Webhook请求
  48. WebhookDispatchService::registerPackageHandlers('urs', [
  49. 'register' => UrsRegisterWebhook::class, // 注册通知 - 专门处理用户注册
  50. 'deposit' => UrsDepositWebhook::class, // 充值通知 - 专门处理充值操作
  51. 'withdraw' => UrsWithdrawWebhook::class, // 提取通知 - 专门处理提取操作
  52. 'check' => UrsCheckWebhook::class, // 余额检查 - 专门处理余额检查
  53. ]);
  54. }
  55. /**
  56. * 获取提供的服务
  57. *
  58. * @return array
  59. */
  60. public function provides()
  61. {
  62. return [
  63. 'thirdparty.urs.request',
  64. ];
  65. }
  66. }