随机验证码和短信验证

一、随机验证码

随机的码+当前时间(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);
      }
    },

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值