- 当前 Bug 的表现(可附上截图)
- 预期表现
想要不报错,正确的获取openid
- 复现路径
无
- 提供一个最简复现 Demo
App({
onLaunch: function() {
//获取access_token
wx.request({
url: ‘http://api.wss.onlyjune.com/accessToken?client_id=20882088&secret=nGk5R2wrnZqQ02bed29rjzax1QWRIu1O’,
data: {},
method: ‘post’,
header: {
‘Content-Type’: ‘application/json’
},
success: function(res) {
// console.log(res.data)
console.log(res.data.access_token)
wx.login({
success: function(res) {
console.log(res.code)
//发送请求
wx.request({
url: ‘http://api.wss.onlyjune.com/login/getWxOpenid.html’,
data: {
access_token: res.data.access_token,
code: res.code
},
header: {
‘content-type’: ‘application/json’ //默认值
},
success: function(res) {
var that = this;
console.log(res.data)
}
})
}
})
// console.log(res.data)
wx.setStorage({
key: ‘access_token’,
data: {
access_token: res.data.access_token,
expires: Date.parse(new Date()) + res.data.expires,
},
success: function(res) {},
})
},
fail: function() {
}
})
},
globalData: {
userInfo: null
}
})