This repository was archived by the owner on Dec 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
118 lines (118 loc) · 3.86 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
//app.js
App({
onLaunch: function () {
},
globalData: {
userInfo: null
},
download(path, success) {
wx.downloadFile({
url: "https://water.nfls.io/" + path,
header: {
"Cookie": this.getWaterCookie(),
"Client": "weChat"
},
success: res => {
success(res)
}
})
},
upload(path, file, success) {
wx.uploadFile({
url: "https://water.nfls.io/" + path,
header: {
"Cookie": this.getWaterCookie(),
"Client": "weChat"
},
filePath: file,
name: 'image',
success: res => {
console.log(res.data)
success(res.data)
}
})
},
requestAPI: function (path, data, method, success) {
let cookie = ""
let value = wx.getStorageSync('PHPSESSID_MAIN')
if (value) {
cookie = "PHPSESSID=" + value + ";"
}
wx.request({
url: "https://nfls.io/" + path,
data: data,
method: method,
header: {
"Cookie": cookie,
"Client": "weChat"
},
success:(res)=>{
if (res.code === 504) {
this.requestAPI(path, data, method, success)
} else {
if (res.header["Set-Cookie"]) {
let cookie = res.header["Set-Cookie"].split(";")[0].split("=")[1]
wx.setStorageSync("PHPSESSID_MAIN", cookie)
}
if (res.data["code"] === 307 && res.data["data"].startsWith("https")) {
getApp().handleRedirect(res.data["data"], success)
} else {
success(res.data)
}
}
}
})
},
requestWaterAPI(path, data, method, success) {
wx.request({
url: "https://water.nfls.io/" + path,
data: data,
method: method,
header: {
"Cookie": this.getWaterCookie(),
"Client": "weChat"
},
success: (res)=>{
if (res.code === 504) {
this.requestAPI(path, data, method, success)
} else {
this.setWaterCookie(res)
if (res.data["code"] === 307 && res.data["data"].startsWith("https")) {
getApp().handleRedirect(res.data["data"], success)
} else {
success(res.data)
}
}
}
})
},
handleRedirect(url, success) {
if (url.startsWith("https://nfls.io")) {
getApp().requestAPI(url.replace("https://nfls.io/", ""), null, "GET", success)
} else if (url.startsWith("https://water.nfls.io")) {
getApp().requestWaterAPI(url.replace("https://water.nfls.io/", ""), null, "GET", success)
}
},
setWaterCookie(res) {
if (res.header["Set-Cookie"]) {
let cookie = res.header["Set-Cookie"].split(";")[0].split("=")[1]
wx.setStorageSync("PHPSESSID_WATER", cookie)
}
if (res.data["cookie"] != null && res.data["cookie"]["remember_token"] != null) {
wx.setStorageSync("TOKEN_WATER", res.data["cookie"]["remember_token"])
}
},
getWaterCookie() {
let cookie = ""
let token = wx.getStorageSync('TOKEN_WATER')
if (token) {
cookie += "remember_token=" + encodeURIComponent(token) + ";"
}
let session = wx.getStorageSync('PHPSESSID_WATER')
if (session) {
cookie += "PHPSESSID=" + encodeURIComponent(session) + ";"
}
return cookie
},
params: null
})