12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- <?php
- namespace App\Rules;
- use Illuminate\Contracts\Validation\Rule;
- use Vinkla\Hashids\Facades\Hashids;
- /**
- * 检测邮件验证码
- *
- * @author 刘相欣
- *
- */
- class CheckCode implements Rule{
- /**
- * 判断是否通过验证规则
- *
- * @param string $attribute
- * @param mixed $value
- * @return bool
- */
- public function passes($attribute, $value)
- {
- // 解密
- $client_id = request('client_id','');
- // 解码
- $client_id = Hashids::decode($client_id);
- // 错误提示
- if( !$client_id ) return false;
- // 验证码
- $code = empty($client_id[0]) ? '' : $client_id[0];
- // 过期时间
- $expire = empty($client_id[1]) ? 0 : $client_id[1];
- // 比对验证码
- if( $code != $value ) return false;
- // 过期
- if( $expire < time() ) return false;
- // 返回正确
- return true;
- }
- /**
- * 获取校验错误信息
- *
- * @return string
- */
- public function message()
- {
- return trans('validation.check_code');
- }
- }
|