forked from hxxy2003/wechat_shop_xcx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
149 lines (139 loc) · 3.55 KB
/
app.js
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// app.js
App({
d: {
hostUrl: 'https://wxplus.paoyeba.com/index.php',
hostImg: 'http://img.ynjmzb.net',
hostVideo: 'http://zhubaotong-file.oss-cn-beijing.aliyuncs.com',
userId: 1,
appId:"",
appKey:"",
ceshiUrl:'https://wxplus.paoyeba.com/index.php',
},
onLaunch: function () {
//调用API从本地缓存中获取数据
var logs = wx.getStorageSync('logs') || []
logs.unshift(Date.now())
wx.setStorageSync('logs', logs);
//login
this.getUserInfo();
},
getUserInfo:function(cb){
var that = this
if(this.globalData.userInfo){
typeof cb == "function" && cb(this.globalData.userInfo)
}else{
//调用登录接口
wx.login({
success: function (res) {
var code = res.code;
//get wx user simple info
wx.getUserInfo({
success: function (res) {
that.globalData.userInfo = res.userInfo
typeof cb == "function" && cb(that.globalData.userInfo);
//get user sessionKey
//get sessionKey
that.getUserSessionKey(code);
}
});
}
});
}
},
getUserSessionKey:function(code){
//用户的订单状态
var that = this;
wx.request({
url: that.d.ceshiUrl + '/Api/Login/getsessionkey',
method:'post',
data: {
code: code
},
header: {
'Content-Type': 'application/x-www-form-urlencoded'
},
success: function (res) {
//--init data
var data = res.data;
if(data.status==0){
wx.showToast({
title: data.err,
duration: 2000
});
return false;
}
that.globalData.userInfo['sessionId'] = data.session_key;
that.globalData.userInfo['openid'] = data.openid;
that.onLoginUser();
},
fail:function(e){
wx.showToast({
title: '网络异常!err:getsessionkeys',
duration: 2000
});
},
});
},
onLoginUser:function(){
var that = this;
var user = that.globalData.userInfo;
wx.request({
url: that.d.ceshiUrl + '/Api/Login/authlogin',
method:'post',
data: {
SessionId: user.sessionId,
gender:user.gender,
NickName: user.nickName,
HeadUrl: user.avatarUrl,
openid:user.openid
},
header: {
'Content-Type': 'application/x-www-form-urlencoded'
},
success: function (res) {
//--init data
var data = res.data.arr;
var status = res.data.status;
if(status!=1){
wx.showToast({
title: res.data.err,
duration: 3000
});
return false;
}
that.globalData.userInfo['id'] = data.ID;
that.globalData.userInfo['NickName'] = data.NickName;
that.globalData.userInfo['HeadUrl'] = data.HeadUrl;
var userId = data.ID;
if (!userId){
wx.showToast({
title: '登录失败!',
duration: 3000
});
return false;
}
that.d.userId = userId;
},
fail:function(e){
wx.showToast({
title: '网络异常!err:authlogin',
duration: 2000
});
},
});
},
getOrBindTelPhone:function(returnUrl){
var user = this.globalData.userInfo;
if(!user.tel){
wx.navigateTo({
url: 'pages/binding/binding'
});
}
},
globalData:{
userInfo:null
},
onPullDownRefresh: function (){
wx.stopPullDownRefresh();
}
});