guilhermedev98 / larasms
使用多种供应商(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
This package is not auto-updated.
Last update: 2024-10-01 11:47:27 UTC
README
Laravel SMS 是一个能够通过各种供应商(如 SMSgateway.me、Zenziva.id 等)的 SMS 网关发送和接收 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,您必须手动设置提供者,通过在您的 config/app.php
文件中添加 Yugo\SMSGateway\Providers\SmsServiceProvider::class
。
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。