-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
101 lines (101 loc) · 2.63 KB
/
Copy pathapp.js
File metadata and controls
101 lines (101 loc) · 2.63 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//app.js
const http = require('./utils/http.js');
App({
onLaunch: function () {
let _this = this
if (wx.authorize) {
wx.authorize({
scope: 'scope.userInfo',
success: (res) => {
_this.getUserInfoAll();
},
fail: () => {
wx.showModal({
title: '提示',
confirmColor: '#E65454',
content: "授权失败,小程序部分功能将可能无法使用",
showCancel: false
})
}
})
} else {
wx.showModal({
title: '提示',
content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。'
})
}
wx.checkSession({
success: function () {
//登录态未过期
},
fail: function () {
//登录态过期
wx.getStorage({
key: 'c_Token',
success: function (res) {
_this.getUserInfoAll(res.data);
}
})
}
})
},
getUserInfoAll: function (token) {
let _this = this
wx.login({
success:(res) => {
console.log(res, 'app')
if (res.code) {
let loginCode = res.code
wx.getUserInfo({
withCredentials: true,
success: (res) => {
console.log(res,'app')
wx.setStorage({
key: "userInfo",
data: res.userInfo
})
let data = {
code: loginCode,
encryptedData: res.encryptedData,
iv: res.iv,
rawData: res.rawData
}
wx.request({
url: http.host + 'xcx/wxLogin',
data: data,
method: 'post',
success: function (res) {
console.log(res, 'app')
let resData = res.data;
if (resData.code === 0) {
wx.setStorage({
key: "c_Token",
data: resData.data.c_Token
})
} else {
wx.showModal({
title: '提示',
confirmColor: '#E65454',
content: JSON.stringify(resData.message),
showCancel: false
})
}
}
});
}
})
} else {
console.log('获取用户登录态失败!' + res.errMsg)
}
},
fail: (res)=> {
console.log(res)
}
})
},
userData: {
userInfo: {},
profile: null,
c_Token: ''
}
})