All Projects → guojiangclub → laravel-sms

guojiangclub / laravel-sms

Licence: MIT license
Laravel 贴合实际需求同时满足多种通道的短信发送组件

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to laravel-sms

laravelbdsms
Xenon\LaravelBDSms is a sms gateway package for sending text message to Bangladeshi mobile numbers using several gateways like sslcommerz, greenweb, dianahost, metronet,boomcast, bulksmsbd, banglalink from Laravel framework
Stars: ✭ 68 (+1.49%)
Mutual labels:  sms, laravel-sms
laravel-sms-api
Laravel package to provide SMS API integration.
Stars: ✭ 84 (+25.37%)
Mutual labels:  sms, laravel-sms
laravel-sms
Package for sending SMS from your Laravel app / Пакет для отправки смс из вашего приложения Laravel
Stars: ✭ 21 (-68.66%)
Mutual labels:  sms, laravel-sms
laravel-zend-acl
Adds ACL to Laravel via Zend\Permissions\Acl component.
Stars: ✭ 41 (-38.81%)
Mutual labels:  laravel-5-package
voyager-portfolio
A Portfolio Module for Laravel Voyager 💋
Stars: ✭ 15 (-77.61%)
Mutual labels:  laravel-5-package
laravel-ab
Laravel A/B experiment testing tool
Stars: ✭ 108 (+61.19%)
Mutual labels:  laravel-5-package
Simple-SMS-Messenger
An easy and quick way of managing SMS and MMS messages without ads.
Stars: ✭ 358 (+434.33%)
Mutual labels:  sms
EVIL-EMAIL-SMS-BOMBER
The EVIL EMAIL/SMS BOMBER is made for research and testing purposes only. Prank your friends. EVIL EMAIL/SMS BOMBER can send bulk mail or SMS text messages. DISCLAIMER: Use at your own risk! I take no responsibility for your actions. This was made for pranks, testing and investigation purposes only. Coded by Jeff Childers
Stars: ✭ 36 (-46.27%)
Mutual labels:  sms
sms-bot
an SMS bot built with Google sheets and Twilio
Stars: ✭ 61 (-8.96%)
Mutual labels:  sms
voyager-page-blocks
A module to provide page blocks for Voyager 📝
Stars: ✭ 80 (+19.4%)
Mutual labels:  laravel-5-package
cmd-sms
Yeni nesil sms guard bot
Stars: ✭ 2 (-97.01%)
Mutual labels:  sms
keycloak-phone-provider
A Keycloak provider which phone and SMS
Stars: ✭ 83 (+23.88%)
Mutual labels:  sms
laravel-payfort
Laravel Payfort provides a simple and rich way to perform and handle operations for Payfort online payment gateway
Stars: ✭ 14 (-79.1%)
Mutual labels:  laravel-5-package
LARAVEL-PDF-VIEWER
A Laravel Package for viewing PDF files or documents on the web without leaving your Web Application
Stars: ✭ 80 (+19.4%)
Mutual labels:  laravel-5-package
Laralang
This package lets you translate any string to multiple languages easily in laravel 5.4
Stars: ✭ 45 (-32.84%)
Mutual labels:  laravel-5-package
laravel-form-builder
laravel专用表单生成器,快速生成现代化的form表单。包含复选框、单选框、输入框、下拉选择框等元素以及,省市区三级联动,时间选择,日期选择,颜色选择,树型,文件/图片上传等功能。
Stars: ✭ 59 (-11.94%)
Mutual labels:  laravel-5-package
ChristmasSpiritBreaker-andNewYearsToo
Python script which automatically sends Christmas/New Year's messages from a custom messages list on Whatsapp, Facebook Messenger or via SMS in a given time range, to a custom contacts list. Time to work smart, not hard.
Stars: ✭ 81 (+20.9%)
Mutual labels:  sms
laravel-admin-lte
Easy AdminLTE integration with Laravel and laravel mix friendly.
Stars: ✭ 25 (-62.69%)
Mutual labels:  laravel-5-package
laravel-ses
A Laravel Package that allows you to get simple sending statistics for emails you send through SES, including deliveries, opens, bounces, complaints and link tracking
Stars: ✭ 39 (-41.79%)
Mutual labels:  laravel-5-package
sms-spring-boot-project
短信服务Spring Boot Starter ,目前支持腾讯、阿里、赛邮和云之讯短信服务,腾讯、阿里、赛邮和云之讯短信均已验证,期待各位小伙伴合作完善这个项目
Stars: ✭ 79 (+17.91%)
Mutual labels:  sms

Laravel Sms

Laravel 贴合实际需求同时满足多种通道的短信发送组件

Build Status Scrutinizer Code Quality Code Coverage Build Status Latest Stable Version Latest Unstable Version License

Featrue

基于业务需求在 overtrue/easy-sms 基础进行扩展开发,主要实现如下目标:

  1. 支持短信验证码直接在 config 中配置模板ID
  2. 支持短信验证码自定义长度
  3. 支持短信验证码有效分钟,默认5分钟
  4. 支持短信验证码重试次数,防止用户意外输错验证码导致需要再次发送验证码的问题。
  5. 支持短信验证码未验证时,用户再次请求验证码,在有效分钟内验证码保持一致。
  6. 集成短信发送路由,支持 web 和 api 发送方式。
  7. 支持验证码调试,debug 模式下可直接查询手机号目前有效的验证码
  8. 支持短信验证码发送记录保存到数据库
  9. 短信发送频率限制,同一 IP 限定时间内请求次数

