123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- <?php
- // +----------------------------------------------------------------------
- // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
- // +----------------------------------------------------------------------
- // | Author: CRMEB Team <admin@crmeb.com>
- // +----------------------------------------------------------------------
- namespace crmeb\basic;
- use think\facade\Config;
- abstract class BaseMessage extends BaseStorage
- {
- /**
- * 模板id
- * @var array
- */
- protected $templateIds = [];
- /**
- * openId
- * @var string
- */
- protected $openId;
- /**
- * 跳转链接
- * @var string
- */
- protected $toUrl;
- /**
- * 颜色
- * @var string
- */
- protected $color;
- /**
- * 初始化
- * @param array $config
- * @return mixed|void
- */
- protected function initialize(array $config)
- {
- $this->templateIds = Config::get($this->configFile . '.stores.' . $this->name . '.template_id', []);
- }
- /**
- * 是否记录日志
- * @return mixed
- */
- public function isLog()
- {
- $isLog = Config::get($this->configFile . 'isLog', false);
- return Config::get($this->configFile . '.stores.' . $this->name . '.isLog', $isLog);
- }
- /**
- * 获取模板id
- * @return array
- */
- public function getTemplateId()
- {
- return $this->templateIds;
- }
- /**
- * openid
- * @param string $openId
- * @return $this
- */
- public function to(string $openId)
- {
- $this->openId = $openId;
- return $this;
- }
- /**
- * 跳转路径
- * @param string $url
- * @return $this
- */
- public function url(string $url)
- {
- $this->toUrl = $url;
- return $this;
- }
- /**
- * 设置背景颜色
- * @param string $color
- * @return $this
- */
- public function color(?string $color)
- {
- $this->color = $color;
- return $this;
- }
- /**
- * 提取模板code
- * @param string $templateId
- * @return null
- */
- protected function getTemplateCode(string $templateId)
- {
- return $this->templateIds[$templateId] ?? null;
- }
- /**
- * 恢复默认值
- */
- protected function clear()
- {
- $this->openId = null;
- $this->toUrl = null;
- $this->color = null;
- }
- /**
- * 发送消息
- * @param string $templateId
- * @param array $data
- * @return mixed
- */
- abstract public function send(string $templateId, array $data = []);
- /**
- * 添加模板
- * @param string $shortId
- * @return mixed
- */
- abstract public function add(string $shortId);
- /**
- * 删除模板
- * @param string $templateId
- * @return mixed
- */
- abstract public function delete(string $templateId);
- /**
- * 获取所有模板
- * @return mixed
- */
- abstract public function list();
- }
|