jareddmz / laravel-infobip-sms
简单配置和使用通过Infobip发送短信。
dev-master
2019-07-23 15:40 UTC
Requires
- php: >=7
This package is auto-updated.
Last update: 2024-09-24 03:44:08 UTC
README
简单配置和使用通过Infobip发送短信。
在composer.json中请求此包,并更新composor或直接复制以下内容
composer require jareddmz/laravel-infobip-sms:dev-master
安装
更新编辑器后,将服务提供者添加到config/app.php中的提供商数组中
JaredDmz\LaravelInfobipSMS\SMSIProvider::class,
可选:使用外观以获得更短的代码。将以下内容添加到你的外观中
'SMSI' => JaredDmz\LaravelInfobipSMS\SMSIFacade::class,
使用
1. 在.env文件末尾创建2个新的全局变量:在这里添加你的Infobip门户会话数据以通过API登录
SMS_USERNAME=''
SMS_PASSWORD=''
2. 执行以下3个命令以清除应用程序的缓存并允许加载全局变量:
php artisan config:clear
php artisan cache:clear
composer dump-autoload
3. 在你的PHP文件(控制器)中调用外观,并传递2个String类型的参数,电话号码(12位数字)和消息:
use SMSI;
...
SMSI::enviar('520000000000','Hola, gusto en saludarte.');
响应
为了方便使用此包装器并确保短信已发送,调用将返回以下形式的数组响应,如果为正面
[
estatus => 'si',
mensaje => 'El SMS fue enviado correctamente.'
];
或者,如果是负面的
[
estatus => 'no',
mensaje => 'Erorr, al tratar de hacer...'
];
如有必要,使用try,catch以更合适地处理错误。
许可
此存储库受MIT许可证的约束。