rezahmady / smsir
1.1.0
2022-03-15 21:15 UTC
Requires
- php: ~7.3|| ^8
- ext-json: *
- guzzlehttp/guzzle: ^7.2
- illuminate/notifications: ~6.0 || ~7.0 || ~8.0 || ~9.0
- illuminate/support: ~6.0 || ~7.0 || ~8.0 || ~9.0
Requires (Dev)
- mockery/mockery: ^1.4.4
- phpunit/phpunit: ^9.5.10
This package is auto-updated.
Last update: 2024-09-16 03:02:33 UTC
README
此包简化了使用Smsir在Laravel 5.5+、6.x、7.x、8.x和9.x发送通知的过程。
内容
安装
composer require rezahmady/smsir
配置Smsir服务
首先,在.env文件中添加以下环境变量
SMSIR_API_KEY="xxxx"
SMSIR_SECRET_KEY="xxxx"
SMSIR_LINE_NUMBER="xxxx"
然后,将此方法添加到您的User模型中
public function routeNotificationForSmsir()
{
return $this->mobile;
}
使用方法
示例通知类
namespace App\Notifications\Sms;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Rezahmady\Smsir\SmsirChannel;
use Rezahmady\Smsir\SmsirMessage;
class VerificationCode extends Notification
{
use Queueable;
public $parameter;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct($parameter)
{
$this->parameter = $parameter;
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return [SmsirChannel::class];
}
public function toSmsir($notifiable)
{
return (new SmsirMessage())
->setMethod('ultraFastSend')
->setTemplateId('47119')
->setParameters([
'VerificationCode' => $this->parameter
]);
}
}
示例触发此通知
return auth()->user()->notify(new VerificationCode('1234'));
可用的消息方法
所有可用选项的列表
setMethod
是否需要
->setMethod('METHOD_NAME')
smsir有发送短信的两种方法
1. ultraFastSend 需要的属性是parameters
(数组)和templateId
(字符串),通过以下链式方法设置它们:
->setTemplateId('THEMPLATE_ID')
->setParameters([...]);
2. sendVerificationCode
需要的属性是code
(字符串),通过以下链式方法设置它:
->setCode('YOUR_CODE')
变更日志
有关最近更改的更多信息,请参阅CHANGELOG。
测试
$ composer test
安全
如果您发现任何安全相关的问题,请通过ahmadireza15@gmail.com发送电子邮件,而不是使用问题跟踪器。
贡献
有关详细信息,请参阅CONTRIBUTING。
鸣谢
许可证
MIT许可证(MIT)。有关更多信息,请参阅许可证文件。
注意:此包已用于开发amirbagh75/smsir-php。感谢Amirhossein Baghaie。