restapi.js
3.39 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
function t(t, e, a, i, c, p, s, u) {
var l = getApp();
Date.now();
wx.showNavigationBarLoading(), n(a);
wx.request({
url: o + t,
data: e,
header: a,
method: i,
dataType: c,
responseType: p,
success: function (t) {
n(t.header), 401 == t.statusCode ? wx.navigateTo({
url: "/pages/auth/login/login"
}) : 200 == t.statusCode ? s(t.data) : 412 == t.statusCode || 411 == t.statusCode ? wx.login({
success: function (t) {
l.globalData.code = t.code, wx.redirectTo({
url: "/pages/index/index"
});
}
}) : 413 == t.statusCode ? wx.redirectTo({
url: "/pages/login/index/index"
}) : u && "function" == typeof u && u();
},
fail: function (t) {
console.log("error:" + JSON.stringify(t)), u && "function" == typeof u && u();
},
complete: function (t) {
wx.hideNavigationBarLoading();
}
});
}
function n(t) {
var n = wx.getStorageSync(e),
o = t["Set-Cookie"];
if (o) {
var a = new RegExp(e + "=([^;]*)", "ig");
(n = o.match(a) ? o.match(a)[0].substr(e.length + 1) : null) && wx.setStorageSync(e, n);
}
return n && (t.Cookie = [e, "=", n].join("")), t;
}
//测试环境
//var o = "https://dj.test.glsx.com.cn";
// 正式环境
var o = "https://gps.cgacar.com";
var e = "DJ_S_";
getApp();
module.exports = {
domain: o,
req: t,
uploadMedia: function (t, n, e) {
wx.uploadFile({
url: o + "/web-dj-weapp-mp/" + t,
filePath: n,
name: "file",
formData: {
fileCategory: "AG"
},
success: function (t) {
e(JSON.parse(t.data));
},
fail: function (t) {
console.log(t), wx.showToast({
title: t,
icon: "none"
});
}
});
},
getSessionId: function () {
return wx.getStorageSync(e);
},
jscodeLogin: function (n, o, e) {
t("/web-dj-weapp-mp/jscode/login", {
code: n,
appId: o
}, {}, "GET", "json", "text", e);
},
authUserInfo: function (n, o, e) {
t("/web-dj-weapp-mp/auth/userinfo", JSON.stringify(n), {
"content-type": "application/json"
}, "POST", "json", "text", o, e);
},
authPhone: function (n, o) {
t("/web-dj-weapp-mp/auth/phone", JSON.stringify(n), {
"content-type": "application/json"
}, "POST", "json", "text", o);
},
authAccount: function (n, o) {
t("/web-dj-weapp-mp/auth/account", JSON.stringify(n), {
"content-type": "application/json"
}, "POST", "json", "text", o);
},
choiceAccountLogin: function (n, o) {
t("/web-dj-weapp-mp/choice/account/login", JSON.stringify(n), {
"content-type": "application/json"
}, "POST", "json", "text", o);
},
logout: function (n) {
t("/web-dj-weapp-mp/logout", null, {
"content-type": "application/json"
}, "POST", "json", "text", n);
},
checkLogin: function (n) {
t("/web-dj-weapp-mp/login/check", null, {
"content-type": "application/json"
}, "POST", "json", "text", n);
}
};