/**
* 检测手机短信验证码
*/
protected function checkRegSms($mobile, $code = false)
{
if (!$mobile) return false;
if ($code === false) { //判断60秒以内是否重复发送
if (!Cache::has('sms_' . $mobile)) return true;
if (Cache::get('sms_' . $mobile)['times'] > time()) {
return false;
} else {
return true;
}
} else { //判断验证码是否输入正确
if (!Cache::has('sms_' . $mobile)) return false;
if (Cache::get('sms_' . $mobile)['code'] == $code) {
return true;
} else {
return false;
}
}
}
/**
* 设置手机短息验证码缓存
*/
protected function setRegSmsCache($data_cache)
{
Cache::set('sms_'. $data_cache['mobile'], $data_cache, 300);
}
《PHP-Cache实现短信验证码验证》
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.