1111
This commit is contained in:
123
common/wxSilentLogin.js
Normal file
123
common/wxSilentLogin.js
Normal file
@@ -0,0 +1,123 @@
|
||||
// 静默登录
|
||||
import {
|
||||
isEmpty
|
||||
} from './TextUtils.js'
|
||||
|
||||
//引入bus
|
||||
import bus from '@/common/bus';
|
||||
|
||||
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)
|
||||
|
||||
bus.$emit('wholeSpin', 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
|
||||
Reference in New Issue
Block a user