1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
| var that = this
if (wx.getStorageSync('sessionid') != "") {
wx.request({
url: 'https://pangzi.jcdfkj.cn/app/index.php?i=4&c=entry&do=expire&m=weisrc_dish001&a=wxapp',
data: {
sessionid: wx.getStorageSync('sessionid')
},
success: function (res) {
if (res.data.data.msg == 1) {
console.log('登录中,账号未过期')
} else {
wx.login({
success: function (res) {
if (res.code) {
//发起网络请求
wx.request({
url: 'https://pangzi.jcdfkj.cn/app/index.php?i=4&c=entry&do=login&m=weisrc_dish001&a=wxapp',
data: {
code: res.code,
},
header: {
'content-type': 'application/json' // 默认值
},
success: function (res) {
console.log(res.data.data)
console.log(res.data.data.openid)
wx.setStorageSync('openid', res.data.data.openid)
wx.setStorageSync('sessionid', res.data.data.sessionid)
if (res.data.data.userinfo == 'need') {
wx.request({
url: 'https://pangzi.jcdfkj.cn/app/index.php?i=4&c=entry&do=upuser&m=weisrc_dish001&a=wxapp',
data: {
},
success: function (res) {
}
})
}
}
})
} else {
console.log('获取用户登录态失败!' + res.errMsg)
}
}
});
}
}
})
} else {
wx.login({
success: function (res) {
console.log(res)
if (res.code) {
//发起网络请求
wx.request({
url: 'https://pangzi.jcdfkj.cn/app/index.php?i=4&c=entry&do=login&m=weisrc_dish001&a=wxapp',
data: {
code: res.code,
},
success: function (res) {
console.log(res)
wx.setStorageSync('sessionid', res.data.data.sessionid)
wx.setStorageSync('openid', res.data.data.openid)
if (res.data.data.userinfo == 'need') {
console.log(that.globalData.userInfo.nickName)
console.log(that.globalData.userInfo.avatarUrl)
wx.request({
url: 'https://pangzi.jcdfkj.cn/app/index.php?i=4&c=entry&do=upuser&m=weisrc_dish001&a=wxapp',
data: {
sessionid: wx.getStorageSync('sessionid'),
nickname: that.globalData.userInfo.nickName,
avatar: that.globalData.userInfo.avatarUrl
},
success: function (res) {
}
})
}
}
})
} else {
console.log('获取用户登录态失败!' + res.errMsg)
}
}
});
} |