- 设置手机短信验证码缓存方法:
/**
* 设置手机短信验证码缓存
* #User: JW
* #Email:jw_333@163.com
* #Date:
* @param $data_cache
*/
public function setRegSmsCache($data_cache)
{
Cache::set('sms_' . $data_cache['mobile'], $data_cache, 300);
}
调动手机短信验证码缓存方法
public function send_text_message()
$data['time']=time()+60;//验证码过期时这里设置的是一分钟后过期
$data['mobile']='18888888888';//接受短信的手机号
$data['code']= rand(100000,999999);//随机获取6位短信验证码
$this->setRegSmsCache($data);
}
- 验证手机短信验证码缓存方法:
/**
* 验证验证码是否是否正确
* @param $mobile 接收人
* @param $code 短信验证码
* @return json
*/
public function checkRegSms($mobile, $code = false){
if (!$mobile) return false;
if ($code === false) {
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;
}
}
}
调动验证手机短信验证码缓存方法
public function verification_code()
$mobile='18888888888';//需要验证的手机号
$code='100000';//收到的验证码
$this->checkRegSms($mobile,$code);
}