utcl/utelsms

此包使您能够通过 Laravel 使用 UTel 发送通知变得简单

v1.0.2 2024-05-14 11:22 UTC

This package is auto-updated.

Last update: 2024-09-14 12:24:12 UTC


README

内容

安装

您可以通过 composer 安装此包

composer require utel/utelsms

服务提供者将自动加载。

设置 UTelSms 服务

请注意,如果您没有有效的 sender_ID,请从 .env 文件中删除 "AT_FROM",或者将其留空 ""

UTCL_BASE_DOMAIN=""
UTCL_TOKEN=""
UTCL_FROM=""

要加载它们,请将以下内容添加到您的 config/services.php 文件中。这将从 .env 文件中加载 AfricasTalking 数据。

'utelsms' => [
    'baseDomain'      => env('UTCL_BASE_DOMAIN'),
    'token'           => env('UTCL_KEY'),
    'from'          => env('UTCL_FROM'),
]

在您的可通知模型上添加 routeNotificationForUTelSms 方法。如果不添加此方法,将自动使用 phone_number 字段。

<?php

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Notifiable;

    /**
     * Route notifications for the channel.
     *
     * @param  \Illuminate\Notifications\Notification  $notification
     * @return string
     */
    public function routeNotificationForUTelSms($notification)
    {
        return $this->phone_number;
    }
}

使用

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

<?php

use NotificationChannels\UTelSms\UTelSmsChannel;
use NotificationChannels\UTelSms\UTelSmsMessage;

class NewsWasPublished extends Notification
{

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

    public function toUTelSms($notifiable)
    {
		return (new UTelSmsMessage())
                    ->content('Your SMS message content');

    }
}

您还可以修改通知(短信)发送者,这将覆盖 .env 中的 AT_FROM=。**请仅在您有有效的 sender_ID 时执行此操作**

        return (new UTelSmsMessage())
                    ->content("Your SMS message content")
                    ->from("set any sender id/name here");

您还可以修改通知(短信)的接收者(收件人)

        return (new UTelSmsMessage())
                    ->content("Your SMS message content")
                    ->to("put the recipient phone number here"); //eg ->to(716094525)

了解接收者电话号码的顺序很重要,该顺序将用于发送通知(短信)

  1. 如果您在可通知类(本例中的 User.php)上定义了 routeNotificationForUTelSms() 方法并返回了有效的电话号码,则将使用该号码。

  2. 如果您在可通知类(本例中的 User.php)上未定义 routeNotificationForUTelSms() 方法,则将使用 User 的 phone_number 属性($user->phone_number)

  3. 最后,如果使用 ->to(716094525) 设置了接收者电话号码,这将覆盖 1 或 2 中提供的电话号码。

        return (new UTelSmsMessage())
                    ->content("Your SMS message content")
                    ->to("put the recipient phone number here"); //eg ->to(716094525)

测试

$ composer test

安全

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

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