app.js
2.69 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
App({
url: 'https://stg.natureresearch.cn',
onLaunch: function () {
this.getUserInfo()
},
getUserInfo: function (cb) {
if (this.globalData.userInfo) {
typeof cb == "function" && cb(this.globalData.userInfo)
} else {
//调用登录接口
wx.login({
success: function (res) {
if (res.code) {
//获取用户信息
wx.getUserInfo({
success: function (infores) {
console.info('iv', infores.iv);
console.info('encryptedData', infores.encryptedData);
typeof cb == "function" && cb(that.globalData.userInfo);
//插入修改会员表返回openid
wx.request({
url: 'https://stg.natureresearch.cn/mpapi/1.0.0/user/login',
method: 'POST',
header: {
'content-type': 'application/json',
'x-wx-encrypted-data': infores.encryptedData,
'x-wx-iv': infores.iv,
'x-wx-code': res.code
},
success: function (inforesres) {
console.info('返回-skey', inforesres.data.data);
wx.setStorage({
key: "key",
data: inforesres.data.data.skey
})
console.info('WO去登录了e获得skey', inforesres.data.data.skey)
wx.setStorage({
key: "timexx",
data: new Date
})
wx.setStorage({
key: "user",
data: inforesres.data.data.wxUserinfo
})
wx.setStorage({
key: "information",
data: inforesres.data.data.userProfile
})
var data = inforesres.data;
console.info('打印状态403需重新登陆', inforesres.statusCode);
if (data.error == 0) {
//wx.setStorageSync('openId', 'sns_wa_' + data.openId);//存储到本地缓存openid
}
},
fail: function (err) {
console.info('打印状态403需重新登陆', err.statusCode);
}
})
},
fail: function (err) {
console.info('测试222222222222状态', err.statusCode);
wx.redirectTo({
url: '../ceshi4/ceshi4',
})
}
})
}
}
})
}
},
globalData: {
userInfo: null
}
})