Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. namespace crmeb\basic;
  3. use think\facade\Config;
  4. abstract class BaseMessage extends BaseStorage
  5. {
  6. /**
  7. * 模板id
  8. * @var array
  9. */
  10. protected $templateIds = [];
  11. /**
  12. * openId
  13. * @var string
  14. */
  15. protected $openId;
  16. /**
  17. * 跳转链接
  18. * @var string
  19. */
  20. protected $toUrl;
  21. /**
  22. * 颜色
  23. * @var string
  24. */
  25. protected $color;
  26. /**
  27. * 初始化
  28. * @param array $config
  29. * @return mixed|void
  30. */
  31. protected function initialize(array $config)
  32. {
  33. $this->templateIds = Config::get($this->configFile . '.stores.' . $this->name . '.template_id', []);
  34. }
  35. /**
  36. * 是否记录日志
  37. * @return mixed
  38. */
  39. public function isLog()
  40. {
  41. $isLog = Config::get($this->configFile . 'isLog', false);
  42. return Config::get($this->configFile . '.stores.' . $this->name . '.isLog', $isLog);
  43. }
  44. /**
  45. * 获取模板id
  46. * @return array
  47. */
  48. public function getTemplateId()
  49. {
  50. return $this->templateIds;
  51. }
  52. /**
  53. * openid
  54. * @param string $openId
  55. * @return $this
  56. */
  57. public function to(string $openId)
  58. {
  59. $this->openId = $openId;
  60. return $this;
  61. }
  62. /**
  63. * 跳转路径
  64. * @param string $url
  65. * @return $this
  66. */
  67. public function url(string $url)
  68. {
  69. $this->toUrl = $url;
  70. return $this;
  71. }
  72. /**
  73. * 设置背景颜色
  74. * @param string $color
  75. * @return $this
  76. */
  77. public function color(?string $color)
  78. {
  79. $this->color = $color;
  80. return $this;
  81. }
  82. /**
  83. * 提取模板code
  84. * @param string $templateId
  85. * @return null
  86. */
  87. protected function getTemplateCode(string $templateId)
  88. {
  89. return $this->templateIds[$templateId] ?? null;
  90. }
  91. /**
  92. * 恢复默认值
  93. */
  94. protected function clear()
  95. {
  96. $this->openId = null;
  97. $this->toUrl = null;
  98. $this->color = null;
  99. }
  100. /**
  101. * 发送消息
  102. * @param string $templateId
  103. * @param array $data
  104. * @return mixed
  105. */
  106. abstract public function send(string $templateId, array $data = []);
  107. /**
  108. * 添加模板
  109. * @param string $shortId
  110. * @return mixed
  111. */
  112. abstract public function add(string $shortId);
  113. /**
  114. * 删除模板
  115. * @param string $templateId
  116. * @return mixed
  117. */
  118. abstract public function delete(string $templateId);
  119. /**
  120. * 获取所有模板
  121. * @return mixed
  122. */
  123. abstract public function list();
  124. }