国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 熱點(diǎn) > 微信 > 正文

微信小程序發(fā)送短信驗(yàn)證碼完整實(shí)例

2024-07-22 01:19:15
字體:
供稿:網(wǎng)友

微信小程序注冊(cè)完整實(shí)例,發(fā)送短信驗(yàn)證碼,帶60秒倒計(jì)時(shí)功能,無需服務(wù)器端。效果圖:

代碼:

index.wxml

<!--index.wxml--><view class="container"> <view class='row'>   <input placeholder='請(qǐng)輸入姓名' bindinput='bindNameInput'/>  </view>  <view class='row'>   <input placeholder='請(qǐng)輸入手機(jī)號(hào)' bindinput='bindPhoneInput'/>  </view> <view class='row'>   <input placeholder='請(qǐng)輸驗(yàn)證碼' bindinput='bindCodeInput' style='width:70%;'/>    <button class='codeBtn' bindtap='getCode' hidden='{{hidden}}' disabled='{{btnDisabled}}'>{{btnValue}}</button> </view> <view>   <button class='save' bindtap='save' >保存</button> </view> </view>

index.js

//index.jsvar zhenzisms = require('../../utils/zhenzisms.js');//獲取應(yīng)用實(shí)例const app = getApp(); Page({ data: {  hidden: true,  btnValue:'',  btnDisabled:false,  name: '',  phone: '',  code: '',  second: 60 }, onLoad: function () {   }, //姓名輸入 bindNameInput(e) {  this.setData({   name: e.detail.value  }) }, //手機(jī)號(hào)輸入 bindPhoneInput(e) {  console.log(e.detail.value);  var val = e.detail.value;  this.setData({   phone: val  })  if(val != ''){   this.setData({    hidden: false,    btnValue: '獲取驗(yàn)證碼'   })  }else{   this.setData({    hidden: true   })  } }, //驗(yàn)證碼輸入 bindCodeInput(e) {  this.setData({   code: e.detail.value  }) }, //獲取短信驗(yàn)證碼 getCode(e) {  console.log('獲取驗(yàn)證碼');  var that = this;  zhenzisms.client.init('https://sms_developer.zhenzikj.com', 'appId', 'appSecret');  zhenzisms.client.send(function (res) {   if(res.data.code == 0){    that.timer();    return ;   }   wx.showToast({    title: res.data.data,    icon: 'none',    duration: 2000   })  }, '15801636347', '驗(yàn)證碼為:3322');   }, timer: function () {  let promise = new Promise((resolve, reject) => {   let setTimer = setInterval(    () => {     var second = this.data.second - 1;     this.setData({      second: second,      btnValue: second+'秒',      btnDisabled: true     })     if (this.data.second <= 0) {      this.setData({       second: 60,       btnValue: '獲取驗(yàn)證碼',       btnDisabled: false      })      resolve(setTimer)     }    }    , 1000)  })  promise.then((setTimer) => {   clearInterval(setTimer)  }) }, //保存 save(e) {  console.log('姓名: ' + this.data.name);  console.log('手機(jī)號(hào): ' + this.data.phone);  console.log('驗(yàn)證碼: ' + this.data.code);    //省略提交過程 }})

index.wxss

/**index.wxss**/page{ height: 100%; width: 100%; background: linear-gradient(#5681d7, #486ec3); display: flex; flex-direction: column;}.container{ display: flex; flex-direction: column; justify-content: space-around; width: 90%; margin: 50rpx auto;} .row{ position: relative; height: 80rpx; width: 100%; border-radius: 10rpx; background: #fff; margin-bottom: 20rpx; padding-left: 20rpx; box-sizing: border-box;}.row input{ width: 100%; height:100%;}.codeBtn{ position: absolute; right: 0; top: 0; color: #bbb; width: 30%; font-size: 26rpx; height: 80rpx; line-height: 80rpx;}.subBtn{ width: 200rpx; height: 80rpx; background: #fff; color: #000; border-radius: 50rpx; line-height: 80rpx;}            
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 乐平市| 凤山市| 宿州市| 重庆市| 彝良县| 平潭县| 朔州市| 赫章县| 红原县| 正阳县| 牙克石市| 彰化县| 六枝特区| 东安县| 荔浦县| 八宿县| 东莞市| 徐闻县| 钦州市| 龙门县| 临海市| 嘉义市| 湄潭县| 长白| 同德县| 民县| 大足县| 琼结县| 云浮市| 贺州市| 洪泽县| 贞丰县| 天等县| 博白县| 兴文县| 长汀县| 龙南县| 赤水市| 龙江县| 靖宇县| 阿拉善盟|