Coder Social home page Coder Social logo

laravel-sms's Introduction

Laravel Sms

StyleCI Latest Stable Version Total Downloads

一个基于Laravel框架的功能强大的手机号合法性验证解决方案。

1. 关于2.0

laravel-sms 2.0是基于toplan/phpsms开发的适用于Laravel框架的手机号验证解决方案。 phpsmslaravel-sms提供了全套的短信发送机制,而且phpsms也有自己的 service provider ,也就是说你完全可以在Laravel框架下无障碍的独立使用phpsms。 这也是为什么使用laravel-sms会在项目中生成两个配置文件(phpsms.phplaravel-sms.php)的原因。

config/phpsms.php负责配置代理器参数以及规划如何最优调度代理器(由phpsms提供), config/laravel-sms.php负责验证码发送/验证模块的配置(由laravel-sms提供)。

2. why me

为了更进一步提高开发效率,laravel-smsLaravel框架定制好了如下功能:

3. 如何快速开始?

上面提了这么多特性,那么如何快速上手并体验一下验证码发送与验证呢?只需要依次完成以下三个步骤即可。

公告

  • QQ群:159379848
  • 旧版本更新到2.6.4+版本时,建议更新原有的config/laravel-sms.phplaravel-sms.js文件(如果有用到)
  • 如果是Laravel 5.1版本,则需要在config/laravel-sms.php文件中注释掉middleware
  • 开发调试过程中,如果需要查看短信发送结果的详细信息,建议打开数据库日志

安装

在项目根目录下运行如下composer命令:

//推荐
composer require toplan/laravel-sms:~2.6

//安装开发中版本
composer require toplan/laravel-sms:dev-master

准备工作

1.注册服务提供器

在config/app.php文件中providers数组里加入:

Toplan\PhpSms\PhpSmsServiceProvider::class,
Toplan\Sms\SmsManagerServiceProvider::class,

在config/app.php文件中的aliases数组里加入

'PhpSms' => Toplan\PhpSms\Facades\Sms::class,
'SmsManager' => Toplan\Sms\Facades\SmsManager::class,

2.参数配置

  • 生成配置文件和migration文件
php artisan vendor:publish --provider="Toplan\PhpSms\PhpSmsServiceProvider"
php artisan vendor:publish --provider="Toplan\Sms\SmsManagerServiceProvider"

这里会生成两个配置文件,分别为phpsms.php和laravel-sms.php。

  • 配置代理器参数

在config/phpsms.php的agents数组中,找到你想要使用的代理器,并填写好配置信息。

  • 代理器均衡调度

在config/phpsms.php中设置代理器的均衡调度方案。

'scheme' => [
    //被使用概率为2/3
    'Luosimao' => '20',

    //被使用概率为1/3,且为备用代理器
    'YunPian' => '10 backup',

    //仅为备用代理器
    'YunTongXun' => '0 backup',
];

调度方案解析: 如果按照以上配置,那么系统首次会尝试使用LuosimaoYunPian发送短信,且它们被使用的概率分别为2/31/3。 如果使用其中一个代理器发送失败,那么会启用备用代理器,按照配置可知备用代理器有YunPianYunTongXun,那么会依次调用直到发送成功或无备用代理器可用。 值得注意的是,如果首次尝试的是YunPian,那么备用代理器将会只会使用YunTongXun,也就是会排除使用过的代理器。

发送前数据验证

1. 声明

当客户端向服务器端请求发送验证码短信/语音时,服务器端需要对接收到的数据(本库将其称为field)进行验证,只有在所有需验证的数据都通过了验证才会向第三方服务提供商发起请求。 对于每项你想验证的field,不管是使用静态验证规则还是动态验证规则,都需要提前到配置文件(config/laravel-sms.php)中声明,并做好必要的配置。

本文档中所说的服务器端是我们自己的应用系统,而非第三方短信服务提供商。

配置项

对于每项数据,都有以下几项可设置:

