softon/sms

简单短信网关包,用于从您的应用程序发送短文本消息。Laravel 5 的外观。目前支持的网关包括 Clickatell、MVaayoo、Gupshup、SmsAchariya、SmsCountry、SmsLane、Nexmo、Mocker 以及任何基于 HTTP/s 的网关,都可以通过自定义网关支持。日志网关可用于测试。

v2.0.6 2020-09-23 09:53 UTC

This package is auto-updated.

Last update: 2024-09-23 18:28:03 UTC


README

简单 SMS(短消息服务)网关包,用于从您的应用程序发送短文本消息。Laravel 5 的外观(已更新以兼容 Laravel 5.*)。目前支持的网关包括 Clickatell、MVaayoo、Gupshup、SmsAchariya、SmsCountry、SmsLane、Nexmo、Mocker、MSG91 以及任何基于 HTTP/s 的网关,都可以通过自定义网关支持。日志网关可用于测试。

安装

  1. 编辑 composer.json 并将其添加到 require 数组中,然后运行 composer update
     composer require softon/sms 
  2. (可选,对于 Laravel 5.5+) 将服务提供者添加到 Laravel 的 config/app.php 文件中
     Softon\Sms\SmsServiceProvider::class, 
  3. (可选,对于 Laravel 5.5) 在 Laravel 的 config/app.php 文件中为外观添加别名
     'Sms' => Softon\Sms\Facades\Sms::class, 
  4. 运行以下命令发布配置和视图
     php artisan vendor:publish --provider="Softon\Sms\SmsServiceProvider" 

使用方法

编辑 config/sms.php。设置合适的网关及其参数。然后在您的代码中...
将您的短信 blade 模板放在 resources/views/sms 文件夹中。然后使用以下代码行发送短信。

use Softon\Sms\Facades\Sms;  

使用视图发送单个短信:

// Params: [MobileNumber,Blade View Location,SMS Params If Required]
Sms::send('9090909090','sms.test',['param1'=>'Name 1']);  

使用原始消息发送单个短信:

// Params: [MobileNumber,Blade View Location,SMS Params If Required]
Sms::send('9090909090','Any Message Text To be sent.');  

发送多个短信:

// Params: [Array of MobileNumbers,Blade View Location,SMS Params If Required]
Sms::send(['87686655455','1212121212','2323232323'],'sms.test',['param1'=>'Name 1']);  

在发送消息之前选择网关:

/*****************************************************
 Gateways ::  log / clickatell / gupshup / mvaayoo / 
              smsachariya / smscountry / smslane / 
              nexmo / msg91 / mocker / custom 
*****************************************************/

Sms::gateway('mocker')->send(['87686655455','1212121212','2323232323'],'sms.test',['param1'=>'Name 1']);  

带有响应:

// This command gives you the reply recieved from the server.
Sms::send(['87686655455','1212121212','2323232323'],'sms.test',['param1'=>'Name 1'])->response();  

自定义网关 假设您想使用其他网关。找到可以使用短信发送的 API URL。例如:http://example.com/api/sms.php?uid=737262316a&pin=YOURPIN&sender=your_sender_id&route=0&mobile=8888888888&message=How are You&pushid=1

然后您可以按如下方式设置自定义网关的配置

        'custom' => [                           // Can be used for any gateway
            'url' => '',                        // Gateway Endpoint
            'params' => [                       // Parameters to be included in the request
                'send_to_name' => 'mobile',           // Name of the field of recipient number
                'msg_name' => 'message',               // Name of the field of Message Text
                'others' => [                   // Other Authentication params with their values
                    'uid' => '737262316a',
                    'pin' => 'YOURPIN',
                    'sender' => 'your_sender_id',
                    'route' => '0',
                    'pushid' => '1',
                ],
            ],
            'add_code' => true,                 // Append country code to the mobile numbers
        ],