You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
115 lines
3.1 KiB
115 lines
3.1 KiB
|
|
const wxSilentLogin = () => {
|
|
return new Promise((resolve, reject) => {
|
|
wx.login({
|
|
success: function(res) {
|
|
if (res.code) {
|
|
console.log('Http网络请求信息', {
|
|
"wxCode": res.code
|
|
})
|
|
uni.request({
|
|
// 组装请求地址
|
|
url: getApp().globalData.wxSilentLoginURL + "?wxCode=" + res
|
|
.code,
|
|
// 请求方式 GET POST
|
|
method: "GET",
|
|
header: {
|
|
// 传参方式
|
|
'content-type': "application/x-www-form-urlencoded"
|
|
},
|
|
// 具体参数
|
|
data: {
|
|
"wxCode": res.code
|
|
},
|
|
success: res => {
|
|
console.log("请求openid", res)
|
|
// if (getApp().globalData.isDebug) {
|
|
// console.log('Http网络路径', getApp().globalData
|
|
// .wxSilentLoginURL)
|
|
// }
|
|
if (res.statusCode == 200) {
|
|
if (!res.data.success) {
|
|
|
|
// if (res.data.code == 500) {
|
|
// uni.showModal({
|
|
// title: '温馨提示',
|
|
// content: '您的平台应用未被授权,请联系工作人员。',
|
|
// showCancel: false,
|
|
// success: function(res) {
|
|
// if (res.confirm) {
|
|
// wx.exitMiniProgram({
|
|
// success: function() {},
|
|
// fail: function() {}
|
|
// })
|
|
// } else {
|
|
// console.log('点击了取消')
|
|
// }
|
|
// }
|
|
// })
|
|
|
|
|
|
// return
|
|
// }
|
|
|
|
// if (res.data.code == 100) {
|
|
// 未绑定用户
|
|
uni.navigateTo({
|
|
url: '../index/BindPhone?openid=' +
|
|
res.data.data.openid+"&unionid="+
|
|
res.data.data.unionid
|
|
})
|
|
// }
|
|
|
|
} else {
|
|
|
|
console.log("Http网络请求res", res)
|
|
console.log("Global-Auth-Token", res.data.data
|
|
.token)
|
|
|
|
|
|
getApp().globalData.username = res.data.data
|
|
.name
|
|
getApp().globalData.token = res.data.data.token
|
|
getApp().globalData.sid = res.data.data.sid
|
|
getApp().globalData.mobile = res.data.data
|
|
.mobile
|
|
|
|
getApp().globalData.isAdmin = res.data.data.isAdmin
|
|
getApp().globalData.orgSidPath = res.data.data.orgSidPath
|
|
getApp().globalData.orgNamePath = res.data.data.orgNamePath
|
|
getApp().globalData.organizationSid = res.data.data.organizationSid
|
|
getApp().globalData.headImage = res.data.data.headImage
|
|
|
|
getApp().globalData.isLogin = true
|
|
|
|
uni.setStorageSync("Global-Auth-Token", res.data
|
|
.data.token)
|
|
uni.setStorageSync("sid", res.data.data.sid)
|
|
uni.setStorageSync("isLogin", true)
|
|
|
|
}
|
|
} else {
|
|
getApp().globalData.isLogin = false
|
|
}
|
|
},
|
|
fail: (err) => {
|
|
if (getApp().globalData.isDebug) {
|
|
console.log("Http网络请求fail", err)
|
|
}
|
|
},
|
|
complete: () => {}
|
|
});
|
|
}
|
|
},
|
|
fail: function(res) {
|
|
uni.showToast({
|
|
title: "静默登录失败:" + res.errMsg,
|
|
icon: 'none'
|
|
})
|
|
|
|
reject(res.errMsg)
|
|
}
|
|
});
|
|
})
|
|
}
|
|
export default wxSilentLogin
|