zhandos-prog/mobizon-sms-driver

tzsk/sms 的 Mobizon SMS 驱动程序包

0.2.0 2023-03-03 08:39 UTC

This package is auto-updated.

Last update: 2024-09-30 02:02:49 UTC


README

要求

功能

  • [✓] 发送单个短信
  • [✓] 发送批量短信

安装

composer require zhandos-prog/mobizon-sms-driver

配置

发布配置文件

$ php artisan sms:publish

在配置文件中,您可以设置用于所有短信的默认驱动程序。但您也可以在运行时更改驱动程序。

选择您想要为您的应用程序使用的网关。然后将它设置为默认驱动程序,这样您就无需在各个地方指定它。但是,您也可以在项目中使用多个网关。

配置文件路径:app/config/sms.php

// Eg. if you want to use MobizonSmsDriver.
'default' => 'smsmobizon',

然后在 drivers 数组中填写该网关的凭证。

// Eg. for MobizonSmsDriver.
'drivers' => [
    'smsmobizon' => [
        // Fill all the credentials here.
        'apiKey' => 'Your Api Key',
        'from' => 'Your Mobizon Sender ID',
        'url' => 'Your Url Api'
    ],
    ...
]

类 MobizonSmsDriver 需要映射,在 map 部分指定它

// Eg. for MobizonSmsDriver.
'map' => [
    ...
    'smsmobizon' => ZhandosProg\MobizonSmsDriver\Driver\MobizonDriver::class,
]

注册服务提供者

配置文件路径:app/config/app.php

// Eg. for MobizonSmsDriver.
'providers' => [
    ...
    ZhandosProg\MobizonSmsDriver\MobizonServiceProvider::class,
]

使用

在您的代码中,可以这样使用它。

use ZhandosProg\MobizonSmsDriver\MobizonSenderSMSInterface;

Class ExampleController {
    
    private MobizonSenderSMSInterface $mobizonSenderSMS;
    
    public function __construct(MobizonSenderSMSInterface $mobizonSenderSMS)
    {
        $this->mobizonSenderSMS = $mobizonSenderSMS
    }
    
    public function single()
    {
        /// ... your logic
       
        $response = $this->mobizonSenderSMS->send('77779998877', '42')
        dd($response);
        
        /// ... your logic
    }
    
    public function mass()
    {
        /// ... your logic
       
        $response = $this->mobizonSenderSMS->send(['77773335566','87774444242'], '42')
        dd($response);
        
        /// ... your logic
    }
}

您还可以使用包门面 Laravel SMS Gateway。所有详细信息在 使用 部分!

如果您使用门面 Laravel SMS Gateway,则无需注册服务提供者!

异常

  • PhoneNumberValidationException