Files
ulthon_admin/extend/base/common/notice/channel/SmsChannel.php
2026-10-12 13:40:40 +00:00

47 lines
1.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace base\common\notice\channel;
use base\common\notice\NoticeChannelInterface;
use think\facade\Log;
/**
* 短信渠道驱动(骨架).
*
* 骨架形态:读开关、记日志、恒成功,不执行真实外呼。
* 正常业务流不会产生 sms 投递行(scenes() 注册渠道不含 sms),
* 行进队列的场景是 app 层注册新场景引入 sms 渠道之后。
*/
class SmsChannel implements NoticeChannelInterface
{
public static function name(): string
{
return 'sms';
}
public function send(array $target, array $notice): bool
{
/*
* TODO 下游对接指引(真实短信发送):
* - 使用既有 guzzlehttp/guzzle 客户端调用短信服务商 API(阿里云/腾讯云 SMS 等);
* - 读取 sysconfig('notify','notify_sms_sign'/'notify_sms_appid'/'notify_sms_secret')
* 组装签名与模板参数,POST 服务商接口;
* - 服务商接口非成功码(HTTP 非 2xx 或业务失败码)时抛出 RuntimeException,
* 异常消息携带服务商返回的失败信息,交由 timer 消费者退避重试;
* - target_addr 为手机号,notice 为通知主体(title/content)。
*/
// 骨架驱动模拟发送:开关状态仅记入日志(关闭也恒成功),不拦截投递、不真实外呼
$enabled = (int) sysconfig('notify', 'notify_sms_enable');
Log::info('notice sms channel skeleton simulated send', [
'channel' => self::name(),
'enabled' => $enabled,
'notice_id' => $notice['id'] ?? 0,
'target_addr' => $target['target_addr'] ?? '',
'title' => $notice['title'] ?? '',
]);
return true;
}
}