配置项 必填 说明
isMobile 是否为手机号码
enable 是否需要进行验证
default 默认静态验证规则
staticRules 所有静态验证规则

示例

'validation' => [
    //内置的mobile参数的验证配置
    'mobile' => [
        'isMobile'    => true,
        'enable'      => true,
        'default'     => 'mobile_required',
        'staticRules' => [
            'mobile_required' => 'required|zh_mobile',
            ...
        ],
    ],
    //自定义你可能需要验证的字段
    'image_captcha' => [
        'enable' => true,
    ],
],

2. 使用

静态验证规则和动态验证规则的使用方法一致。

客户端

通过{field}_rule参数告知服务器{field}参数需要使用的验证规则的名称。 比如mobile_rule参数可以告知服务器在验证mobile参数时使用什么验证规则, image_captcha_rule参数可以告知服务器在验证image_captcha参数时使用什么验证规则。

服务器端

示例见此

验证码模块

可以直接访问http[s]://your-domain/laravel-sms/info查看该模块是否启用,并可在该页面里观察验证码短信发送状态,方便你进行调试。

如果是api应用(无session)需要在上述地址后面加上?access_token=xxxx

1. [服务器端]配置短信内容/模板

短信内容

如果你使用了内容短信,则需要设置content的值。

配置文件为config/laravel-sms.php

'content' => function ($code, $minutes, $input) {
    return '【signature】您的验证码是' . $code . ',有效期为' . $minutes . '分钟,请尽快验证。';
}

模版id

如果你使用了模板短信,需要配置到使用到的代理器的模板标示符。

配置文件为config/laravel-sms.php

'templates' => [
    'YunTongXun' => '短信模版id',
    'Alidayu'    => ['短信模版id', '语音模版id'],
]

模版数据

如果你使用了模板短信,需要配置准备使用的模版数据。

配置文件为config/laravel-sms.php

'data' => [
    'code' => function ($code) {
        return $code;
    },
    ...
],

2. [浏览器端]请求发送验证码短信

该包已经封装好浏览器端的基于jQuery(zepto)的发送插件,只需要为发送按钮添加扩展方法即可实现发送短信。

js文件在本库的js文件夹中,请复制到项目资源目录。

<script src="/path/to/laravel-sms.js"></script>
<script>
$('#sendVerifySmsButton').sms({
    //laravel csrf token
    token       : "{{csrf_token()}}",
    //请求间隔时间
    interval    : 60,
    //请求参数
    requestData : {
        //手机号
        mobile : function () {
            return $('input[name=mobile]').val();
        },
        //手机号的检测规则
        mobile_rule : 'mobile_required'
    }
});
</script>

laravel-sms.js 的更多用法请见此

3. [服务器端]合法性验证

用户填写验证码并提交表单到服务器时,在你的控制器中需要验证手机号和验证码是否正确,你只需要加上如下代码即可:

use SmsManager;
...

//验证数据
$validator = Validator::make($request->all(), [
    'mobile'     => 'required|confirm_mobile_not_change|confirm_rule:mobile_required',
    'verifyCode' => 'required|verify_code',
    //more...
]);
if ($validator->fails()) {
   //验证失败后建议清空存储的发送状态,防止用户重复试错
   SmsManager::forgetState();
   return redirect()->back()->withErrors($validator);
}

confirm_mobile_not_change, verify_code, confirm_rule的详解请参看Validator扩展

Validator扩展

zh_mobile

检测标准的**大陆手机号码。

confirm_mobile_not_change

检测用户提交的手机号是否变更。

verify_code

检测验证码是否合法且有效,如果验证码错误,过期或超出尝试次数都无法验证通过。

confirm_rule:$ruleName

检测验证规则是否合法,后面跟的第一个参数为待检测的验证规则的名称。 如果不填写参数$ruleName(不写冒号才表示不填写哦),系统会尝试设置其为前一个访问路径的path部分。