TODO:

  1. 支持语音验证码

安装

composer require ibrand/laravel-sms:~1.0 -vvv

低于 Laravel5.5 版本

config/app.php 文件中 'providers' 添加

iBrand\Sms\ServiceProvider::class

config/app.php 文件中 'aliases' 添加

'Sms'=> iBrand\Sms\Facade::class

使用

发送验证码

  1. 实现了发送短信验证码路由,支持 web 和 api ,可以自定义路由的 prefix。
'route' => [
        'prefix' => 'sms',
        'middleware' => ['web'],
    ],
    
or

'route' => [
        'prefix' => 'sms',
        'middleware' => ['api'],
    ],

POST请求 http://your.domain/sms/verify-code

参数:mobile

备注:为了开发调试方便,在 debug 模式下不会验证手机的有效性。

返回参数:

{
    "status": true,
    "message": "短信发送成功"
}
  1. 如果需要自定义路由,也可以通过使用Facade发送验证码:
use iBrand\Sms\Facade as Sms;

Sms::send(request('mobile'));

由于使用多网关发送,所以一条短信要支持多平台发送,每家的发送方式不一样,但是我们抽象定义了以下公用属性:

  • content 文字内容,使用在像云片类似的以文字内容发送的平台
  • template 模板 ID,使用在以模板ID来发送短信的平台
  • data 模板变量,使用在以模板ID来发送短信的平台
use iBrand\Sms\Facade as Sms;

Sms::send(request('mobile'), [
    'content'  => '您的验证码为: 83115',
    'template' => 'SMS_001',
    'data' => [
        'code' => 83115
    ],
]);

默认使用 default 中的设置来发送,如果某一条短信你想要覆盖默认的设置。在 send 方法中使用第三个参数即可:

use iBrand\Sms\Facade as Sms;

Sms::send((request('mobile'), [
    'content'  => '您的验证码为: 83115',
    'template' => 'SMS_001',
    'data' => [
        'code' => 83115
    ],
], ['aliyun']); // 这里的网关配置将会覆盖全局默认

定义短信

容联云通讯为例:你可以根据发送场景的不同,定义不同的短信类,通过继承 Overtrue\EasySms\Message 来定义短信模型:

<?php
    
use Overtrue\EasySms\Message;
use Overtrue\EasySms\Contracts\GatewayInterface;

class CustomMessage extends Message
{
    protected $code;
    protected $gateways = ['yuntongxun']; //在sms.php配置文件中添加gateways选项: yuntongxun
    //...

    public function __construct($code)
    {
        $this->code = $code;
    }

    // 定义直接使用内容发送平台的内容
    public function getContent(GatewayInterface $gateway = null)
    {
    	
    }

    // 定义使用模板发送方式平台所需要的模板 ID
    public function getTemplate(GatewayInterface $gateway = null)
    {
        return 'templateId';
    }

    // 模板参数
    public function getData(GatewayInterface $gateway = null)
    {
        return [
            $this->code,
            //...
        ];    
    }
}

使用,具体请参考iBrand\Sms\Test\CustomMessage

use iBrand\Sms\Facade as Sms;
$code = Sms::getNewCode(request('mobile'));
$message = new CustomMessage($code->code);

Sms::send(request('mobile'), $message, ['yuntongxun']);

验证验证码

use iBrand\Sms\Facade as Sms;

if (!Sms::checkCode(\request('mobile'), \request('code'))) {
    //Add you code.
}

配置模板 ID

config/ibrand/sms.phpgateways 参数可以直接添加 code_template_id 来配置模板 id

    // 可用的网关配置
        'gateways' => [

            'errorlog' => [
                'file' => '/tmp/easy-sms.log',
            ],

            'yunpian' => [
                'api_key' => '824f0ff2f71cab52936axxxxxxxxxx',
            ],

            'aliyun' => [
                'access_key_id' => 'dalvTXXX',
                'access_key_secret' => 'XXXX',
                'sign_name' => '阿里云短信测试专用',
                'code_template_id' => 'SMS_80215252'
            ],

            'alidayu' => 
                //...
            ],
        ],

配置 Content

非模板类通道,可以通过 config/ibrand/sms.php 自定义短信内容

'content' => '【your signature】亲爱的用户,您的验证码是%s。有效期为%s分钟,请尽快验证。'

debug

在实际开发中会存在并不用真实发出验证码的情况,因此在 debug 模式下,可以通过

http://your.domain/api/sms/info?mobile=1898888XXXX 来直接只看某个手机号当前有效验证码信息。

database log

目前已经支持把发送记录保存到数据库,执行 php artisan migrate 生成  laravel_sms_log 表。

同时在 config/ibrand/sms.phpdblog 设置为 true

'dblog' => true,

Resources

  1. overtrue/easy-sms
  2. toplan/laravel-sms

果酱云社区

点击跳转

  • 全网真正免费的IT课程平台

  • 专注于综合IT技术的在线课程,致力于打造优质、高效的IT在线教育平台

  • 课程方向包含Python、Java、前端、大数据、数据分析、人工智能等热门IT课程

  • 300+免费课程任你选择

点击跳转

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].