|
|
|
@ -138,6 +138,7 @@ Page({ |
|
|
|
success: res => { |
|
|
|
// 可以将 res 发送给后台解码出 unionId
|
|
|
|
app.globalData.userInfo = res.userInfo |
|
|
|
|
|
|
|
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
|
|
|
|
// 所以此处加入 callback 以防止这种情况
|
|
|
|
if (app.userInfoReadyCallback) { |
|
|
|
@ -171,6 +172,8 @@ Page({ |
|
|
|
that.ohShitfadeOut(); |
|
|
|
return; |
|
|
|
} |
|
|
|
// 发送 res.code 到后台换取 openId, sessionKey, unionId
|
|
|
|
that.commitUserInfo(that.globalData.openid, res.encryptedData, res.iv); |
|
|
|
app.globalData.sessionId = data.response.sessionId; |
|
|
|
wx.setStorageSync('sessionId', data.response.sessionId); |
|
|
|
console.log('sessionId : ' + data.response.sessionId); |
|
|
|
@ -199,6 +202,41 @@ Page({ |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
commitUserInfo: function (openid, encryptedData, iv) { |
|
|
|
var that = this; |
|
|
|
wx.request({ |
|
|
|
url: this.gw.hostUrl + '/mall/wxa/auth/userinfo', |
|
|
|
method: 'POST', |
|
|
|
data: { |
|
|
|
openid: openid, |
|
|
|
encryptedData: encryptedData, |
|
|
|
iv: iv |
|
|
|
}, |
|
|
|
header: { |
|
|
|
'Content-Type': 'application/x-www-form-urlencoded', |
|
|
|
}, |
|
|
|
success: function (res) { |
|
|
|
//--init data
|
|
|
|
var data = res.data; |
|
|
|
var status = data.code; |
|
|
|
if (status != 0) { |
|
|
|
wx.showToast({ |
|
|
|
title: data.msg, |
|
|
|
icon: 'none', |
|
|
|
duration: 3000 |
|
|
|
}); |
|
|
|
return false; |
|
|
|
} |
|
|
|
}, |
|
|
|
fail: function (e) { |
|
|
|
wx.showToast({ |
|
|
|
title: '网络异常!err:authlogin', |
|
|
|
icon: 'none', |
|
|
|
duration: 2000 |
|
|
|
}); |
|
|
|
}, |
|
|
|
}); |
|
|
|
}, |
|
|
|
onLoad: function (options) { |
|
|
|
if (app.globalData.userInfo) { |
|
|
|
this.setData({ |
|
|
|
|