nasution / zenziva-sms
Zenziva - Indonesia Online SMS Gateway
Installs: 17 475
Dependents: 0
Suggesters: 0
Security: 0
Stars: 32
Watchers: 5
Forks: 17
Open Issues: 0
Requires
- rmccue/requests: ~1.7.0
Requires (Dev)
- phpunit/phpunit: ^5.6
README
Zenziva SMS client. Read their docs for more information.
Installation
Run composer
composer require nasution/zenziva-sms
Usage
Standalone usage
Make sure you already have Zenziva account.
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();
Use with Laravel Notification
Starts from Laravel 5.3, you can use Laravel Notification feature. You need to register the service provider. Open config/app.php
, add this line inside providers
.
Nasution\ZenzivaSms\NotificationServiceProvider::class,
Note: If you use Laravel 5.5 or higher, you can skip register service provider manually.
Insert this inside your config/services.php
,
'zenziva' => [ 'userkey' => 'your-userkey', 'passkey' => 'your-password', 'subdomain' => '', 'masking' => false, 'scheme' => 'https', ],
Add this method to your User
model (or any notifiable model),
public function routeNotificationForZenzivaSms() { return $this->phone_number; // Depends on your users table field. }
On your Notification class, add this inside via method. Like so
use Nasution\ZenzivaSms\NotificationChannel as ZenzivaSms; // ... public function via($notifiable) { return [ZenzivaSms::class]; }
Now, we are ready to use notification feature in 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); });
License
MIT © Mulia Arifandi Nasution