yugo / smsgateway
使用各种供应商(SMSGateway.me、Zenziva等)的Laravel SMS网关
Requires
- php: >=7.0.0
- laravel/framework: >=5.4
- mashape/unirest-php: 3.0.4
Requires (Dev)
- phpunit/phpunit: 7.1.5
README
Laravel SMS是一个包,具有通过各种供应商(如SMSgateway.me、Zenziva.id等)的SMS网关发送和接收短信的能力。
目录
要求
- PHP 7.0或更高版本。
- PHP的cURL扩展。
- Laravel版本5.4或更高。
可用供应商
- SMSGateway.me (
smsgatewayme) - Zenziva.id (
zenziva)
安装说明
通过运行以下命令使用Composer安装包
composer require yugo/smsgateway -vvv
使用以下命令发布包资产
php artisan vendor:publish
从yugo/smsgateway中选择包,自动将配置文件复制到您的配置应用程序目录。
注意:如果您使用的是Laravel版本5.4,您必须手动设置提供者,通过将Yugo\SMSGateway\Providers\SmsServiceProvider::class添加到您的config/app.php文件中。
App\Providers\AppServiceProvider::class, App\Providers\AuthServiceProvider::class, // App\Providers\BroadcastServiceProvider::class, App\Providers\EventServiceProvider::class, App\Providers\RouteServiceProvider::class, Yugo\SMSGateway\Providers\SmsServiceProvider::class,
然后,使用以下命令发布包提供者。
php artisan vendor:publish --provider="Yugo\SMSGateway\Providers\SmsServiceProvider"
SMSGateway.me
要启用和使用SMSGateway.me供应商,您必须根据SMSGateway.me设置设置新配置。添加如下两个配置值。
SMS_VENDOR="smsgatewayme"
SMSGATEWAYME_DEVICE=
SMSGATEWAYME_TOKEN=
Zenziva.id
登录到您的Zenziva.id仪表板帐户以获取userkey和passkey值。使用以下配置将这些值添加到.env文件中。
SMS_VENDOR="zenziva"
ZENZIVA_USERKEY=userkey
ZENZIVA_PASSKEY=passkey
使用方法
使用Laravel SMS发送新消息非常简单。您只需从包中导入实时外观并在其中调用可用的方法。
use Facades\Yugo\SMSGateway\Interfaces\SMS;
现在,您可以在PHP文件中使用SMS类。每个供应商都有send(array $destinations, string $message)方法。
快速示例
SMS::send(['62891111111'], 'Hello, how are you?');
附加方法
一些供应商有附加方法。例如,您可以使用Zenziva检查余额,使用SMSGateway.me检查设备。
SMSGateway.me
// get registered device information SMS::device(?int $id); // $id is nullable // get detailed information from message SMS::info(int $id); // cancel queued message SMS::cancel(array $id);
默认情况下,SMSgateway.me包将使用.env文件中的API配置(例如设备和令牌)。但是,您可以通过应用程序程序化地设置设备ID和令牌。例如
SMS::setDevice(12345) // make sure it's integer value ->setToken('secret-token') ->send(['08111111111'], 'Message with custom device and token.');
Zenziva.id
// get credit balance SMS::credit();
如果您想手动设置userkey和/或passkey,您可以使用setUser(string $user)和setPassword(string $password)方法。例如
SMS::setUser('you') ->setPassword('secret') ->send(['08111111111'], 'Message with custom user and password.');
许可证
MIT。