适用于Laravel的Pushwoosh通知通道

v3.4.0 2024-03-15 21:50 UTC

This package is auto-updated.

Last update: 2024-09-15 22:58:52 UTC


README

Build status Downloads Latest release Code coverage License

本软件包简化了使用 Pushwoosh 发送通知的过程。

内容

需求

使用此软件包,您需要

  • Laravel 5.5或更高版本
  • PHP 7.1或更高版本
  • 有效的Pushwoosh订阅(并使用至少一个Pushwoosh SDK)

安装

要安装此软件包,请运行以下命令

composer require laravel-notification-channels/pushwoosh

接下来,将以下行添加到您的 config/services.php

'pushwoosh' => [
    'application' => env('PUSHWOOSH_APP_CODE'),
    'token' => env('PUSHWOOSH_TOKEN'),
],

现在,将 PUSHWOOSH_APP_CODE(可在 此处 找到)和 PUSHWOOSH_TOKEN(可在 此处 找到)添加到您的环境文件中。

使用

使用此软件包,您可以在Laravel中像使用任何其他通知通道一样使用Pushwoosh。有关Laravel通知系统的更多信息,请参阅 官方文档

请注意,在开始发送推送之前,您必须首先使用Pushwoosh的SDK之一将用户注册到您的应用程序中。

路由通知

为了使Pushwoosh知道需要向哪些设备发送,您需要在您的可通知模型中添加 routeNotificationForPushwoosh,例如

class Customer extends Model
{
    use Notifiable;
    
    public function routeNotificationForPushwoosh()
    {
        // In this example 'device_id' is a token previously
        // retrieved from Pushwoosh using one of their SDKs
        return (new PushwooshRecipient)->device($this->device_id);
    }
}

routeNotificationForPushwoosh 方法可能返回一个字符串、一个字符串数组或一个 PushwooshRecipient 实例。有关 PushwooshRecipient 类的更多信息,请参阅 可用方法 部分。

发送通知

发送Pushwoosh消息很简单,将 pushwoosh 添加到通知的 via 方法中并实现 toPushwoosh 方法,例如

class WishlistItemOnSale extends Notification
{
    public function via($notifiable)
    {
        return ['pushwoosh'];
    }
    
    public function toPushwoosh($notifiable)
    {
        return (new PushwooshMessage)
            ->content('Your wishlist item ' . $this->product->name . ' is on sale, get it now!')
            ->url(route('products.show', $this->product))
            ->deliverAt(Carbon::now()->addMinutes(10));
    }
}

toPushwoosh 方法可能返回一个字符串或 PushwooshMessage 类的实例。有关 PushwooshMessage 类的更多信息,请参阅 可用方法 部分。

然后您可以向单个用户发送推送

$customer->notify(new WishlistItemOnSale($product));

或向多个用户发送

Notification::send($customers, new WishlistItemOnSale($product));

未知设备

当您引用不存在的设备时,将触发一个 NotificationChannels\Pushwoosh\Events\UnknownDevices 事件。

您可以轻松地像这样挂钩到该事件

Event::listen(
    NotificationChannels\Pushwoosh\Events\UnknownDevices::class,
    function ($event) {
        // Handle the event
    }
);

可用方法

本节详细介绍了此软件包的公共API。

PushwooshMessage

以下是 PushwooshMessage 类上的可用方法列表。

PushwooshRecipient

以下是 PushwooshRecipient 类上的可用方法列表。

平台

以下是支持的平台列表,用于 PushwooshRecipient::platform 方法。

  • 亚马逊
  • 安卓
  • 黑莓
  • Chrome
  • Firefox
  • 苹果iOS
  • 苹果Mac
  • Safari
  • Windows
  • Windows Phone

变更日志

请参阅 变更日志 以获取有关最近更改的更多信息。

测试

composer test

贡献

如果您想为这个包做出贡献,请查看贡献指南

致谢

许可证

本产品遵循MIT许可协议(MIT)。有关更多信息,请参阅许可文件