AsyncSms.php 845 B

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