SmsSendServices.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\services\message\sms;
  12. use app\services\BaseServices;
  13. use app\services\serve\ServeServices;
  14. use think\exception\ValidateException;
  15. /**
  16. * 短信发送
  17. * Class SmsSendServices
  18. * @package app\services\message\sms
  19. */
  20. class SmsSendServices extends BaseServices
  21. {
  22. /**
  23. * 发送短信
  24. * @param bool $switch
  25. * @param $phone
  26. * @param array $data
  27. * @param string $template
  28. * @return bool
  29. */
  30. public function send(bool $switch, $phone, array $data, string $template)
  31. {
  32. if ($switch && $phone) {
  33. /** @var ServeServices $services */
  34. $services = app()->make(ServeServices::class);
  35. $res = $services->sms()->send($phone, $template, $data);
  36. if ($res === false) {
  37. throw new ValidateException($services->getError());
  38. }
  39. return true;
  40. } else {
  41. return false;
  42. }
  43. }
  44. }