kagatan/sms-ukraine

从SmsUkraine发送短信

dev-master 2018-07-04 19:18 UTC

This package is auto-updated.

Last update: 2024-09-15 05:18:26 UTC


README

Laravel

“SMS Ukraine”服务的通知频道

使用本包,您可以将短信通知轻松集成到Laravel应用程序中,用于发送的短信服务为“SMS Ukraine”。

安装

在终端中执行以下命令以安装此包

$ composer require kagatan/sms-ukraine

需要已安装的composer。要安装它,请访问此链接

如果您使用的是Laravel 5.5或更高版本,则该包的服务提供程序将自动注册。否则,您需要自行在文件./config/app.phpproviders部分中注册服务提供程序

'providers' => [
    // ...
   Kagatan\SmsUkraine\SmsUkraineServiceProvider::class,
]

添加外观

 'aliases' => [
    ...
    'SmsUkraine' => Kagatan\SmsUkraine\Facades\SmsUkraine::class
]

将以下内容添加到文件config/services.php

// config/services.php
...
'sms-ukraine' => [
        'key'      => function_exists('env') ? env('SMSUKRAINE_KEY', '') : '',
        'login'    => function_exists('env') ? env('SMSUKRAINE_LOGIN', '') : '',
        'password' => function_exists('env') ? env('SMSUKRAINE_PASSWORD', '') : '',
        'from'     => function_exists('env') ? env('SMSUKRAINE_FROM', '') : '',
    ],
...

发布提供程序

php artisan vendor:publish --provider="Kagatan\SmsUkraine\SmsUkraineServiceProvider"

配置

安装后,您需要修改文件./.env并添加以下键值

SMSUKRAINE_KEY=xxxxxxxxxxxxxxxxxxxxxx

SMSUKRAINE_FROM=SENDER-NAME

如果想要使用用户名/密码组合,请添加以下键值

SMSUKRAINE_LOGIN=xxxxx

SMSUKRAINE_PASSWORD=xxxxx

SMSUKRAINE_FROM=SENDER-NAME

升级

composer update kagatan/sms-ukraine

使用

使用Laravel应用程序中的通知功能发送基本短信通知的示例

SmsUkraineMessage对象可用的可用方法

通知类示例

<?php

use Illuminate\Notifications\Notification;
use Kagatan\SmsUkraine\SmsUkraineChannel;
use Kagatan\SmsUkraine\SmsUkraineMessage;

/**
 * Notification object.
 */
class InvoicePaid extends Notification
{
    /**
     * Get the notification channels.
     *
     * @param mixed $notifiable
     *
     * @return array|string
     */
    public function via($notifiable)
    {
        return [SmsUkraineChannel::class];
    }

    /**
     * Get the SMS Ukraine Message representation of the notification.
     *
     * @param mixed $notifiable
     *
     * @return SmsUkraineMessage
     */
    public function toSmsUkraine($notifiable)
    {
        return SmsUkraineMessage::create()
            ->content('Some SMS notification message');
    }
}

在您可通知的模型中,请务必添加routeNotificationForSmsUkraine()方法,该方法返回电话号码或电话号码数组。

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;

class User extends Model
{
    use Notifiable;

    /**
     * Route notifications for the SmsUkraine channel.
     *
     * @param $notifiable
     * @return string
     */
    public function routeNotificationForSmsUkraine($notifiable)
    {
        return $this->phone;
    }
}

使用Notifiable Trait的示例

$user->notify(new InvoicePaid());

使用Notification Facade的示例

Notification::send($users, new InvoicePaid());

使用外观发送短信的示例(不使用Notification)

<?php

use Kagatan\SmsUkraine\Facades\SmsUkraine;
use Kagatan\SmsUkraine\SmsUkraineMessage;

public function test(){

        $message = SmsUkraineMessage::create()
            ->content("Example sending SMS.")
            ->to("380987654210")
            ->from("WiFi-POINT")
            ->toArray();

        $id = SmsUkraine::send($message);
        
        echo $id;
}

许可

本包的代码在MIT许可证下分发。