msonowal/laravel-notification-channel-textlocal

v2.7.0 2024-05-11 09:02 UTC

README

此包允许通过使用 Laravel 通知通道 textlocal sms 通过 Textlocal API 发送 SMS。

支持 Laravel 5.5 到 10.x

Latest Stable Version License Total Downloads

此包使得使用 Laravel 5.3.+ 发送通知变得简单,通过 textlocal。

要使用 ^2.3.0 及以上版本,需要 PHP 8.0。

对于其他 PHP 版本,请使用 ^2.2.0 及以下版本。

内容

安装

在 textlocal 中创建一个账户,然后创建一个 API 密钥或散列(密码)。

composer require msonowal/laravel-notification-channel-textlocal

设置 textlocal 服务

默认配置 textlocal.php 更新到所需位置

重要提示:请指定密钥或散列中的一个 - 不要同时输入两者!

return [
	'username'  => env('TEXTLOCAL_USERNAME'),
	'password'  => env('TEXTLOCAL_PASSWORD'),
	'hash'      => env('TEXTLOCAL_HASH'),  //optional if api_key is set
	'api_key'   => env('TEXTLOCAL_API_KEY'), //optional if hash is set
	'sender'    => env('TEXTLOCAL_SENDER'),
	'request_urls' => [
		'IN' => 'https://api.textlocal.in/',
		'UK' => 'https://api.txtlocal.com/'
	],
	'country'   => env('TEXTLOCAL_COUNTRY', 'IN'),
    'extra' => [
        // extra config define keys as desired for use within the textlocal client config
        // if you want to use the custom client config for each notification or notifiable 
        // INotificationUsesTextlocalClientConfig
    ]public function getSenderId($notifiable)
### Configuring .env
TEXTLOCAL_USERNAME=Your email id or api key
TEXTLOCAL_HASH=get it from url '/docs/' under your API KEYS section
TEXTLOCAL_API_KEY get it from url '/docs/' under your API KEYS section
TEXTLOCAL_SENDER=Name of the Sender that will be displayed to the recipient (max 6 Characters).
TEXTLOCAL_COUNTRY=Your Two letter(ISO-3166-alpha-2) Country Code. It should be the Country of the TEXTLOCAL account. defaults to IN

### Publish Config
php artisan vendor:publish --tag=textlocal

Currently, only textlocal of two country is supported IN(India) and UK(United Kingdom). 

## Usage

Implement this method `routeNotificationForTextlocal()` in your notifiable class/model which will return array of mobile numbers. Please make sure the mobile number contains the dial code as well (e.g +91 for India). And lastly implement `toSms()` method in the notification class which will return the (string) sms or template that is defined in textlocal account that needs to be send.


## Usage

You can use the channel in your `via()` method inside the notification:

```php
use Illuminate\Notifications\Notification;
use NotificationChannels\Textlocal\TextlocalChannel;

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

    public function toSms($notifiable)
    {
        return 'Use 1234 as OTP for resetting your password.';
    }
}

在您的可通知模型中,确保包含一个 routeNotificationForTextlocal() 方法,该方法返回一个电话号码或多个电话号码的数组。

public function routeNotificationForTextlocal(): array
{
    return [$this->mobile_no];
}

匿名可通知:当手机号码未添加到可通知模型时,可以直接使用该手机号码发送短信。

Notification::route('Textlocal', $mobileNo')->notify(new VerifyMobileNotification($otp));

可用的消息方法

如果要根据通知设置特定的发送者,例如,使用一个用于促销通知,另一个用于交易,则可以在您的通知类中定义此方法,该方法将仅为此通知返回发送者 ID。

public function getSenderId($notifiable)
{
     return 'YOUR_SENDER_ID';
}

Unicode 支持:如果您想发送具有 Unicode 支持的通知内容,请在您的通知中定义此方法,该方法将根据返回的布尔值将 SMS 设置为 Textlocal API 中的 Unicode 模式。

public function getUnicodeMode()
{
     return true;
}

所有可用选项的列表

变更日志

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

测试

$ composer test

安全

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

发现任何错误或改进,请打开一个问题或发送 PR

贡献

有关详细信息,请参阅 CONTRIBUTING

致谢

许可

MIT 许可证 (MIT)。请参阅 许可文件 了解更多信息。

待办事项

需要将核心中的客户端转换为 Guzzle Http,添加更多国家,添加测试