mikaelkael/ntfy-notifier

Symfony Ntfy Notifier 桥接器

安装次数: 140

依赖者: 0

建议者: 0

安全性: 0

星标: 1

关注者: 1

分支: 0

开放问题: 0

类型:symfony-notifier-bridge

v2.1.0 2024-08-31 15:08 UTC

This package is auto-updated.

Last update: 2024-08-31 19:35:49 UTC


README

Build Status License

为 Symfony Notifier 提供 Ntfy 集成。此组件应该在 Symfony 6.4 中通过此 PR #50131 引入。此包为 Symfony 5.4.x 到 6.3.x 提供相同的功能。

DSN 示例

# .env
NTFY_DSN=ntfy://[USER:PASSWORD]@default[:PORT]/TOPIC?[secureHttp=[on]]

where

  • URL 是你使用的 ntfy 服务器
    • 如果提供了 default,则默认为托管在 ntfy.sh 上的公共 ntfy 服务器。
  • TOPIC 是此 ntfy 服务器上的主题。
  • PORT 是可选的特定端口。
  • USERPASSWORD 是服务器支持访问控制时的用户名和密码

如果服务器不安全,可以通过设置 secureHttp=off 来禁用 https。

启用 texter

# config/packages/notifier.yaml
framework:
    notifier:
        texter_transports:
            nfty: '%env(NTFY_DSN)%'

发送推送消息

// src/Controller/TestController.php
namespace App\Controller;

use Symfony\Component\Notifier\Message\SmsMessage;
use Symfony\Component\Notifier\TexterInterface;
use Symfony\Component\Routing\Annotation\Route;

class TestController
{
    /**
     * @Route("/test")
     */
    public function test(TexterInterface $texter)
    {
        $pushMessage = new PushMessage(
            'Title',
            'Message content',
            new NtfyOptions(['tags' => ['warning'], 'priority' => 5])
        );
        $result = $texter->send($pushMessage);

        // ...
    }
}