mmockelyn/laravel-ovh-sms

Laravel 7+ 的 OVH SMS API 集成。

1.0.1 2022-08-11 09:19 UTC

This package is not auto-updated.

Last update: 2024-09-20 17:32:41 UTC


README

这是 Laravel 7+ 的非官方 OVH SMS 集成库 ovh/php-ovh

摘要

安装

目前,此软件包未包含在 packagist 中(https://packagist.org.cn/)。您必须将私有仓库添加到 composer.json 文件中才能使用此软件包。您可以在 composer.json 文件中添加私有仓库,方法是在此部分添加以下内容:

{
"repositories": [
    {
      "name": "orykami/laravel-ovh-sms",
      "type": "git",
      "url": "https://github.com/orykami/laravel-ovh-sms"
    }
  ]
}

使用 composer 安装此软件包

composer require orykami/laravel-ovh-sms

更新 composer 后,将 ServiceProvider 添加到 config/app.php 文件中的 providers 数组

Illuminate\Notifications\OvhSmsChannelServiceProvider::class,

配置

此软件包需要在 config/services.php 中进行一些配置

return [
  // Add configuration to third party services
  'ovh' => [
    'app_key' => env('OVH_APP_KEY', 'YOUR_APP_KEY_HERE'),
    'app_secret' => env('OVH_APP_SECRET', 'YOUR_APP_SECRET_HERE'),
    'endpoint' => env('OVH_ENDPOINT', 'OVH_ENDPOINT_HERE'),
    'consumer_key' => env('OVH_CONSUMER_KEY', 'YOUR_CONSUMER_KEY_HERE'),
    'sms_account' => env('OVH_SMS_ACCOUNT', 'sms-xxxxxxx-x'),
    'sms_default_sender' => env('OVH_SMS_DEFAULT_SENDER', 'SENDER_NAME')),
    'sms_sandbox_mode' => env('OVH_SMS_SANDBOX_MODE', false)),
  ],
];

与 Laravel 通知一起使用

此软件包可以用作 Laravel 通知(Laravel >= 7.X)的驱动程序。

示例通知

以下是一个简单的通知示例。

namespace App\Notifications;

use Illuminate\Notifications\Channels\OvhSmsChannel;
use Illuminate\Notifications\Messages\OvhSmsMessage;
use Illuminate\Notifications\Notification;

class ExampleNotification extends Notification
{
    /**
     * Notification via OvhSmsChannel.
     */
    public function via($notifiable)
    {
        return [OvhSmsChannel::class];
    }

    /**
     * Your notification must implements "toOvh()"
     */
    public function toOvh($notifiable)
    {
    	return (new OvhSmsMessage('A new invoice was paid! Amount: $9.00'));
    }
}

此外,您的可通知模型必须实现 routeNotificationForOvhSms()

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Notifiable;
    
    /**
     * Returns the user's phone number.
     */
    public function routeNotificationForOvhSms()
    {
        return $this->phone; // Ex: +33611223344
    }
}

现在您已经准备好使用新的 Laravel 通知系统了! :-) 注意,Channel 方法 send 会返回消耗的 OVH 信用(如果需要配额/指标的话)。

许可协议

MIT