ibnuhalimm/laravel-thai-bulk-sms

Laravel的泰国批量短信包装器

v1.2.1 2022-04-23 03:38 UTC

This package is auto-updated.

Last update: 2024-09-23 08:38:05 UTC


README

Latest Version on Packagist Total Downloads

Laravel的泰国批量短信包装器。

内容

要求

  1. 注册泰国批量短信账户
  2. 在设置部分创建 Api 密钥和 Secret 密钥

安装

您可以通过 composer 安装此包

composer require ibnuhalimm/laravel-thai-bulk-sms

可选,您可以使用此命令发布此包的配置文件

php artisan vendor:publish --provider="Ibnuhalimm\LaravelThaiBulkSms\ThaiBulkSmsServiceProvider"

设置

将您的 API 密钥Secret 密钥THAI_BULK_SENDER 放入 .env 文件

THAI_BULK_API_KEY=
THAI_BULK_SECRET_KEY=
THAI_BULK_SENDER=

使用

  1. 您可以直接使用 ThaiBulkSms Facade(别名或类本身)

    use Ibnuhalimm\LaravelThaiBulkSms\Facades\ThaiBulkSms;
    
    // Send the sms to single recipient
    $phoneNumber = '+6612345678';
    $message = 'Hi, our message here.';
    ThaiBulkSms::send($phoneNumber, $message);
    
    // Send the sms to multiple phone number
    $phoneNumber = [
        '+6612345678',
        '+6690111213',
    ];
    $message = 'Hi, our message here.';
    ThaiBulkSms::send($phoneNumber, $message);

    此方法的响应格式将与泰国批量短信API的响应类似。

  2. 通知
    让我们看看作为通知通道的实现。

    use Ibnuhalimm\LaravelThaiBulkSms\ThaiBulkSmsChannel;
    use Ibnuhalimm\LaravelThaiBulkSms\ThaiBulkSmsMessage;
    use Illuminate\Notifications\Notification;
    
    class VerifyMobileNumber extends Notification
    {
        public function via()
        {
            return [ThaiBulkSmsChannel::class];
        }
    
        public function toThaiBulkSms($notifiable)
        {
            return (new ThaiBulkSmsMessage())
                ->message("Your OTP to complete the registration is {$this->otp}");
        }
    }

    为了让通知知道您正在发送到哪个手机号码,默认情况下,通道将查找可通知模型的 mobile_number 属性。如果您想覆盖此行为,请将 routeNotificationForThaiBulkSms 方法添加到您的可通知模型中。

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

    或者使用 to 方法直接将接收者手机号码设置为可通知实例

    ...
    public function toThaiBulkSms($notifiable)
    {
        return (new ThaiBulkSmsMessage())
            ->message("Your OTP to complete the registration is {$notifiable->otp}")
            ->to($notifiable->phone); // add this
    }
    ...

测试

composer test

变更日志

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

贡献

有关详细信息,请参阅CONTRIBUTING

安全

如果您发现任何安全相关的问题,请通过电子邮件ibnuhalim@pm.me联系,而不是使用问题跟踪器。

鸣谢

许可证

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