数据库日志

开发调试过程中,如果需要查看短信发送结果的详细信息,建议打开数据库日志。

1. 生成数据表

运行如下命令在数据库中生成laravel_sms表。

php artisan migrate

2. 开启权限

在配置文件config/laravel-sms.php中设置dbLogstrue

'dbLogs' => true,

短信队列

1. 启用/关闭队列

laravel-sms已实现的短信队列默认是关闭的,判断当前队列状态:

$enable = PhpSms::queue(); //true of false

开启/关闭队列的示例如下:

//开启队列:
PhpSms::queue(true);

//关闭队列:
PhpSms::queue(false);

如果你开启了队列,需要运行如下命名监听队列

php artisan queue:listen

2. 队列自定义

如果你运行过php artisan app:name修改应用名称,或者需要自己实现队列工作逻辑,那么你需要进行自定义队列Job或者自定义队列流程(任选一种)。

  • 方式1:自定义队列Job

该方式只需要你自己实现一个Job class,然后在config/laravel-sms.php中键为queueJob处配置你使用的Job class。 值得注意的是你的Job class构造函数的第一个参数是Toplan\PhpSms\Sms的实例,发送时你只需要调用他的send()方法即可。

  • 方式2:自定义队列流程

在发送短信前,你可以完全重新定义你的队列流程!

//example:
PhpSms::queue(function($sms, $data){
    //假设如此推入队列:
    $this->dispatch(new YourQueueJobClass($sms));
});

无会话支持

1. 服务器端准备

config/laravel-sms.php中配置路由器组中间件middleware

//example:
'middleware' => ['api'],

2. Access Token

Access Token值建议设置在请求头中的Access-Token上,当然也可以带在请求参数access_token中。

根据你的实际应用场景,也可考虑将手机号作为access_token

3. 请求地址

  • 短信: scheme://host/laravel-sms/verify-code

  • 语音: scheme://host/laravel-sms/voice-verify

4. 默认参数

参数名 必填 说明
mobile 手机号码
mobile_rule 手机号检测规则

5. 响应数据

参数名 说明
success 是否请求发送成功
type 类型
message 详细信息

API

laravel-sms提供的所有功能都是由该章节的接口和phpsms的接口实现的。 虽然通过配置文件可以完成基本所有的常规需求,但是对于更加变态(个性化)的需求, 可能需要在laravel-sms的基础上做定制化的开发,在这种情况下阅读该章节或许能给你提供帮助,否则可以忽略该章节。

use SmsManager;

1. 发送前校验

validateSendable()

校验是否可进行发送。如果校验未通过,返回数据中会包含错误信息。

$result = SmsManager::validateSendable();

validateFields([$input][, $validation])

校验数据合法性。如果校验未通过,返回数据中会包含错误信息。

//使用内置的验证逻辑
$result = SmsManager::validateFields();

//自定义验证逻辑
$result = SmsManager::validateFields(function ($fields, $rules) {
    //在这里做你的验证处理,并返回结果...
    //如:
    return Validator::make($fields, $rules);
});

2. 发送

requestVerifySms()

请求发送验证码短信。

$result = SmsManager::requestVerifySms();

requestVoiceVerify()

请求发送语音验证码。

$result = SmsManager::requestVoiceVerify();

3. 发送状态

state([$key][, $default])

获取当前的发送状态(非持久化的)。

//example:
$state = SmsManager::state();

retrieveState([$key])

获取持久化存储的发送状态,即存储到session或缓存中的状态数据。

$state = SmsManager::retrieveState();

updateState($name, $value)

更新持久化存储的发送状态。

SmsManager::updateState('key', 'value');
SmsManager::updateState([
    'key' => 'value'
]);

forgetState()

删除持久化存储的发送状态。

SmsManager::forgetState();

4. 动态验证规则

storeRule($field[, $name], $rule);

定义客户端数据(字段)的动态验证规则。

