一、随机验证码
随机的码+当前时间(this.randoms = now + pwd;)
调用接口:let res = await captcha({ Captcha: this.randoms });
获取ID与生成的base64的图片
random() { let len = 6; var $chars = "ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678"; var maxPos = $chars.length; var pwd = ""; let i = 0; for (i = 0; i < len; i++) { pwd += $chars.charAt(Math.floor(Math.random() * maxPos)); } var now = new Date().getTime(); this.randoms = now + pwd; }, // yanzhengma async getcaptcha() { this.random(); let res = await captcha({ Captcha: this.randoms }); console.log(res,"res") this.verification = res.Data.Img; this.captchaid = res.Data.ID; },
二、短信验证
定时器的使用:
window.setInterval(fun,1000)
window.clearInterval
async sendcode() { if (this.editpaypwd.Phone == "") { this.$toast("手机号不能为空哦"); return false; } if (this.vfication == "") { this.$toast("图形验证码不能为空哦"); return false; } let _this = this; let res = await phone({ Phone: this.editpaypwd.Phone, Captcha: this.randoms, Value: this.vfication, ID: this.captchaid, Type: 1 }); if (res.Code == 1) { this.$toast("已发送,请注意查收!"); _this.sendMsgDisabled = true; let codeInterval = window.setInterval(function() { if (_this.codeTime-- <= 0) { _this.codeTime = 59; _this.sendMsgDisabled = false; window.clearInterval(codeInterval); } }, 1000); } else { this.getcaptcha(); this.$toast(res.Msg); } },