alif / alif-sms-notification
v2.1.0
2023-12-06 06:25 UTC
Requires
- php: ^8.1
- guzzlehttp/guzzle: ^7.4.1
This package is not auto-updated.
Last update: 2024-09-23 15:56:22 UTC
README
先决条件
要使用此包,您需要
- composer 2.2 及以上版本
- php 8.1 及以上版本
- guzzlehttp/guzzle
- laravel 9 及以上版本
安装
通过运行以下命令安装包
composer require alif/alif-sms-notification
它将在名为 config/sms-notification.php
的文件中创建和粘贴以下代码
<?php return [ 'host' => env('SMS_NOTIFICATION_HOST'), 'method' => 'POST', 'headers' => [ 'X-Api-Key' => env('SMS_NOTIFICATION_API_KEY'), 'Content-type' => 'application/json', 'charset' => 'utf-8' ], 'routes' => [ 'send_sms' => '/api/v1/Sms' ], ];
用法
- 简单发送
$smsSender = new SmsNotificationSender(); //OR $smsSender = SmsNotificationSender::make(); $smsSender->from('John Doe') ->to('123456789') ->send('Message text'); //or SmsNotificationSender::make() ->from('John Doe') ->to('123456789') ->send('Message text');
- 异步发送
$smsSender = new SmsNotificationSender(); //OR $smsSender = SmsNotificationSender::make(); $smsSender->from('John Doe') ->to('123456789') ->sendAsinc('Message text');
- 处理异常
$smsSender = SmsNotificationSender::make(); $smsSender->from('John Doe') ->to('123456789') ->onFail(function(Exception $e) { // do something ... })->onSuccess(function(ResponseInterface $response) { // do smth ... })->send('Message text');
- 使用头部信息
$smsSender = SmsNotificationSender::make(); $smsSender->from('John Doe') ->to('123456789') ->headers($headers) ->onFail(function(Exception $e) { //... })->onSuccess(function(ResponseInterface $response) { //... })->send('Message text');
$smsSender = SmsNotificationSender::make(); $smsSender->from('John Doe') ->to('123456789') ->priority($priority) ->onFail(function(Exception $e) { //... })->onSuccess(function(ResponseInterface $response) { //... })->send('Message text');
- 设置 expiresIn
$smsSender->from('John Doe') ->to('123456789') ->expiresIn($expiresIn) ->onFail(function(Exception $e) { //... })->onSuccess(function(ResponseInterface $response) { //... })->send('Message text');
- 设置 countryCode
$smsSender->from('John Doe') ->to('123456789') ->countryCode($countryCode) ->onFail(function(Exception $e) { //... })->onSuccess(function(ResponseInterface $response) { //... })->send('Message text');