2017 © Pedro Peláez
 

library laravel-sms

SMS gateway package for laravel5

image

hinet/laravel-sms

SMS gateway package for laravel5

  • Friday, December 29, 2017
  • by hinet
  • Repository
  • 1 Watchers
  • 1 Stars
  • 76 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 7 Versions
  • 85 % Grown

The README.md

laravel-sms

基于Laravel与Lumen的短信发送网关,支持阿里云短信、腾讯云短信、百度云短信、SendCloud;极易扩展,你可以自由定义自已的网关驱动。, (*1)

安装

composer require hinet/laravel-sms, (*2)

配置

  • 注册服务提供器 在config/app.php文件中providers数组里加入:
Hinet\Sms\SmsServiceProvider::class,

在config/app.php文件中的aliases数组里加入, (*3)

'Sms' => Hinet\Sms\Facades\Sms::class,
  • 发布配置文件
php artisan vendor:publish --tag=smsconfig
  • 注意事项

在web路由中,可以使用session或cache来存储状态;在api路由需要使用cache存储,因为api中间件中不含session会话支持, (*4)

//config/sms.php
//存储器
'storage' => [
        'prefix' => '',//存储key的前缀
        'driver' => 'cache',//存储方式,内置可选的值有'session'和'cache',api路由中请使用cache
]

网关

平台 网关名称
阿里云 aliyun
腾讯云 qcloud
百度云 baidu
聚合 juhe
sendcloud sendcloud

使用方法

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Sms;

class HomeController extends Controller
{
    public function index(){
        $gateway = Sms::gateway('aliyun');
        //发送
        echo $gateway->send('测试手机号码');
        //校验码是否正确
        echo $gateway->verifyCode('测试手机号码','验证码');
    }
}

自定义验证

打开app\Providers\AppServiceProvider.php文件,在boot()方法中添加:, (*5)

//use Illuminate\Support\Facades\Validator;
Validator::extend('verify_sms', function ($attribute, $value, $parameters) {
    $mobile = app('request')->input($parameters[0]);
    $gateway = \Sms::gateway(config('sms.default'));
    return $gateway->verifyCode($mobile,$value);
});

验证示例:, (*6)

$validator = Validator::make($data, [
      'phone' => 'unique:表名',
      'verifyCode' => 'verify_sms:phone',//verifyCode为表单中的验证码名称,verify_sms为短信验证方法名,phone为表单中的手机号字段名
]);

Testing

拷贝单元测试文件SmsUnitTest.php到根目录tests文件中',并在命令行执行:, (*7)

vendor\bin\phpunit tests\SmsUnitTest.php

The Versions

29/12 2017

dev-master

9999999-dev

SMS gateway package for laravel5

  Sources   Download

MIT

The Requires

 

The Development Requires

29/12 2017

1.1.2

1.1.2.0

SMS gateway package for laravel5

  Sources   Download

MIT

The Requires

 

The Development Requires

29/12 2017

1.1.1

1.1.1.0

SMS gateway package for laravel5

  Sources   Download

MIT

The Requires

 

The Development Requires

29/12 2017

1.1.0

1.1.0.0

SMS gateway package for laravel5

  Sources   Download

MIT

The Requires

 

The Development Requires

27/04 2017

1.0.3

1.0.3.0

SMS gateway package for laravel5

  Sources   Download

MIT

The Requires

 

The Development Requires

27/04 2017

1.0.2

1.0.2.0

SMS gateway package for laravel5

  Sources   Download

MIT

The Requires

 

The Development Requires

27/04 2017

1.0.0

1.0.0.0

SMS gateway package for laravel5

  Sources   Download

MIT

The Requires

 

The Development Requires