//方式1:
//如果不设置name,那么name默认为当前访问路径的path部分
SmsManager::storeRule('mobile', 'required|zh_mobile|unique:users,mobile,NULL,id,account_id,1');

//方式2:
SmsManager::storeRule('mobile', 'myRuleName', 'required|zh_mobile|unique:users,mobile,NULL,id,account_id,1');

//方式3
SmsManager::storeRule('mobile', [
    'myRuleName' => 'required|zh_mobile|unique:users,mobile,NULL,id,account_id,1',
    'myRuleName2' => ...,
]);

存储的动态验证规则可通过访问http[s]://your-domain/laravel-sms/info查看。 动态验证规则的名称最好不要和静态验证规则同名,因为静态验证规则的优先级更高。

retrieveRule($field[, $name])

获取字段的指定名称的动态验证规则。

$rule = SmsManager::retrieveRule('mobile', 'myRuleName');

retrieveRules($field)

获取字段的所有动态验证规则。

$rules = SmsManager::retrieveRules('mobile');

forgetRule($field[, $name])

删除字段的指定名称的动态验证规则。

SmsManager::forgetRule('mobile', 'myRuleName');

forgetRules($field)

删除字段的所有动态验证规则。

SmsManager::forgetRules('mobile');

5. 客户端数据

input([$key][, $default])

获取客户端传递来的数据。客户端数据会自动注入到配置文件(laravel-sms.php)中闭包函数的$input参数中。

$mobileRuleName = SmsManager::input('mobile_rule');
$all = SmsManager::input();

6. 其它

closure($closure)

序列化闭包。

SmsManager::closure(function () {
    //do someting...
});

laravel-sms.js

$('#sendVerifySmsButton').sms({
    //laravel csrf token
    //该token仅为laravel框架的csrf验证,不是access_token!
    token       : "{{csrf_token()}}",

    //请求时间间隔
    interval    : 60,

    //语音验证码
    voice       : false,

    //请求参数
    requestData : {
        //手机号
        mobile: function () {
            return $('input[name=mobile]').val();
        },
        //手机号的检测规则
        mobile_rule: 'mobile_required'
    },

    //消息展示方式(默认为alert)
    notify      : function (msg, type) {
        alert(msg);
    },

    //语言包
    language    : {
        sending    : '短信发送中...',
        failed     : '请求失败,请重试',
        resendable : '{{seconds}} 秒后再次发送'
    }
});

License

MIT

laravel-sms's People

Contributors

goodspb avatar hiship avatar jzyuchen avatar kslr avatar medz avatar nauxliu avatar skys215 avatar toplan avatar yaoshanliang avatar zhichao-poper avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laravel-sms's Issues

vendor publish error

/Applications/XAMPP/xamppfiles/bin/php /Users/liwei/Documents/dev/huifeng/artisan vendor:publish

[Toplan\PhpSms\PhpSmsException]
Please set at least one enable agent in config file(config/phpsms.php) or use method enable()

Process finished with exit code 1 at 19:03:47.
Execution time: 89 ms.

php artisan vendor:publish 后出现错误

按照首页教程,一步一步来,当进行到:

php artisan vendor:publish

出现以下错误:

[Toplan\PhpSms\PhpSmsException]
Please set at least one enable agent in config file(config/phpsms.php) or use method enable()

SUBMAIL 发送成功后有错误信息

SUBMAIL 成功的时候没有返回 msg,导致发送信息后提示错误。

Undefined index: msg(30行)
/Path/To/WWW/vendor/toplan/laravel-sms/src/Toplan/LaravelSms/agents/SubMailAgent.php

以下是SUBMAIL官方提供的返回内容。

http://submail.cn/chs/documents/developer/t2f1J2
请求成功

{
"status":"success"
"send_id":"093c0a7df143c087d6cba9cdf0cf3738"
"sms_credits":14197
}
请求失败

{
"status":"error",
"code":"1xx",
"msg":"error message"
}

