這篇文章給大家分享的是有關(guān)小程序獲取手機(jī)驗證碼的方法的內(nèi)容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。
網(wǎng)站制作、網(wǎng)站建設(shè),成都做網(wǎng)站公司-成都創(chuàng)新互聯(lián)公司已向近1000家企業(yè)提供了,網(wǎng)站設(shè)計,網(wǎng)站制作,網(wǎng)絡(luò)營銷等服務(wù)!設(shè)計與技術(shù)結(jié)合,多年網(wǎng)站推廣經(jīng)驗,合理的價格為您打造企業(yè)品質(zhì)網(wǎng)站。
一種比較常見的功能獲取手機(jī)驗證碼,具體內(nèi)容如下
先看效果圖:

其實這個功能實現(xiàn)起來很簡單,主要就是調(diào)取第三方接口,拿到返回值驗證的問題
直接上代碼吧:
<view class='changeInfo'>
<view class='changeInfoName'>
<input placeholder='請輸入姓名' bindinput='getNameValue' value='{{name}}'/>
</view>
<view class='changeInfoName'>
<input placeholder='請輸入手機(jī)號' bindinput='getPhoneValue' value='{{phone}}'/>
</view>
<view class='changeInfoName'>
<input placeholder='請輸驗證碼' bindinput='getCodeValue' value='{[code]}' style='width:70%;'/>
<button class='codeBtn' bindtap='getVerificationCode' disabled='{{disabled}}' >{{codename}}</button>
</view>
<button class='changeBtn' bindtap='save'>保存</button>
</view>CSS:
page{
height: 100%;
width: 100%;
background: linear-gradient(#5681d7, #486ec3);
}
.changeInfo{
display: flex;
flex-direction: column;
justify-content: space-between;
width: 90%;
margin: 50rpx auto;
}
.changeInfoName{
position: relative;
height: 80rpx;
width: 100%;
border-radius: 10rpx;
background: #fff;
margin-bottom: 20rpx;
padding-left: 20rpx;
box-sizing: border-box;
}
.codeBtn{
position: absolute;
right: 0;
top: 0;
color: #bbb;
width: 30%;
font-size: 26rpx;
height: 80rpx;
line-height: 80rpx;
}
.changeInfoName input{
width: 100%;
height:100%;
}
.changeBtn{
width: 40%;
height: 100rpx;
background: #fff;
color: #000;
border-radius: 50rpx;
position: absolute;
bottom: 10%;
left: 50%;
margin-left: -20%;
line-height: 100rpx;
}js:
var app = require('../../resource/js/util.js');
Page({
/**
* 頁面的初始數(shù)據(jù)
*/
data: {
name:'',//姓名
phone:'',//手機(jī)號
code:'',//驗證碼
iscode:null,//用于存放驗證碼接口里獲取到的code
codename:'獲取驗證碼'
},
//獲取input輸入框的值
getNameValue:function(e){
this.setData({
name:e.detail.value
})
},
getPhoneValue:function(e){
this.setData({
phone:e.detail.value
})
},
getCodeValue: function (e) {
this.setData({
code: e.detail.value
})
},
getCode:function(){
var a = this.data.phone;
var _this = this;
var myreg = /^(14[0-9]|13[0-9]|15[0-9]|17[0-9]|18[0-9])\d{8}$$/;
if (this.data.phone == "") {
wx.showToast({
title: '手機(jī)號不能為空',
icon: 'none',
duration: 1000
})
return false;
} else if (!myreg.test(this.data.phone)) {
wx.showToast({
title: '請輸入正確的手機(jī)號',
icon: 'none',
duration: 1000
})
return false;
}else{
wx.request({
data: {},
'url': 接口地址,
success(res) {
console.log(res.data.data)
_this.setData({
iscode: res.data.data
})
var num = 61;
var timer = setInterval(function () {
num--;
if (num <= 0) {
clearInterval(timer);
_this.setData({
codename: '重新發(fā)送',
disabled: false
})
} else {
_this.setData({
codename: num + "s"
})
}
}, 1000)
}
})
}
},
//獲取驗證碼
getVerificationCode() {
this.getCode();
var _this = this
_this.setData({
disabled: true
})
},
//提交表單信息
save:function(){
var myreg = /^(14[0-9]|13[0-9]|15[0-9]|17[0-9]|18[0-9])\d{8}$$/;
if(this.data.name == ""){
wx.showToast({
title: '姓名不能為空',
icon: 'none',
duration: 1000
})
return false;
}
if(this.data.phone == ""){
wx.showToast({
title: '手機(jī)號不能為空',
icon: 'none',
duration: 1000
})
return false;
}else if(!myreg.test(this.data.phone)){
wx.showToast({
title: '請輸入正確的手機(jī)號',
icon: 'none',
duration: 1000
})
return false;
}
if(this.data.code == ""){
wx.showToast({
title: '驗證碼不能為空',
icon: 'none',
duration: 1000
})
return false;
}else if(this.data.code != this.data.iscode){
wx.showToast({
title: '驗證碼錯誤',
icon: 'none',
duration: 1000
})
return false;
}else{
wx.setStorageSync('name', this.data.name);
wx.setStorageSync('phone', this.data.phone);
wx.redirectTo({
url: '../add/add',
})
}
},
/**
* 生命周期函數(shù)--監(jiān)聽頁面加載
*/
onLoad: function (options) {
},
/**
* 生命周期函數(shù)--監(jiān)聽頁面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函數(shù)--監(jiān)聽頁面顯示
*/
onShow: function () {
},
/**
* 生命周期函數(shù)--監(jiān)聽頁面隱藏
*/
onHide: function () {
},
/**
* 生命周期函數(shù)--監(jiān)聽頁面卸載
*/
onUnload: function () {
},
/**
* 頁面相關(guān)事件處理函數(shù)--監(jiān)聽用戶下拉動作
*/
onPullDownRefresh: function () {
},
/**
* 頁面上拉觸底事件的處理函數(shù)
*/
onReachBottom: function () {
},
/**
* 用戶點擊右上角分享
*/
onShareAppMessage: function () {
}
})感謝各位的閱讀!關(guān)于“小程序獲取手機(jī)驗證碼的方法”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,讓大家可以學(xué)到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!
新聞名稱:小程序獲取手機(jī)驗證碼的方法
URL地址:http://chinadenli.net/article26/jigijg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站建設(shè)、移動網(wǎng)站建設(shè)、做網(wǎng)站、建站公司、電子商務(wù)、品牌網(wǎng)站設(shè)計
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)