wx.login({
success: res => {
// 发送 res.code 到后台换取 openId, sessionKey, unionId
if(res.code){
wx.request({
url: ‘接口url‘, //仅为示例,并非真实的接口地址
method: "GET",
data: {
"code":res.code
},
header: {
‘content-type‘: ‘application/json‘ // 默认值
},
success: function (res) {
if (res.data.openid){
wx.setStorage({
key:"tokenId",
data:res.data.openid,
})
}
}
})
}
}
})
原文地址:https://www.cnblogs.com/mk12/p/11242100.html
时间: 2024-11-14 10:24:51