如何查看提交发送短信后,服务商的返回结果呢?

用这个方法发短信:

//只希望使用模板方式发送短信,可以不设置内容content (如云通讯,Submail)
PhpSms::make()->to('1828****349')->template('Luosimao', 'xxx')->data(['12345', 5])->send();

如何查看服务商返回的结果呢?
谢谢。

一个关于类名规范的建议

建议把底层的类名改为PhpSms,和对外提供的一样。不一样的话在触发事件的时候,由于对外提供的是PhpSms,很容易让人误解:

$sms = PhpSms::make()->to($request->input('phone'))->template([
            'Alidayu' => '123'
        ])->data([
            'code' => (string)$verfiyCode,
            'product' => '123'
        ]);

        dd( event(new SendSms($sms)) );

如下这段代码,在触发事件的时候需要一个短信对象,这个对象类型必须用Sms提示,但是对外提供的却是PhpSms,如果没去看源码,肯定会掉坑里面

confirm_rule:mobile,mobile_required是什么意思

confirm_rule:mobile,mobile_required是应用mobile_required规则吗?
我在validation文件中应用
'mobile' => [
'unique' => '手机号码已经注册,请直接登录',
'required' => '请填写手机号码',
'zh_mobile' => '手机号码格式错误',
'confirm_rule' => '手机号码前后不一致',
],
后一直提示手机号码前后不一致;

放在:
'verifyCode' =>[
'required' => '请输入验证码',
'verify_code' => '验证码错误',
'confirm_rule' => '手机号码前后不一致',
],
这里又一直提示validation.confirm_rule

特殊情况

请问下 我用自定义的代理发送短信内容/使用云之讯发送语音,这种情况下怎样切换代理?!

云片模板问题

云片已支持模板短信发送,详情如下:
//模板接口样例(不推荐。需要测试请将注释去掉。)
/* 以下代码块已被注释
$apikey = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; //请用自己的apikey代替
$mobile = "xxxxxxxxxxx"; //请用自己的手机号代替
$tpl_id = 1; //对应默认模板 【#company#】您的验证码是#code#
$tpl_value = "#company#=云片网&#code#=1234";
echo tpl_send_sms($apikey,$tpl_id, $tpl_value, $mobile);
*/
我看到你代码中并没有开发这个功能:
public function sendTemplateSms($tempId, $to, Array $data)
{
return null;
}

云通讯发送成功返回没有statusMsg属性

云通讯发送短信成功返回的$result
不存在statusMsg属性。
会报以下错误
Undefined property: stdClass::$statusMsg

"line":78,"file":"/vendor/toplan/phpsms/src/phpsms/agents/YunTongXunAgent.php",

发送短信验证规则提示问题

$vars['passed'] = false;
if ($rule == 'check_mobile_unique') {
$vars['msg'] = '该手机号码已存在';
} elseif ($rule == 'check_mobile_exists') {
$vars['msg'] = '不存在此手机号码';
} else {
$vars['msg'] = '抱歉,你的手机号未通过合法性检测';
}
$vars['type'] = $rule;

如果新增一个rule,无法定制错误提醒,都会进到else中提示手机号未通过合法性监测,比如增加一个后台限制60秒只接受一条发送的规则防止机器人刷短信。提示无法更改。建议从lang文件中取提示。根据rule的namespace

在请求验证码mobileRule参数为空的时候会导致500错误

在请求验证码mobileRule参数为空,并且URL::previous()无法获取到“path”的时候会导致 $realName = $parsed['path'];请求失败500错误

/**
     * retrieve custom mobile rule
     *
     * @param $token
     * @param string|null $name
     *
     * @throws LaravelSmsException
     *
     * @return mixed
     */
    public function retrieveMobileRule($token, $name = null)
    {
        if (!$name) {
            $parsed = parse_url(URL::previous());
            $realName = $parsed['path'];
        } else {
            $realName = $name;
        }
        $key = $this->getStoreKey($token, self::CUSTOM_RULE_FLAG, $realName);
        $customRule = $this->storage()->get($key, '');
        if ($name && !$customRule) {
            return $this->retrieveMobileRule($token, null);
        }

        return $customRule;
    }

