| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- <?php
- /**
- * @author mybsdc <[email protected]>
- * @date 2021/10/20
- * @time 13:46
- */
- namespace Luolongfei\Libs;
- use Luolongfei\Libs\Connector\MessageServiceInterface;
- /**
- * Class Message
- *
- * @method bool send(string $content, string $subject = '', int $type = 1, array $data = [], ?string $recipient = null, ...$params) 送信
- */
- abstract class Message extends Base
- {
- /**
- * @var bool 防止同一个执行周期里每次送信都提示未启用
- */
- protected static $notEnabledTips = true;
- /**
- * @param $method
- * @param $params
- *
- * @return bool
- * @throws \Exception
- */
- public static function __callStatic($method, $params)
- {
- $result = false;
- foreach (config('message') as $conf) {
- if ($conf['enable'] !== 1) {
- if ($conf['not_enabled_tips'] && self::$notEnabledTips) { // 仅在存在配置的送信项未启用的情况下提醒
- system_log(sprintf(lang('100055'), $conf['name'], $conf['name']));
- }
- continue;
- }
- try {
- $serviceInstance = self::getInstance($conf['class'], 'IS_MESSAGE_SERVICE');
- if (!$serviceInstance instanceof MessageServiceInterface) {
- throw new \Exception(sprintf(lang('100056'), $conf['class']));
- }
- if ($serviceInstance->$method(...$params) && !$result) { // 任一方式送信成功即为成功
- $result = true;
- }
- } catch (\Throwable $e) {
- system_log(sprintf('%s送信失败:%s', $conf['name'], $e->getMessage()));
- }
- }
- self::$notEnabledTips = false;
- return $result;
- }
- }
|