feat(notice): PHPMailer 邮箱驱动与短信公众号骨架

This commit is contained in:
augushong
2026-10-12 12:09:00 +00:00
parent e95e5942ea
commit 02f77f4eca
6 changed files with 382 additions and 5 deletions

View File

@@ -0,0 +1,46 @@
<?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;
}
}