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.
73 lines
1.7 KiB
73 lines
1.7 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,
|
|
// 请求方式 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) {
|
|
return
|
|
}
|
|
else
|
|
{
|
|
uni.setStorageSync("sysUserSid", res.data.data.sysUserSid);
|
|
uni.setStorageSync("token", res.data.data.token);
|
|
uni.setStorageSync("isLogin", res.data.data.isLogin);
|
|
|
|
getApp().globalData.isLogin = res.data.data.isLogin
|
|
getApp().globalData.sysUserSid = res.data.data.sysUserSid
|
|
resolve(res.data.data.sysUserSid)
|
|
}
|
|
}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
|
|
|