liliom / unifonic-notification-channel

此包已被废弃且不再维护。作者建议使用 multicaret/unifonic-notification-channel 包。

Unifonic 通知通道用于 Laravel。

v3.0.0 2021-06-01 18:38 UTC

This package is auto-updated.

Last update: 2021-06-01 18:38:52 UTC


README

687474703a2f2f63646e2e6d756c746963617265742e636f6d2f7061636b616765732f6173736574732f696d672f756e69666f6e69632d6c6f676f2e706e67

Unifonic 通知通道用于 Laravel 8.x+

Unifonic 通道使得发送 Laravel 通知作为短信成为可能。

Total Downloads Latest Stable Version License

安装

您可以通过 composer 安装此包。

composer require multicaret/unifonic-notification-channel

服务提供者将自动加载。

设置 Unifonic 服务

查看 Laravel Unifonic 库 的配置。

使用方法

要使用此包,您需要在 Laravel 应用程序中创建一个通知类,例如以下示例中的 InvoicePaid。请确保查看 Laravel 文档 了解此过程。

通知示例

<?php
namespace App\Notifications;

use Illuminate\Notifications\Notification;
use Multicaret\Notifications\Messages\UnifonicMessage;

class InvoicePaid extends Notification
{
   private $message;

    /**
     * Create a new notification instance.
     *
     * @param $message
     */
    public function __construct($message)
    {
        $this->message = $message;
    }
    
    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return [
            'unifonic',
        ];
    }

    /**
     * Get the text message representation of the notification
     *
     * @param  mixed $notifiable
     *
     * @return UnifonicMessage
     */
    public function toUnifonic($notifiable)
    {
        return (new UnifonicMessage())
            ->content($this->message);
    }
}

或直接传递您想要的内容到构造函数中

public function toUnifonic($notifiable)
{
    return new UnifonicMessage('Laravel notifications are awesome!');
}

发送通知

在 Laravel 中发送通知有两种方法

方法 1

使用任何使用 Notifiable 特性的模型的 notify() 函数。为了实现这一点,您需要提供用作接收者号码的适当列,如下例所示,此函数位于 User 模型中(您可能希望将其写入不同的模型中,只需确保使用 use Notifiable 即可)

    /**
     * Route notifications for the Unifonic channel.
     *
     * @param  \Illuminate\Notifications\Notification $notification
     *
     * @return string
     */
    public function routeNotificationForUnifonic($notification)
    {
        return $this->phone; // where phone is the column within your, let's say, users table.
    }

方法 2

使用 Notification 类的静态函数 route()

Notification::route('unifonic', 'xxxxx')
                 ->notify(
                    new \App\Notifications\InvoicePaid('Laravel notifications are awesome!')
                 );
                 // where xxxxx is the phone number you want to sent to,
                 // i.e: 1xxxxxxx - NO NEED for _00_ or _+_ 

贡献

查看 CONTRIBUTING 指南。

变更日志

请参阅 CHANGELOG 了解最近更改的详细信息。