trezrayan/raygan-sms-notification-channel

适用于 Laravel 5.3+ 的 Raygan SMS 通道

dev-main 2023-08-12 09:04 UTC

This package is not auto-updated.

Last update: 2024-09-22 12:35:43 UTC


README

此包使您能够通过 RayganSms API(点击访问)轻松发送通知,适用于 Laravel 5.3+。

RayganSms 通知通道,适用于 Laravel 5.3+

Latest Version on Packagist Software License StyleCI Scrutinizer Code Quality Build Status Code Intelligence Status Quality Score Total Downloads

此包提供了使用 RayganSms API 发送通知的功能。

内容

安装和配置

使用 composer 可以安装此服务

composer require trezrayan/raygan-sms-notification-channel
请注意,RayganSms API 将与此包一起自动安装到您的项目中。因此,如果您已安装并配置了 RayganSms API,安装过程将自动完成;否则,请根据该包的文档(在 Laravel 中配置)进行操作。

使用方法

使用 ()via 方法将此通道添加到通知,并按以下方式添加 toRayganSms 方法以发送通知:

use Illuminate\Notifications\Notification;
use NotificationChannels\RayganSms\RaygansmsChannel;
use NotificationChannels\RayganSms\TextMessage;
use NotificationChannels\RayganSms\AuthCodeMessage;

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

    public function toRayganSms($notifiable)
    {
        return (new TextMessage)
            ->content("your message to send ...");
    }
}
要向用户发送激活码,可以按照以下操作:
...
    public function toRayganSms($notifiable)
    {
        return (new AuthCodeMessage)
                    ->content('Welcome');
    }
    ...
如果要发送自定义激活码:
...
    public function toRayganSms($notifiable)
    {
        return (new AuthCodeMessage)
                    ->content('کد تایید شما : 325689')
                    ->autoGenerate(false);
    }

注意:为了确保将短信发送到用户的电话号码,通常使用用户模型(通常是 User 模型)来提取用户的电话号码。首先,将以下 trait 添加到您的模型中:
    use Notifiable;
然后,将以下方法添加到模型中:
    public function routeNotificationForRayganSms()
    {
        return $this->phone_number;
    }
请注意,在此模型中,包含用户电话号码的列名为 phone_number。如果不是这样,请将 this->phone_number$ 替换为包含电话号码的列名。

出品者

许可证

此包的许可证为 MIT。有关许可证的更多信息,请参阅 许可证文件