Laravel 5.1 support

这个包兼容 laravel 5.1.x 吗?

./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for toplan/laravel-sms dev-master -> satisfiable by toplan/laravel-sms[dev-master].
    - Conclusion: remove laravel/framework v5.1.0
    - Conclusion: don't install laravel/framework v5.1.0
    - toplan/laravel-sms dev-master requires illuminate/support 5.0.* -> satisfiable by illuminate/support[5.0.x-dev, v5.0.0, v5.0.22, v5.0.25, v5.0.26, v5.0.28, v5.0.33, v5.0.4].
    - don't install illuminate/support 5.0.x-dev|don't install laravel/framework v5.1.0
    - don't install illuminate/support v5.0.0|don't install laravel/framework v5.1.0
    - don't install illuminate/support v5.0.22|don't install laravel/framework v5.1.0
    - don't install illuminate/support v5.0.25|don't install laravel/framework v5.1.0
    - don't install illuminate/support v5.0.26|don't install laravel/framework v5.1.0
    - don't install illuminate/support v5.0.28|don't install laravel/framework v5.1.0
    - don't install illuminate/support v5.0.33|don't install laravel/framework v5.1.0
    - don't install illuminate/support v5.0.4|don't install laravel/framework v5.1.0
    - Installation request for laravel/framework == 5.1.0.0 -> satisfiable by laravel/framework[v5.1.0].

luosimao不支持批量发送API,不可以用逗号把收件人手机号分开

做了点小改动,但感觉这样效率不高,希望toplan能够给出更好的方案
public function sendContentSms($to, $content)
{
//因为Luosimao的签名必须放在最后,所以发送前需要检测签名位置
//如果不是在最后,则调整至最后
$content = trim($content);
if ($content &amp;&amp; !preg_match('/】$/', $content)) {
preg_match('/【([0-9a-zA-Z\W]+)】/', $content, $matches);
$content = str_replace($matches[0], '', $content) . $matches[0];
}

    $url = 'https://sms-api.luosimao.com/v1/send.json';
    $apikey = $this->apikey;

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "$url");

    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_HEADER, FALSE);

    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    curl_setopt($ch, CURLOPT_USERPWD, 'api:key-' . $apikey);

    curl_setopt($ch, CURLOPT_POST, TRUE);


    $phone_list = explode(',', $to);
    foreach ($phone_list as $phone) {
        $optData = [
            'mobile' => $phone,
            'message' => $content
        ];
        curl_setopt($ch, CURLOPT_POSTFIELDS, $optData);
        $res = curl_exec($ch);
    }

    curl_close($ch);

    $data = json_decode($res, true);
    if ($data['error'] == 0) {
        $this->result['success'] = true;
    }
    $this->result['info'] = $this->currentAgentName . ':' . $data['msg'] . "({$data['error']})";
    $this->result['code'] = $data['error'];
}

Class 'Toplan\PhpSms\Facades\Sms' not found

Laravel5.2
laravel-sms v2.2.6

在本地Mac运行正常,可以发送短信,但是在Ubuntu系统报错:

  • ErrorException in AliasLoader.php line 66:
  • Class 'Toplan\PhpSms\Facades\Sms' not found

然后检查了一下:

  • var_dump(class_exists('Toplan\PhpSms\Facades\Sms'));
  • var_dump(class_exists('Toplan\Sms\Facades\SmsManager'));

输出:

  • bool(false) bool(true)

代码是完全一样的,有没有人遇到过这问题?
可能是什么原因导致的呢?目录名字大小写?

result_info 没有默认值

