nasution / zenziva-sms
1.5.0
2019-12-25 06:44 UTC
Requires
- rmccue/requests: ~1.7.0
Requires (Dev)
- phpunit/phpunit: ^5.6
README
Zenziva SMS 客户端。请阅读他们的 文档 获取更多信息。
安装
运行 composer
composer require nasution/zenziva-sms
使用方法
独立使用
请确保您已有 Zenziva 账户。
require 'vendor/autoload.php'; use Nasution\ZenzivaSms\Client as Sms; $sms = new Sms('userkey', 'passkey'); // Simple usage $sms->send('08123456789', 'Halo apa kabar?'); // Alternative way $sms->to('08123456789') ->text('Halo apa kabar?') ->send(); // SMS masking $sms->masking()->send('08123456789', 'Halo apa kabar?'); // For OTP $sms->masking()->otp()->send('08123456789', 'This is OTP code'); // With custom sub-domain (if you choose paid for "SMS Center" plan) $sms->subdomain('hello') ->to('08123456789') ->text('Halo apa kabar?') ->send(); // Change default URL $sms->url('https://reguler.zenziva.co.id/apps/smsapi.php') ->to('08123456789') ->text('Halo') ->send();
与 Laravel 通知一起使用
从 Laravel 5.3 开始,您可以使用 Laravel 通知功能。您需要注册服务提供者。打开 config/app.php,在 providers 中添加此行。
Nasution\ZenzivaSms\NotificationServiceProvider::class,
注意:如果您使用 Laravel 5.5 或更高版本,可以跳过手动注册服务提供者。
在您的 config/services.php 中插入以下内容:
'zenziva' => [ 'userkey' => 'your-userkey', 'passkey' => 'your-password', 'subdomain' => '', 'masking' => false, 'scheme' => 'https', ],
将此方法添加到您的 User 模型(或任何通知模型),
public function routeNotificationForZenzivaSms() { return $this->phone_number; // Depends on your users table field. }
在您的通知类中,通过方法添加以下内容。例如
use Nasution\ZenzivaSms\NotificationChannel as ZenzivaSms; // ... public function via($notifiable) { return [ZenzivaSms::class]; }
现在,我们已经准备好在 Laravel 5.3 中使用通知功能。
use App\User; use App\Notifications\PingNotification; Route::get('/', function () { // Send notification to all users $users = User::all(); \Notification::send($users, new PingNotification); // Or just to one user User::find(1)->notify(new PingNotification); });
许可证
MIT © Mulia Arifandi Nasution