AsyncSms.php 846 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace tw\async\tasks;
  3. use crmeb\repositories\ShortLetterRepositories;
  4. /**
  5. * 异步发短信
  6. */
  7. class AsyncSms extends Task
  8. {
  9. public function getCmd(): string
  10. {
  11. return 'sms';
  12. }
  13. protected function _exec(array $params)
  14. {
  15. return ShortLetterRepositories::send(true, $params['phone'], $params['data'], $params['template']);
  16. }
  17. /**
  18. * 接口
  19. *
  20. * @param string $phone 接收手机号
  21. * @param array $data 模板参数
  22. * @param string $template 模板代号 见 config/sms.php
  23. * @return bool
  24. */
  25. public static function push(string $phone, array $data, string $template): bool
  26. {
  27. $inst = new self();
  28. return $inst->put([
  29. 'phone' => $phone,
  30. 'data' => $data,
  31. 'template' => $template,
  32. ]);
  33. }
  34. }