wxrequest.js
4.31 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
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
145
146
147
148
149
150
151
//const domain = 'https://e-shield.didihu.com.cn/otmini/'; //正式环境
const domain = 'https://e-shield.hhxtechnology.com/otmini/'; //正式环境
//const domain = 'https://devwx.glsx.com.cn/otmini/'; //开发环境
/*
新e盾找车
*/
// 开发:https://eshield.dev.glsx.com.cn/
// 测试:https://eshield.test.glsx.com.cn/
// 生产:https://eshield.didihu.com.cn/
const newDomain = 'https://eshield.didihu.com.cn/'
// 公众号授权页面
const wxDomain = 'https://e-shield.hhxtechnology.com/otmini/'
function redirectToLogin(){console.log('redirectToLogin')
wx.redirectTo({
url: '../../pages/login/login'
});
}
module.exports = {
domain,
wxDomain,
login(data){
return new Promise(function(resolve, reject){
wx.showLoading();
wx.login({
success: res => {
wx.setStorageSync("code", res.code);
const postData = {
...data,
code: res.code
}
if(wx.getStorageSync("publicCode")){
postData.publicCode = wx.getStorageSync("publicCode");
}
const params = {
url: `${domain}loginByCode`, //loginminipro
data: postData,
success: function(res) {
wx.hideLoading();
if(res.statusCode === 200){
const result = res.data;
if(result.returnCode === '0'){
const status = result.data.status;
wx.setStorageSync("sessionid", res.header["Set-Cookie"]);
wx.setStorageSync("userStatus", status);
if(status === 0){//分享者
wx.setStorageSync("userinfo", result.data.user);
wx.setStorageSync('loginUserId', result.data.user.id);
}else if(status === 1){//被分享者
wx.setStorageSync("userinfo", result.data.wxuser);
}
resolve();
}else{
const pages = getCurrentPages();
const currentPage = pages[pages.length-1];
const url = currentPage.route;
if(url !== 'pages/login/login'){
redirectToLogin();
}else{
wx.showModal({
content: result.message,
showCancel: false
});
reject()
}
}
}else{
redirectToLogin();
}
},
fail(){
console.log('fail')
},
complete(){
console.log('complete')
}
};
/*if(data){
data.code = res.code;
params.data = data;
}*/
wx.request(params);
}
});
})
},
get(url, data, isNewFindCar, notShowLoading){
return new Promise(function(resolve, reject){
if (!notShowLoading) { // 实时监控不显示加载中
wx.showLoading();
}
//wx.setStorageSync('sessionid', 'JSESSIONID=node03r5y0xa3w4fh1jdk4e2q4oz860.node0;Path=/otmini')
const params = {
header: {
'cookie': wx.getStorageSync("sessionid")
},
url: isNewFindCar ? `${newDomain}${url}` : `${domain}${url}`,
success: function(res) {
wx.hideLoading();
if(res.statusCode === 200){
const data = res.data;
if('returnCode' in data && data.returnCode !== '0'){
wx.showModal({
content: data.message,
showCancel: false
});
}
if ('code' in data && data.code !== 200) { // 新e盾接口
wx.showModal({
content: data.message,
showCancel: false
});
}
resolve(data);
}else if(res.statusCode === 401){
redirectToLogin();
}
},
fail(){
console.log('fail')
}
};
data && (params.data = data);
wx.request(params);
});
}
}
/*function(){
const testBaseUrl = 'http://localhost:8080/otmini/';
const baseUrl = '';
let args = [].slice.call(arguments, 0)
console.log(args)
}*/