BaseSms.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 crmeb\basic;
  12. use think\facade\Config;
  13. /**
  14. * Class BaseSms
  15. * @package crmeb\basic
  16. */
  17. abstract class BaseSms extends BaseStorage
  18. {
  19. /**
  20. * 模板id
  21. * @var array
  22. */
  23. protected $templateIds = [];
  24. /**
  25. * 初始化
  26. * @param array $config
  27. * @return mixed|void
  28. */
  29. protected function initialize(array $config)
  30. {
  31. $this->templateIds = Config::get($this->configFile . '.stores.' . $this->name . '.template_id', []);
  32. }
  33. /**
  34. * 获取模板id
  35. * @return array
  36. */
  37. public function getTemplateId()
  38. {
  39. return $this->templateIds;
  40. }
  41. /**
  42. * 提取模板code
  43. * @param string $templateId
  44. * @return null
  45. */
  46. protected function getTemplateCode(string $templateId)
  47. {
  48. return $this->templateIds[$templateId] ?? null;
  49. }
  50. /**
  51. * 发送短信
  52. * @param string $phone
  53. * @param string $templateId
  54. * @param array $data
  55. * @return mixed
  56. */
  57. abstract public function send(string $phone, string $templateId, array $data = []);
  58. }