Samuel-Bie/karix

允许您在 Laravel 通知中使用 karix 短信和 WhatsApp 作为自定义渠道

3.2.12 2022-02-13 16:14 UTC

This package is auto-updated.

Last update: 2024-09-13 21:44:51 UTC


README

此包使您能够通过 Karix.io 以 Laravel 6 或更高版本轻松发送短信。

安装

您可以通过 composer 安装此包

composer require samuelbie/karix

设置 Karix ID 和 Token

登录到 Karix.io 并获取您的 ID 和 Token,将其放在您的 .env 文件中,并将您的 Karix ID 和 Token 添加到您的 config/services.php

// config/karix.php
<?php
    return [
        'id'            => env('KARIX_ID'),
        'token'         => env('KARIX_TOKEN'),
        'sms_from'      => env('KARIX_FROM'),
        'whatsapp_from' => env('KARIX_WHATSAPP')
    ];

用法

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

use Samuelbie\Karix\Broadcasting\KarixMessage;
use Samuelbie\Karix\Broadcasting\KarixSMSChannel;
use Samuelbie\Karix\Broadcasting\KarixWhatsappChannel;


class YourNotification extends Notification
{
    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return [KarixSMSChannel::class, KarixWhatsappChannel::class];
    }


    public function toSmSKarix($notifiable)
    {
        return KarixMessage::create()
            ->content(['text' => 'Your message comes here']);
    }

    public function toWhatsappKarix($notifiable)
    {
        return KarixMessage::create()
            ->content([
                'text' => 'Your message comes here',
                'media' => 'url-to-media',
                'location' => [
                    'latitude' => 'the latitude here',
                    'longitude' => 'the longitude here'
                ]
            ]);
    }
}

为了让您的通知知道有一个名为 KarixSmsChannel 的新渠道,请将 routeNotificationForKarix 方法添加到您的 Notifiable 模型中(可能是您的 user.php 文件)。

此方法需要返回用户的电子邮件地址(如果它是私人板)以及要添加卡的 Trello 列表的列表 ID。

注意事项:确保您的表中有一个 'phone' 字段,以及您正在使用的国家代码,例如 +91xxxxxxxxxx。

public function routeNotificationForKarix()
{
    return $this->phone;
}

安全

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

贡献

有关详细信息,请参阅 CONTRIBUTING

鸣谢

许可证

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