natsumework/laravel-notification-mitake

1.2.0 2024-05-22 05:54 UTC

This package is auto-updated.

Last update: 2024-09-22 06:37:56 UTC


README

Latest Version on Packagist Software License Total Downloads

此包(非官方)使得使用 Laravel 5.5+、6.x 和 7.x 发送 Mitake 通知变得简单

这里是 Laravel 通知系统的最新文档

https://laravel.net.cn/docs/master/notifications

内容

安装

composer require natsumework/laravel-notification-mitake

设置 Mitake 服务

将您的 Mitake 账户、密码和 Api 端点 URL(可选)添加到您的 config/services.php

// config/services.php
...
'mitake' => [
    'username' => env('MITAKE_USERNAME'), // reqired
    'password' => env('MITAKE_PASSWORD'), // reqired
    'url' => env('MITAKE_URL'), // optional (has default value): e.g. 'https://{三竹網域名稱}/api/mtk/SmSend
],
...

用法

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

use NotificationChannels\Mitake\MitakeChannel;
use NotificationChannels\Mitake\MitakeMessage;
use Illuminate\Notifications\Notification;

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

    public function toMitake($notifiable)
    {
        return (new MitakeMessage())
            ->content("Your message...");
    }
}

您还可以设置 'dstaddr' 或 'vldtime' 或 'clientid' 选项(有关选项,请参阅 Mitake API 文档)

class SmsNotification extends Notification
{
    ...
    public function toMitake($notifiable)
    {
           return (new MitakeMessage())
                ->content("Your message...")
                ->to("0900000000") // dstaddr: phone number
                ->vldTime("900")  // Validity period: 900 second
                ->clientId("ce910656-7bd1-11ea-bc55-0242ac130003"); //Check duplicate sending
    }
    ...

电话号码

为了让您的通知知道您发送给哪个电话,您需要在 MitakeMessage 中设置电话号码

class SmsNotification extends Notification
{
    ...
    public function toMitake($notifiable)
    {
           return (new MitakeMessage())
                ->to("0900000000") // dstaddr: phone number 
                ...
    }
    ...

您还可以将 routeNotificationForMitake 方法添加到您的 Notifiable 模型中。

public function routeNotificationForMitake()
{
    return '0900000000';
}

或者您可以使用 on-demand-notifications

Notification::route('mitake', '0900000000')
           ->notify(new SmsNotification($message));

变更日志

有关最近更改的更多信息,请参阅 CHANGELOG

测试

$ composer test

安全

如果您发现任何与安全相关的问题,请通过电子邮件 natsumework0902@gmail.com 而不是使用问题跟踪器。

贡献

有关详细信息,请参阅 CONTRIBUTING

鸣谢

许可

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