UrsServiceProvider.php 2.1 KB

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