在发送验证码之前保存 sms 记录的时候 result_info 没有默认值,对于一些 MySQL 实例不能成功添加记录,建议在 save() 之前给 result_info 赋默认值(可以是空值)

[2015-08-13 16:41:26] local.ERROR: exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 1364 Field 'result_info' doesn't have a default value' in /home/vcap/app/vendor/laravel/framework/src/Illuminate/Database/Connection.php:380
...
#13 /home/vcap/app/vendor/toplan/laravel-sms/src/Toplan/LaravelSms/models/Sms.php(177): Illuminate\Database\Eloquent\Model->save()
#14 /home/vcap/app/vendor/toplan/laravel-sms/src/Toplan/LaravelSms/SmsContorller.php(76): Toplan\Sms\Sms->send()
#15 [internal function]: Toplan\Sms\SmsController->postSendCode('check_mobile_un...', '159xxxxxxxx')

云片网络是不支持内容短信的啊

是不是搞错了,亲,云片网络是不支持内容短信的啊
Toplan\Sms\Sms::make(‘1’)->to('1828****349')->data(['12345', 5])->send();
我这样调的然后返回参数错误!?

是我的姿势不对吗?.... ie8下,js报错.

chrome等都好好的, 就是ie8, 加载后就会出错. 呃... 当前界面没有

        var opts = $.extend(
            $.fn.sms.default,
            options
        );

报错是这个 $.fn.sms.default,.
打开ie8的调试台, 显示 缺少标识符 点击后 光标聚焦到 sms.这里....

[服务器端]合法性验证的问题

[服务器端]合法性验证 在控制器需要引入什么文件吗? 为什么我这边测试不成功呢

$validator = \Validator::make($request->all(), [
'mobile' => 'required|mobile_changed',
'verifyCode' => 'required|verify_code|verify_rule:check_mobile_unique',
//more...
]);

    if ($validator->fails()) {
        //验证失败的话需要清除session数据,防止用户多次试错
        \SmsManager::forgetSmsDataFromSession();
        return redirect()->back()->withErrors($validator);
    }

不管输入什么都会报mobile_changed verify_code verify_rule这三个字段的错误消息

【路由改进】发送验证码路由改进

1、路由改进方式:
/sms/verify-code/rule/{$rule}/mobile/{$mobile}
$ruleName指定验证方式;$mobile为手机号码。

2、相应的在服务器端为新加validation验证rule
"verify_rule:{$ruleName}"
如果session中的rule name不等于指定的$ruleName,那么说明是非法请求。

访问 /sms/info 系统报错

访问 /sms/info 系统报错
根据帮助文件:

可以直接访问example.com/sms/info查看该模块是否可用,并可在该页面里观察验证码短信发送数据,方便你进行调试。

但是我访问example.com/sms/info 系统会报错。
snip20160120_22

怎么validation.php中适配错误提示

'custom' => [
'phone' => [
'mobile_required' => '请填写手机号码',
],
]
这个规则无效;
'custom' => [
'phone' => [
'mobile_required.required' => '请填写手机号码',
],
]
也无效。
请问怎么添加规则呢?

日志表名称

很棒!
表名称laravel_sms改为可配置的,config/laravel-sms.php中可以指定表的名称,这样更友好些哦~

PhpSms Not Found

在Controller中,用PhpSms::make()发送短信时提示PhpSms Not Found,请问要导入哪个类?而且我已经在app.php文件中配置过了
谢谢 :)

SmsController命名空间会产生冲突

SmsController命名空间会产生冲突

PHP Fatal error:  Cannot use SmsManager as SmsManager because the name is already in use in /Users/liguochun/Documents/StarShow/lookme/vendor/toplan/laravel-sms/src/Toplan/LaravelSms/SmsController.php on line 7

解决办法

toplan/laravel-sms/src/Toplan/LaravelSms/SmsController.php

<?php

namespace Toplan\Sms;

use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Toplan\Sms\SmsManager;

class SmsController extends Controller

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.