怎么给短信验证码设置失效时间呢?除了session,请各位大神给点建议
1、数据库存发短信的相关信息 手机号 验证码 入库时间 等等 根据入库时间去判断是否过期 或者直接入库一个过期时间
2、缓存 缓存应该是比较方便的 发送时直接存个过期时间 验证的时候取出来一对比 不用查库 至于用什么缓存redis还是什么都可以 根据自身情况而定
这里使用的是TP5框架 代码参考一下
/**
* 发送验证码
*/
public function sendSmsCode() {
// 获取手机号
$phone = input ('phone',0);
// DO:判断手机号是否注册 调用验证器
$count = \app\common\model\Users::where(['phone'=>$phone])->count ();
if ($count > 0 ) return json (['code' => 200, 'msg' => '手机号已存在', 'data' => json([])]);
// 判断是否有验证码 处在 60秒内有效期
if (Cache::has ('reg_sms_code:'.$phone)) {
$old_cache_data = cache ('reg_sms_code:'.$phone);
$last_time = $old_cache_data['send_time'];
if ($last_time + 60 > time ()) {
return json (['code' => 200, 'msg' => '请等60秒后,再次发送验证码', 'data' => json([])]);
}
}
// 正则匹配长度
$preg_str = "/^1\d{10}$/";
$str = preg_match($preg_str, $phone);
//判断是否正则通过
if ($str == 0) {
return json(['code' => 200, 'msg' => '手机号码格式错误 :' . $phone, 'data' => json([])]);
}
// 将验证码记录入缓存
$code = mt_rand (100000,999999);
$expire_time = time () + 300;
$cache_data = [
'phone' => $phone,
'code' => $code,
'expire_time' =>$expire_time, #过期时间
'send_time' => time () #发送时间
];
// DO:发送验证码
Loader::import('alisms\Alisms', EXTEND_PATH);
AliSms::sendSms($phone,$code);
// 将验证码信息加入缓存
cache ('reg_sms_code:'.$phone,$cache_data,300);
return json (['code' => 200, 'msg' => '验证码发送成功','data' => json([])]);
}
在生成验证码的时候不是会往数据库插一条记录吗,同时会记录时间,在验证验证码的时候判断当前手机,验证码的这条记录的时间是否过期就可以了,使用 mysql ,redis 都可以
An RPL Report needs to be submitted by IT professionals who want to migrate to Australia but do not have a degree or diploma which is considered equivalent to an Australian degree or diploma in the related areas by the authority.
Thanks, great post. I really like your point of view. My name is Ellias Brown. If you need best solution regarding Hp Printer Support related problems issues then visit my site .HP Printer Support Number 1-888-902-8333 is your one-stop solution for printer related problems.
https://www.hpprintersupportp...
https://www.hpprintersupportp...
https://www.hpprintersupportp...
https://www.hpprintersupportp...
Recognition of Prior Learning (RPL) is nothing but the assessment of skills of the candidates who are willing to migrate to Australia. The candidates from other countries should have necessary skills and knowledge before they can migrate to Australia. Australian Computer Society (ACS) is an association that assesses the candidates based on their skills and knowledge. It is for the Information and Communications Technology (ICT) professionals and has around 22,000 members all over Australia. The professionals from other countries, with no ICT qualifications or insufficient ICT, have to showcase their skills and knowledge to the ACS for Australia Skilled Migration. This is the reason the candidates without any ICT qualifications are required to submit rpl australia report form for skill assessment.
Students aiming for a career in programming and computer language are often increasingly attracted to the opportunities offered by the reputed universities located in the United Kingdom. But studying in such distinguished institutions always presents with some hurdles, i.e., complex and elaborate assignments. For many out there, preparing these complex assignments requires endless struggles, and it almost seems like waging war. But with our computer programming help services, all your assignment woes would be a thing of the past.
Geek Squad Online Support gives services in-store and over the Internet through remote access and gives all day and on location support. For any tech help dial our toll-free number.
Confused about how to do an assignment? For any law assignment help, get in touch with the best assignment writing service in Australia. Here, you will find an optimum-quality solution for all your assignment needs. Enroll now!
enjoyed reading the article above , really explains everything in detail,the article is very interesting and effective.Thank you and good luck for the upcoming articles . Will be sharing this with my tribe too.
dissertation proposal template
accounting dissertation
I have got the improper HP printer setup issue and this blog seems to be very suitable for my requirement. Thank you for the wonderful content to resolve my issues. You may visit allitexpert.com too for any kind of additional information regarding printer problems.
HP Printer Phone Support Number
HP Printer Support Phone Number
HP Printer Support Number
HP Printer tech Support Number
HP Printer technical Support Number
HP Printer customer Support Number
HP Printer Offline Support Number
GotoAssignmentHelp.com is leading plagiarism free assignment writing help in Australia. We provide customized assignment help service. We are leading the market for more than a decade now and have acquired the name of being the best academic help service for our comprehensive services at pocket-friendly rates.
online conflict management assignment help
write project management assignment
supply chain management assignment help
project management assignment helponline
strategy management assignment help online
assignment on porter's five forces model
history assignment help online
sociology assignment help</a
Our GotoAssignmentHelp Best Assignment Help Website for Quality Assignment Writing Help. Take advantage of a pocket-friendly assignment writing company service. Visit us now and book an order.
online assignment help australia
assignment writing help usa
assignment writing help uk
online assignment help canada
assignment help services in melbourne
yes ! it is so cool ,l think you can do much. l am KNTECH. WE have the ip pbx system ,paging system ,setup a voip phone and industrial intercom system, we also design the voip intercom ,emergency telephone and waterproof box.
4 回答13.5k 阅读✓ 已解决
5 回答7.9k 阅读✓ 已解决
2 回答1.1k 阅读✓ 已解决
3 回答504 阅读✓ 已解决
1 回答1k 阅读✓ 已解决
1 回答1.5k 阅读
1 回答514 阅读✓ 已解决
1.生成验证码
2.让验证码结合时间的概念,比如