- 当前 Bug 的表现(可附上截图)APP和小程序一起写的,APP登录成功了,说明后台没有问题。我已经写了获取验证码了,但是登录的时候还是总是提醒请获取验证码,写了死数据传也是这样。是我两个缓存的调取的原因吗?
- 预期表现
可以登录
- 复现路径
- 提供一个最简复现 Demo
var interval = null //倒计时函数
Page({
data: {
time: ‘获取验证码’, //倒计时
currentTime: 61,
access_token: “”,
expires: “”,
code: “”,
openid: “”,
sns_type: “”,
mobile: “”
},
onLoad: function (options) {
var that = this;
wx.getSystemInfo({
success(res) {
// console.log(res.model)
that.setData({
sns_type: res.model
})
}
})
},
passNameInput: function (e) {
this.setData({
mobile: e.detail.value
})
},
//获取验证码
getVerificationCode: function (e) {
var mobile = this.data.mobile
// console.log(mobile)
//读取access_token本地缓存
wx.getStorage({
key: ‘access_token’,
success: function (res) {
// console.log(res.data)
if (Date.parse(new Date()) + 2000 < res.data.expires) {
if (mobile == ‘’) {
wx.showToast({
title: ‘请输入手机号’,
icon: ‘none’
})
} else {
//获取验证码
wx.request({
url: ‘http://api.wss.onlyjune.com/login/sendCode.html’,
data: {
access_token: res.data.access_token,
mobile: mobile,
type: “2”
},
method: ‘post’,
header: {
‘Content-Type’: ‘application/json’
},
success: function (res) {
console.log(res.data)
wx.showToast({
title: ‘验证码为:1111’,
icon: ‘none’
})
},
fail: function () { }
})
}
} else {
console.log(‘access_token已过期请重新获取’);
}
},
})
},
//手机号验证码登录
formSubmit: function (e) {
var sns_type = this.data.sns_type
// console.log(sns_type)
//读取access_token本地缓存
wx.getStorage({
key: ‘access_token’,
success: function (res) {
// console.log(res.data)
if (Date.parse(new Date()) + 2000 < res.data.expires) {
// if (e.detail.value.mobile == ‘’) {
// wx.showToast({
// title: ‘请输入手机号’,
// icon: ‘none’
// })
// } else if (e.detail.value.code == ‘’) {
// wx.showToast({
// title: ‘请获取验证码’,
// icon: ‘none’
// })
// } else {
//读取openid本地缓存
wx.getStorage({
key: ‘openid’,
success: function (b) {
console.log(b.data.openid)
console.log(sns_type)
console.log(e.detail.value.code)
console.log(e.detail.value.mobile)
console.log(res.data.access_token)
//登录
wx.request({
url: ‘http://api.wss.onlyjune.com/login/codeLogin.html’,
data: {
access_token: res.data.access_token,
mobile: 18761336470,
code: 1111,
sns_type: ‘weixin’,
open_id: ‘fl’
},
method: ‘post’,
header: {
‘Content-Type’: ‘application/json’
},
success: function (res) {
console.log(res.data)
// wx.switchTab({
// url: ‘…/pages/index/index’,
// })
},
fail: function () { }
})
},
})
// }
} else {
console.log(‘access_token已过期请重新获取’);
}
},
})
}
})