CaptchaMessage.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /**
  3. * @link:http://www.gdqijianshi.com/
  4. * @copyright: Copyright (c) 2020 广东七件事集团
  5. * 验证码消息
  6. * Author: zal
  7. * Date: 2020-04-23
  8. * Time: 15:11
  9. */
  10. namespace common\helpers\sms;
  11. use Overtrue\EasySms\Contracts\GatewayInterface;
  12. use Overtrue\EasySms\Message;
  13. class CaptchaMessage extends Message
  14. {
  15. protected $captcha;
  16. protected $captchaConfig;
  17. // protected $strategy = OrderStrategy::class; // 定义本短信的网关使用策略,覆盖全局配置中的 `default.strategy`
  18. // protected $gateways = ['alidayu', 'yunpian', 'juhe']; // 定义本短信的适用平台,覆盖全局配置中的 `default.gateways`
  19. public function __construct($captcha, $captchaConfig)
  20. {
  21. $this->captcha = $captcha;
  22. $this->captchaConfig = $captchaConfig;
  23. }
  24. // 定义直接使用内容发送平台的内容
  25. public function getContent(GatewayInterface $gateway = null)
  26. {
  27. return sprintf('您的验证码为:', $this->captcha);
  28. }
  29. // 定义使用模板发送方式平台所需要的模板 ID
  30. public function getTemplate(GatewayInterface $gateway = null)
  31. {
  32. return $this->captchaConfig['template_id'];
  33. }
  34. // 模板参数
  35. public function getData(GatewayInterface $gateway = null)
  36. {
  37. $data = [
  38. $this->captchaConfig['template_variable'] => $this->captcha
  39. ];
  40. if (!empty($this->captchaConfig['project'])) {
  41. $data['project'] = $this->captchaConfig['project'];
  42. }
  43. return $data;
  44. }
  45. }