RegisterMessage.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace App\Module\Sms\Messages;
  3. use App\Module\Sms\Gateway\MyGateway;
  4. use Overtrue\EasySms\Contracts\GatewayInterface;
  5. use Overtrue\EasySms\Gateways\SmsbaoGateway;
  6. use UCore\Helper\Str;
  7. /**
  8. * 注册验证码消息
  9. */
  10. class RegisterMessage extends BaseMessage
  11. {
  12. /**
  13. * 获取消息内容
  14. *
  15. * @param GatewayInterface|null $gateway 短信网关
  16. * @return string
  17. */
  18. public function getContent(GatewayInterface $gateway = null): string
  19. {
  20. if (is_null($gateway)) {
  21. return '';
  22. }
  23. $template = match (true) {
  24. $gateway instanceof MyGateway => '注册验证码:{code}',
  25. $gateway instanceof SmsbaoGateway => $gateway->getConfig()['register_template'] ?? '注册验证码:{code}',
  26. default => ''
  27. };
  28. return Str::strtr($template, $this->getData($gateway));
  29. }
  30. public function getTemplate(GatewayInterface $gateway = null)
  31. {
  32. return 'SMS_REGISTER';
  33. }
  34. public function getData(GatewayInterface $gateway = null)
  35. {
  36. return [
  37. 'code' => $this->data['code'],
  38. ];
  39. }
  40. }