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.
 
 
 
 
 
 

94 lines
2.4 KiB

// 静默登录
import {
isEmpty
} from './TextUtils.js'
const wxSilentLogin = () => {
return new Promise((resolve, reject) => {
wx.login({
success: function(res) {
if (res.code) {
if (getApp().globalData.isDebug) {
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(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.showToast({
title: "您的平台应用未被授权,请联系工作人员。",
icon: 'none',
duration: 3000,
})
wx.exitMiniProgram({
success: function() {},
fail: function() {}
})
return
}
if (res.data.code == 100) {
// 有账号 未绑定用户
uni.redirectTo({
url: '../index/BindPhone?sysUserWxAuthSid=' +
res.data.data
})
}
} else {
console.log("Http网络请求res", res)
console.log("Global-Auth-Token", res.data.data.token)
uni.setStorageSync("Global-Auth-Token", res.data.data.token)
getApp().globalData.username = res.data.data.userName
getApp().globalData.token = res.data.data.token
getApp().globalData.sid = res.data.data.sid
getApp().globalData.mobile = res.data.data.mobile
getApp().globalData.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