微信小程序的授权登录,直接上代码~
<button open-type="getUserInfo" bindgetuserinfo="bindGetUserInfo"> 微信用户一键登录 </button>
bindGetUserInfo() {
wx.showLoading({
title: '正在加载中...',
mask: true
})
let _that = this
wx.getUserInfo({
success: function (res) {
let signature = res.signature
let rawData = res.rawData
wx.login({
success: (res) => {
wx.request({
url: '请求的地址',
data: {
code: res.code,
rawData: rawData,
signature: signature,
},
method: "POST",
//注意这里 post方法 是 application/x-www-form-urlencoded
// get方法 是 application/json
header: {
'content-type': 'application/x-www-form-urlencoded'
},
success: function (res) {
// console.log(res)
wx.hideLoading()
if (res.data.code == 0) {
//获取数据
} else {
wx.showToast({
title: res.data.msg,
icon: 'none'
})
}
}
})
}
})
}
})
},