pushmix / laravel-web-notification

Pushmix 通知驱动程序用于 Laravel

1.6 2019-09-13 15:27 UTC

README

Latest Version on Packagist Software License StyleCI Build Status Scrutinizer Code Quality Code Coverage Code Intelligence Status

关于

此软件包使得使用 Laravel 6 发送 Pushmix 通知 变得非常简单

内容

设置您的 Pushmix 账户

如果您还没有,请先在 pushmix.co.uk 上注册一个免费账户。

为您的网站创建新的订阅 并选择首选的 集成方法。通过显示一个同意提示来请求用户允许发送推送通知,以此建立您的订阅者群体。

安装

您可以通过 Composer 安装此软件包

$ composer require pushmix/laravel-web-notification:dev-master

如果您在 Laravel 5.4 或更低的版本中安装此软件包,您必须导入服务提供者

// config/app.php
'providers' => [
    ...
    Pushmix\WebNotification\PushmixServiceProvider::class,
],

配置

发布软件包配置和视图文件

php artisan vendor:publish --provider="Pushmix\WebNotification\PushmixServiceProvider"

将您的订阅 ID 添加到 .env 文件中

PUSHMIX_SUBSCRIPTION_ID=PASTE_YOUR_SUBSCRIPTION_ID_HERE

显示同意提示

要显示同意提示,您需要使用 Blade @include 指令将 JavaScript 块包含到模板中。

或者,您可以将 vendor.pushmix.optin 的内容复制并粘贴到模板中。

    <body>
        ...

            <div class="content">
                <div class="title m-b-md">
                    Laravel
                </div>
        </div>

        <!-- Including Opt In Prompt in Blade template-->

        @include('vendor.pushmix.optin')

    </body>
    ...

用法

现在您可以在通知中的 via() 方法内使用该频道

use Pushmix\WebNotification\PushmixChannel;
use Pushmix\WebNotification\PushmixMessage;
use Illuminate\Notifications\Notification;

class AbandonedCart extends Notification
{
    public function via($notifiable)
    {
        return [PushmixChannel::class];
    }

		public function toPushmix($to)
    {

      return PushmixMessage::create($to)
		  /* Required Parameters */
          ->title("You still have items in your Cart!")
          ->body("There's still time to complete your order. Return to your cart?")
          ->url("https://www.pushmix.co.uk")

		  /* Optional Parameters */
          ->button("Return to your cart", "https://www.pushmix.co.uk/docs") // button one
          ->priority("high")
          ->ttl(7200) // time to live
          ->icon("https://www.pushmix.co.uk/media/favicons/apple-touch-icon.png")
          ->badge("https://www.pushmix.co.uk/media/favicons/pm_badge_v2.png")
          ->image("https://www.pushmix.co.uk/media/photos/photo16.jpg");
    }
}

这些通知将被发送到在您网站上显示同意提示时订阅的受众。使用 Notification::route 方法,您可以指定您要针对哪个订阅者组。

use Notification;
use App\Notifications\AbandonedCart;
...
// Target All Subscribed Users
Notification::route('Pushmix', 'all')->notify(new AbandonedCart());

// Target Topic One Subscribers
Notification::route('Pushmix', 'one')->notify(new AbandonedCart());

// Target Topic Two Subscribers
Notification::route('Pushmix', 'two')->notify(new AbandonedCart());

所有可用方法

Pushmix 文档

  • title(''):接受一个字符串值作为标题,必需*

  • body(''):接受一个字符串值作为通知正文,必需*

  • url(''):接受一个 URL 作为通知点击事件,必需*

  • button('', ''):接受字符串值作为按钮标题和一个 URL 作为通知点击事件。最多可以附加 2 个按钮。

  • icon(''):接受一个 URL 作为图标。

  • priority(''):接受 highnormal 字符串。

  • ttl(''):接受一个整数,通知生存时间(以秒为单位),必须是 0 到 2,419,200 之间的数字

  • icon(''):接受一个 URL 作为图标。

  • badge(''):接受一个 URL 作为徽章。

  • image(''):接受一个 URL 作为大图像。

测试

进入软件包文件夹 vendor/pushmix/laravel-web-notification 并执行以下命令

$ composer test

问题

如果您遇到任何问题,请在此处报告它们 here

安全漏洞

如果您发现安全漏洞,请发送电子邮件至 support@pushmix.co.uk

贡献

有关详细信息,请参阅 CONTRIBUTING

鸣谢

许可

MIT 许可证 (MIT)。有关更多信息,请参阅 许可文件