wx.login({
success: res => {
// 发送 res.code 到后台换取 openId, sessionKey, unionId
if(res.code){ //code存在
wx.getUserInfo({
success: function(resp) {
// console.log(resp)
wx.request({
url: 'http://192.168.40.22:88/applet/user/auth',
data: {
wid: res.code
},
method:"POST",
header: {
'content-type': 'application/json' // 默认值
},
success(resp){
console.log(resp) //POST http://192.168.40.22:88/applet/user/auth 401 (Unauthorized)
}
})
}
})
}
}
})
看错了,请求接口要这些参数
https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/login/auth.code2Session.html