第一步:
```const crypto = require('crypto');
```js
第二步:获取需要校验的sign 和time
注释:将获取验证码的成功后的time和sign 作为校验密码是否正确;
//获取验证码
getSmsCode() {
if (!!this.form.phone) {
sendSmsCode(this.form.phone).then((res) => {
this.isCodeStr = true;
this.returnParam = res.data; // 获取验证码后的获取其返回值的time和sign的值
this.countDown();
this.$modal.msgSuccess(res.msg);
}).catch((err) => {
this.$modal.msgError('发送失败');
});
} else if (this.phoneNo.length < 11) {
this.$modal.msgError("请输入正确的手机号");
} else {
this.$modal.msgError("请输入手机号");
}
},
第三步: 将电话,time 和验证码 通过crypto 的方法 进行校验;
//获取验证码
verificaCode(){
const hash = crypto.createHash('md5');
hash.update(`${this.form.phone}.${this.returnParam.time}.${this.verificationCode}1uzwtilrf70mvsh7`);
if (hash.digest('hex') != this.returnParam.sign) {
this.$modal.msgError('验证码错误,请重新发送');
// this.isCodeStr = false;
}else{
this.isCodeStr = false;
this.$modal.msgSuccess('验证码正确');
}
},