E企盈营销工具技术服务商 热线:4006-838-530

微信小程序发送验证码

E企盈直播平台营销卖货系统

记录一下,小程序发送验证码的小案例。废话不多说,直接撸代码。。。1、效果图如下wxml:view class=’header’input type=’number’ placeholder=’请输入手机号’ bindinput=’mInput’/input/viewview class=’nav’view class=’nav_left’input type=’text’ placeholder=’短信验证码’ bindinput=’vInput’/input/viewbutton disabled='{{disabled}}’ class=’nav_btn’ bindtap=’getVCode'{{time}}/button/viewview class=’footer’ bindtap=’bd’绑定/viewjs:var interval = null //倒计时函数const app = getApp();Page({data: {time: ‘获取验证码’, //倒计时currentTime: 61,disabled: false, //可点击mobile: “”,yzm: “”},mInput: function(e) {this.setData({mobile: e.detail.value})},vInput:function(e){this.setData({yzm: e.detail.value})},//获取验证码,倒计时getCode: function(mobile) {var that = this;var params = {sms_type: 1,mobile: mobile};wx.request({url: app.globalData.u + “/send_verification_code.do”,data: params,method: “get”,header: {“content-type”: “application/json”},dataType: “json”,success: function success(res) {if (res.data.result_code == “0”) {wx.showToast({title: ‘验证码发送成功’})//倒计时var currentTime = that.data.currentTimeinterval = setInterval(function() {currentTime–;that.setData({time: currentTime + ‘ 秒’})if (currentTime = 0) {clearInterval(interval)that.setData({time: ‘重新获取’,currentTime: 61,disabled: false})}}, 1000)} else {wx.showModal({title: “”,content: res.data.err_msg });that.setData({time:’获取验证码’,disabled:false})}},fail: function fail(res) {wx.showModal({content: res});}},getVCode() {//校验手机号let mobile = this.data.mobilevar regMobile = /^1[3456789]d{9}$/;if (!regMobile.test(mobile)) {wx.showModal({title: ”,content: ‘手机格式错误’,})return;}this.getCode(mobile);this.setData({disabled: true})},//绑定bd: function() {let mobile = this.data.mobilelet yzm = this.data.yzm//校验手机号、验证码var regMobile = /^1[3456789]d{9}$/;if (!regMobile.test(mobile)) {wx.showModal({title: ”,content: ‘手机格式错误’,})return;}if (yzm == ”) {wx.showModal({title: ”,content: ‘验证码不能为空’,})return;}this.updateUserMobile(mobile,yzm);},updateUserMobile: function (mobile, verifiy_code) {var params = {user_id: app.globalData.userInfo.user_id,mobile: mobile,verifiy_code: verifiy_code};// console.log(params)wx.request({url: app.globalData.u + ‘update_user_mobile.do’,data: params,method: ‘post’,header: {‘content-type’: ‘application/x-www-form-urlencoded’},dataType: ‘json’,success: function success(res) {console.log(res)if (res.data.result_code == ‘0’) {// wx.showToast({// title: ‘绑定成功’,// icon: ‘success’,// duration: 1000// })setTimeout(function(){wx.redirectTo({url: ‘ziliao’,})},1500)} else {wx.showModal({title: ”,content: res.data.err_msg});}},fail: function fail(res) {wx.showModal({content: ‘服务器发生异常,请稍后再试’});},});}})

赞(0) 打赏
未经允许不得转载:E企盈小程序开发-热线:4006-838-530 » 微信小程序发送验证码
分享到: 更多 (0)
E企盈小程序直播营销卖货系统
E企盈直播平台营销卖货系统

评论 抢沙发

E企盈小程序开发

联系我们联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