55 lines
1.4 KiB
PHP
55 lines
1.4 KiB
PHP
<?php
|
||
// +------------------------------------------------+
|
||
// |http://www.cjango.com |
|
||
// +------------------------------------------------+
|
||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||
// +------------------------------------------------+
|
||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||
// +------------------------------------------------+
|
||
namespace app\common\validate;
|
||
|
||
use think\Db;
|
||
use think\Validate;
|
||
use tools\Verify;
|
||
|
||
class Sms extends Validate
|
||
{
|
||
/**
|
||
* 验证规则
|
||
* @var array
|
||
*/
|
||
protected $rule = [
|
||
'mobile' => 'require|checkMobile:|checkTimes:',
|
||
'code' => 'require|length:4,6',
|
||
];
|
||
|
||
/**
|
||
* 错误提示消息
|
||
* @var array
|
||
*/
|
||
protected $message = [
|
||
'mobile.require' => '手机号码 必须填写',
|
||
'mobile.checkMobile' => '手机号码 格式有误',
|
||
'code.require' => '验证码 必须填写',
|
||
'code.length' => '验证码 长度有误',
|
||
];
|
||
|
||
protected $scene = [
|
||
|
||
];
|
||
|
||
protected function checkTimes($value)
|
||
{
|
||
if (time() - Db::name('Sms')->where('mobile', $value)->order('id desc')->value('create_time') < 60) {
|
||
return '发送频率过快';
|
||
} else {
|
||
return true;
|
||
}
|
||
}
|
||
|
||
protected function checkMobile($value)
|
||
{
|
||
return Verify::isMobilePhone($value);
|
||
}
|
||
}
|