nikajorjika/laravel-sms-office

作为格鲁吉亚短信办公室网络服务的通道提供程序的软件包

1.0.3 2022-03-30 11:46 UTC

This package is auto-updated.

Last update: 2024-09-09 18:48:59 UTC


README

nikajorjika/laravel-sms-officesmsoffice.ge 的支持软件包。

安装

使用 composer PHP 软件包管理器安装 nikajorjika/laravel-sms-office

composer require nikajorjika/laravel-sms-office

.env 文件中添加变量

# for testing purposes you can also use SMS_OFFICE_DRIVE=log
SMS_OFFICE_DRIVER=sms-office
SMS_OFFICE_KEY=[api-key-provided-by-smsoffice.ge]
SMS_OFFICE_FROM=[sender-name]
SMS_OFFICE_NOSMS=[no-sms-code-provided-by-smsoffice.ge]

为了进一步定制和配置软件包,我们首先需要发布我们的配置文件

php artisan vendor:publish --provider="Nikajorjika\SmsOffice\SmsOfficeServiceProvider" --tag="config"

这将发布我们 config 文件夹内的 smsoffice.php 文件

<?php

return [
    /**
     * Endpoint for sms office url
     */
    'api_url' => env('SMS_OFFICE_URL', 'http://smsoffice.ge/api/v2/send/'),

    /**
     * Private Key provided by sms office service
     */
    'key' => env('SMS_OFFICE_KEY', null),

    /**
     * Driver that serves as a channel driver for laravel
     */
    'driver' => env('SMS_OFFICE_DRIVER', 'sms-office'),

    /**
     * This key defines sender name
     * for the sms to be delivered from
     */
    'from' => env('SMS_OFFICE_FROM', NULL),

    /**
     * List of drivers that sms office package supports
     */
    'supported_drivers' => ['sms-office', 'log'],

    /**
     * Define no sms code for the user to unsubscribe
     */
    'no_sms_code' => env('SMS_OFFICE_NOSMS', NULL),

];

使用方法

使用此软件包有两种方式。

作为外观

<?php
// Basic Usage
...
use Nikajorjika\SmsOffice\Facades\SmsOffice;

$phoneNumber = '855737812'; // It could also be 995855737812
$message = 'You have found your package ;).';

SmsOffice::message($message)->to($phoneNumber)->send();

作为通道

首先,我们需要在通过通道数组中包含 SmsOfficeChannel::class 并实现我们版本的 toSms 函数,如下所示。

<?php
...
use Nikajorjika\SmsOffice\SmsOfficeChannel;

class FooBarNotification extends Notification implements ShouldQueue
{
    use Queueable;

    ...

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return [SmsOfficeChannel::class];
    }

    /**
     * Return message to send via SmsOffice Channel
     *
     * @param mixed $notifiable
     * @return string $message
     */
    public function toSms($notifiable)
    {
        return 'You have found your package ;).';
    }

在我们的可通知模型中,例如 User,我们应该实现 routeNotificationForSms 方法,如下所示

...
use Illuminate\Notifications\Notifiable;

class User extends Authenticatable
{
    use Notifiable;

    /**
     * Get phone number from notifiable model
     *
     * @return string
     */
    public function routeNotificationForSms()
    {
        return $this->full_phone_number;
    }

就这样,现在我们将能够通过额外的 SmsOffice 通道发送通知。

软件包配置

贡献

欢迎提交拉取请求。对于重大更改,请先提出一个问题以讨论您想更改的内容。

请确保根据需要更新测试。

许可证

MIT