index.js
2.5 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
102
103
104
105
106
//index.js
//获取应用实例
let method = require("../../utils/reuqest.js")
const app = getApp()
Page({
data: {
id:'1',
motto: 'Hello World',
userInfo: {},
hasUserInfo: false,
sessionKey:'',
canIUse: wx.canIUse('button.open-type.getUserInfo')
},
getSesionkey(){
let that = this;
wx.login({
success: function (res) {
method.getRequest('/login/getSessionKey/'+res.code,data=>{
that.setData({
sessionKey :data.data
})
if(typeof(data.data!==String) ){
wx.setStorageSync('Authorization', data.data.authorization)
wx.setStorageSync('wxImg', data.data.loginUser.wxName)
wx.setStorageSync('wxName', data.data.loginUser.wxHeadImg)
wx.switchTab({
url: '/pages/home/home',
})
}
})
}
})
},
//获取用户信息
// getUserInfo(e) {
// this.sessionKey()
// let that = this;
// wx.getSetting({
// success: function (res) {
// if (res.authSetting['scope.userInfo']) {
// wx.navigateBack({
// delta: 0,
// })
// }else{
// wx.getUserInfo({
// success(res) {
// }
// })
// }
// }
// })
// },
onLoad: function () {
// this.getSesionkey();
// this.getUserInfo()
},
onShow:function(){
// let authorization=wx.getStorageSync('authorization');
// if(authorization){
// wx.switchTab({
// url: '/pages/home/home',
// })
// }
},
bindGetUserInfo: function (e) {
this.getSesionkey()
let that = this;
setTimeout(()=>{
let postData = {
sessionKey: that.data.sessionKey,
encryptedData: e.detail.encryptedData,
iv: e.detail.iv,
type: "1"
}
method.postRequest('/login', postData, data => {
if (data.statusCode == 0) {
wx.showToast({
title: '授权成功',
})
wx.switchTab({
url: '/pages/home/home',
})
}
},2000)
})
// let postData = {
// sessionKey: that.data.sessionKey,
// encryptedData: e.detail.encryptedData,
// iv: e.detail.iv,
// type: "1"
// }
// method.postRequest('/login', postData, data => {
// if (data.statusCode == 0) {
// wx.showToast({
// title: '授权成功',
// })
// wx.switchTab({
// url: '/pages/home/home',
// })
// }
// })
}
})