index.js
1.7 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
//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',
})
}
})
}
})
},
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)
})
}
})