agyson/zenziva-sms

Zenziva - 印度尼西亚在线短信网关

dev-master 2021-04-30 05:26 UTC

This package is auto-updated.

Last update: 2024-09-29 05:22:22 UTC


README

Zenziva SMS 客户端。阅读他们的 文档 了解更多信息。

安装

运行 composer

composer require agyson/zenziva-sms:dev-master

使用方法

独立使用

确保您已有 Zenziva 账户。

require 'vendor/autoload.php';

use Agyson\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 内部添加此行。

Agyson\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 Agyson\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 © Agy Nurwicaksono