robust-tools / resala
Laravel SMS网关集成包
2.3.4
2023-03-16 10:05 UTC
Requires
- php: ^8.1|8.2
- ext-dom: *
- ext-json: *
- ext-simplexml: *
- guzzlehttp/guzzle: ^7.5
- illuminate/support: ^9.0|^10
Requires (Dev)
- orchestra/testbench: ^8.0.8
- phpunit/phpunit: ^10.0
README
Resala 是一个PHP & Laravel包(旨在为您的Laravel应用程序或原生PHP应用程序添加对MENA地区本地运营商(如Vodafone、Infopib、Conneckio、VectoryLink)发送短信的支持)。
Resala 不仅限于在Laravel中使用,您还可以将其集成到任何PHP代码中
支持的提供商
- Vodafone SMS网关
- Connekio SMS网关
- InfoPib SMS网关
- Vectory Link SMS网关
安装
您可以通过composer安装此包
composer require robust-tools/resala
Laravel使用方法。
配置
使用以下命令发布配置文件
php artisan vendor:publish --provider="RobustTools\Resala\SMSServiceProvider" --tag="config"
这是已发布的配置文件内容
return [ /* * You can specify a default service provider driver here. * If it is not set we'll use vodafone as the default driver. */ 'default' => env('SMS_DRIVER', 'vodafone'), /* |-------------------------------------------------------------------------- | List of sms drivers |-------------------------------------------------------------------------- | | This is a list of possible sms gateways drivers | */ 'drivers' => [ 'vodafone' => [ 'end_point' => env('VODAFONE_END_POINT'), 'account_id' => env('VODAFONE_ACCOUNT_ID'), 'password' => env('VODAFONE_PASSWORD'), 'secure_hash' => env('VODAFONE_SECURE_HASH'), 'sender_name' => env('VODAFONE_SENDER_NAME', 'Vodafone') ], 'connekio' => [ 'single_sms_endpoint' => env('SINGLE_SMS_ENDPOINT'), 'batch_sms_endpoint' => env('BATCH_SMS_ENDPOINT'), 'username' => env('CONNEKIO_USERNAME'), 'password' => env('CONNEKIO_PASSWORD'), 'account_id' => env('CONNEKIO_ACCOUNT_ID'), 'sender_name' => env('CONNEKIO_SENDER_NAME') ], 'infobip' => [ 'end_point' => env('INFOBIP_END_POINT'), 'username' => env('INFOBIP_USERNAME'), 'password' => env('INFOBIP_PASSWORD'), 'sender_name' => env('INFOBIP_SENDER_NAME', 'Infobip') ], 'vectory_link' => [ 'end_point' => env('VECTORY_LINK_END_POINT'), 'username' => env('VECTORY_LINK_USERNAME'), 'password' => env('VECTORY_LINK_PASSWORD'), 'sender_name' => env('VECTORY_LINK_SENDER_NAME', 'Vectory Link'), 'lang' => env('VECTORY_LINK_LANG', 'E') ], ], /* |-------------------------------------------------------------------------- | Class Maps |-------------------------------------------------------------------------- | | | This is a list of Classes that maps to the Drivers above. */ 'map' => [ 'vodafone' => VodafoneDriver::class, 'connekio' => ConnekioDriver::class, 'infobip' => InfobipDriver::class, 'vectory_link' => VectoryLink::class ], ];
可用命令
这将为您的.env文件添加vodafone环境变量。
php artisan resala:make vodafone
这将为您的.env文件添加connekio环境变量。
php artisan resala:make connekio
这将为您的.env文件添加infobip环境变量。
php artisan resala:make infobip
这将为您的.env文件添加vectory_link环境变量。
php artisan resala:make vectory_link
使用方法
SMS::to('010xxxxxxxx') ->message("Hello World") ->send(); SMS::to(['010xxxxxxxx', '011xxxxxxxx']) ->message("Hello World") ->send();
您可以通过以下方式检查来自您的短信提供商的返回响应
$response = SMS::to(['010xxxxxxxx', '011xxxxxxxx']) ->message("Hello World") ->send(); $response->success(); // returns bool $response->body(); // returns string
您可以使用via方法可选地更改驱动程序
SMS::via('vodafone') ->to('010xxxxxxxx') ->message("Hello World") ->send();
在Laravel之外
您需要在项目目录中添加一个名为resala.php的配置文件,该文件的内容必须与包配置文件的模式相匹配,您可以在这里找到它。
只需将env(values)替换为您的驱动程序配置值。
use RobustTools\Resala\SMS; $configFile = __DIR__ . "/config/resala.php"; (new SMS($driver, $configFile))->to(['010995162378', '012345522']) ->message("Hello World") ->send();
如果没有传递配置文件,则会抛出InvalidArgumentException异常。
贡献
有关详细信息,请参阅CONTRIBUTING。
安全性
如果您发现任何与安全相关的问题,请通过电子邮件mohabdelaziz95@gmail.com联系,而不是使用问题跟踪器。
鸣谢
许可协议
MIT许可(MIT)。有关更多信息,请参阅许可文件。