原创声明:本文为作者原创,未经允许不得转载,经授权转载需注明作者和出处
// 登录
wx.login({
success: res => {
// 发送 res.code 到后台换取 openId, sessionKey, unionId
if (res.code) {
console.log(“res.code=”+res.code)
console.log(“app.js->wx.login”)
//发起网络请求
wx.request({
url: ‘https://api.wxappclub.com/wxLogin‘,
data: {
appkey: ‘b34t9gg2jjlatb8t4c2a2kxeec71lmxt’,
code: res.code
},
header: {
‘content-type’: ‘application/json’
},
// timeout: 5000,
success: res => {
console.log(“wx.login->request->success”);
var sessionId = res.data.result;
console.log(sessionId);
},
fail: res => {
console.log(“wx.login->request->fail”);
console.log(res);
},
complete: res => {
console.log(“wx.login->request->complete”);
}
})
} else {
console.log('登录失败!' + res.errMsg)
}
}
})