本章关于图片验证码过期时间验证需要注意的一个问题
...
// 检查验证码是否过期,重置流程
if (new Date().getTime() > this.captcha.expiredAt) { <= 这里是获取手机当前的时间进行对比
wepy.showToast({
title: '验证码已过期',
icon: 'none',
duration: 2000
})
this.resetRegister()
return false
}
...
// 记录 key 和 过期时间
if (codeResponse.statusCode === 201) {
this.verificationCode = {
key: codeResponse.data.key,
expiredAt: Date.parse(codeResponse.data.expired_at) <= 这里保存的是服务器返回的绝对过期时间(2019-01-03 12:12:12)
}
// 关闭modal
this.captchaModalHidden = true
// 手机输入框 disabled
this.phoneDisabled = true
// 清空报错信息
this.errors = {}
this.$apply()
}
...
注意上面箭头指向的两行代码,考虑下面两种情况:
- 有些用户会故意把手机时间往前调整几分钟(可能是为了不要迟到之类的)
- 有些人在国外访问项目
他们的验证码永远是过期的
推荐文章: