12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <?php
- // +----------------------------------------------------------------------
- // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
- // +----------------------------------------------------------------------
- // | Author: 萤火科技 <admin@yiovo.com>
- // +----------------------------------------------------------------------
- declare (strict_types = 1);
- namespace app\common\service\message;
- use app\common\model\store\Setting as SettingModel;
- use app\common\library\sms\Driver as SmsDriver;
- use app\common\service\BaseService;
- /**
- * 消息通知服务[基类]
- * Class Basics
- * @package app\common\service\message
- */
- abstract class Basics extends BaseService
- {
- // 参数列表
- protected $param = [];
- // 商城ID
- protected $storeId;
- // 错误信息
- protected $error = '';
- /**
- * 构造方法
- * Basics constructor.
- * @param int $storeId
- */
- public function __construct(int $storeId)
- {
- parent::__construct();
- $this->storeId = $storeId;
- }
- /**
- * 发送消息通知
- * @param array $param 参数
- * @return mixed
- */
- abstract public function send(array $param);
- /**
- * 发送短信提醒
- * @param string $sceneValue
- * @param array $templateParams
- * @param array $sceneConfig
- * @return bool
- * @throws \think\Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- protected function sendSms(string $sceneValue, array $templateParams, array $sceneConfig = [])
- {
- // 短信通知设置
- $smsConfig = SettingModel::getItem('sms', $this->storeId);
- // 短信服务
- $SmsDriver = new SmsDriver($smsConfig);
- // 发送短信
- if (!$SmsDriver->sendSms($sceneValue, $templateParams, $sceneConfig)) {
- $this->error = $SmsDriver->getError();
- return false;
- }
- return true;
- }
- /**
- * 字符串截取前20字符
- * [用于兼容thing数据类型]
- * @param string $content
- * @param int $length
- * @return bool|string
- */
- protected function getSubstr(string $content, int $length = 20)
- {
- return str_substr($content, $length);
- }
- /**
- * 获取错误信息
- * @return mixed
- */
- public function getError()
- {
- return $this->error;
- }
- }
|