本篇使用包:
wise-notification、wise-webhook。分界线很清楚:主动告诉用户用前者,和外部系统互相推送用后者。两者默认安装,职责不重叠。
各管什么
wise-notification:8 个通道(邮件、短信、钉钉、企微、飞书、通用 Webhook、公众号模板、站内信),模板编译、中间件管道、偏好与节流、关键消息豁免、指数退避重试 + 死信、断路器、落库脱敏。
\wise\notification\facade\Notification::channel('email')
->send($user, new Message(...));可链式加 ->sync()(同步发)、->template()、->priority('urgent')。
wise-webhook:零第三方依赖、curl 实现。发送侧有 HMAC-SHA256 签名、四种退避、per-host 熔断、SSRF 拦截;接收侧支持多端点签名验证(纯 hex / Stripe / GitHub)、hash_equals 防时序攻击、时间戳防重放,配合 VerifyWebhookSignature 中间件与队列处理。
在框架里怎么接
- notification 的
clean-history已登记进config/wise-crontab.php,默认每天 03:30 跑——这是与定时任务的显式衔接,不用自己加; - 关键安全配置:
channels.webhook.allow_message_endpoint=false(SSRF 开关,默认关)、retry.max_attempts=5、audit.mask_fields; - 命令:
wise:notification:send、retry-failed、health、clean-history; - Webhook 底座复用
wise-support的BackoffStrategy、CircuitBreaker、WiseException。
什么时候该去读完整教程
要写通道模板、调熔断阈值、拼签名串,或者要给接收端点挂中间件时。见 wise-notification 教程与 wise-webhook 教程。
容易搞错的
- 在 HTTP 请求里同步发通知:会拖慢响应,默认走队列,别传
->sync()图省事。 - 把
allow_message_endpoint打开:等于允许消息内容指定任意 URL,SSRF 风险回到你身上。 - 以为 webhook 就是"发个 POST":签名、重放、熔断都在包里,自己写一套等于绕过全部防护。
自查:php think wise:notification:health 输出各通道可用性;config/wise-notification.php 里 channels.webhook.allow_message_endpoint 应为 false。