Files
ulthon_admin/extend/base/common/notice/channel/WechatChannel.php

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;
/**
* 公众号渠道驱动(骨架).
*
* 骨架形态:读开关、记日志、恒成功,不执行真实外呼。
* 正常业务流不会产生 wechat 投递行(scenes() 注册渠道不含 wechat),
* 行进队列的场景是 app 层注册新场景引入 wechat 渠道之后。
*/
class WechatChannel implements NoticeChannelInterface
{
public static function name(): string
{
return 'wechat';
}
public function send(array $target, array $notice): bool
{
/*
* TODO 下游对接指引(公众号模板消息):
* - 实现 access_token 管理:用 sysconfig('notify','notify_wechat_appid'/'notify_wechat_secret')
* 调用微信 token 接口获取凭证,缓存至过期前(token 有效期 7200s,需集中缓存防刷);
* - 用 guzzlehttp/guzzle 调用模板消息接口(POST /cgi-bin/message/template/send),
* target_addr 为接收用户 openid,notice(title/content)映射模板字段;
* - 微信返回 errcode 非 0 时抛出 RuntimeException(携带 errcode/errmsg),
* 交由 timer 消费者退避重试。
*/
// 骨架驱动模拟发送:开关状态仅记入日志(关闭也恒成功),不拦截投递、不真实外呼
$enabled = (int) sysconfig('notify', 'notify_wechat_enable');
Log::info('notice wechat channel skeleton simulated send', [
'channel' => self::name(),
'enabled' => $enabled,
'notice_id' => $notice['id'] ?? 0,
'target_addr' => $target['target_addr'] ?? '',
'title' => $notice['title'] ?? '',
]);
return true;
}
}