fofstudio-aimcpztdata 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/MCPMain.js +2577 -0
- package/build/modules/BufferClass.js +6 -0
- package/build/modules/DataPackaging.js +57 -0
- package/build/modules/DecoderAPI.js +30 -0
- package/build/modules/DialogAPI.js +48 -0
- package/build/modules/EXEAPI.js +64 -0
- package/build/modules/FOFTcp.js +309 -0
- package/build/modules/FOFUDP.js +78 -0
- package/build/modules/File.js +525 -0
- package/build/modules/IP.js +54 -0
- package/build/modules/NoSqlFOFStudio.js +63 -0
- package/build/modules/PlatAPI.js +115 -0
- package/build/modules/ProcessAPI.js +36 -0
- package/build/modules/ReadAPI.js +67 -0
- package/build/modules/SendHttp.js +484 -0
- package/build/modules/dns.js +36 -0
- package/build/modules/mysql.js +0 -0
- package/build/modules/sqlServer.js +0 -0
- package/build/modules/trayApi.js +34 -0
- package/package.json +37 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
const { Notification, powerSaveBlocker, screen, shell} = require('electron');
|
|
2
|
+
const operativeSystemModule = require("os");
|
|
3
|
+
exports.getPlatform = () => {
|
|
4
|
+
return process.platform;
|
|
5
|
+
}
|
|
6
|
+
exports.Notification = (data) => {
|
|
7
|
+
try {
|
|
8
|
+
if (data["图片地址"] != undefined) {
|
|
9
|
+
if (data["图片地址"] != "") {
|
|
10
|
+
new Notification({
|
|
11
|
+
title: data["标题"],
|
|
12
|
+
body: data["内容"],
|
|
13
|
+
icon: data["图片地址"]
|
|
14
|
+
}).show();
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
new Notification({
|
|
19
|
+
title: data["标题"],
|
|
20
|
+
body: data["内容"]
|
|
21
|
+
}).show();
|
|
22
|
+
} catch (err) {
|
|
23
|
+
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.powerSaveBlocker = () => {
|
|
27
|
+
try {
|
|
28
|
+
const id = powerSaveBlocker.start('prevent-display-sleep')
|
|
29
|
+
powerSaveBlocker.isStarted(id)
|
|
30
|
+
powerSaveBlocker.stop(id)
|
|
31
|
+
} catch (err) {
|
|
32
|
+
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.getCursorScreenPoint = () => {
|
|
36
|
+
let Xy = screen.getCursorScreenPoint();
|
|
37
|
+
return { "横向位置": Xy["x"], "纵向位置": Xy["y"] };
|
|
38
|
+
}
|
|
39
|
+
exports.dipToScreenPoint = (point) => {
|
|
40
|
+
try {
|
|
41
|
+
let XyYS = { "x": point["横向位置"], "y": point["纵向位置"] }
|
|
42
|
+
let Xy = screen.dipToScreenPoint(XyYS);
|
|
43
|
+
return { "横向位置": Xy["x"], "纵向位置": Xy["y"] };
|
|
44
|
+
} catch (err) {
|
|
45
|
+
return { "横向位置": 0, "纵向位置": 0 };
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.networkInterfaces = () => {
|
|
49
|
+
return operativeSystemModule.networkInterfaces();
|
|
50
|
+
}
|
|
51
|
+
exports.cpus = () => {
|
|
52
|
+
return operativeSystemModule.cpus();
|
|
53
|
+
}
|
|
54
|
+
exports.tmpDir = () => {
|
|
55
|
+
return operativeSystemModule.tmpdir();
|
|
56
|
+
}
|
|
57
|
+
exports.arch = () => {
|
|
58
|
+
return operativeSystemModule.arch();
|
|
59
|
+
}
|
|
60
|
+
exports.totalmem = () => {
|
|
61
|
+
return operativeSystemModule.totalmem();
|
|
62
|
+
}
|
|
63
|
+
exports.freemem = () => {
|
|
64
|
+
return operativeSystemModule.freemem();
|
|
65
|
+
}
|
|
66
|
+
exports.OStype = () => {
|
|
67
|
+
return operativeSystemModule.type();
|
|
68
|
+
}
|
|
69
|
+
exports.hostname = () => {
|
|
70
|
+
return operativeSystemModule.hostname();
|
|
71
|
+
}
|
|
72
|
+
exports.release = () => {
|
|
73
|
+
return operativeSystemModule.release();
|
|
74
|
+
}
|
|
75
|
+
exports.uptime = () => {
|
|
76
|
+
return operativeSystemModule.uptime();
|
|
77
|
+
}
|
|
78
|
+
exports.loadavg = () => {
|
|
79
|
+
return operativeSystemModule.loadavg();
|
|
80
|
+
}
|
|
81
|
+
exports.showItemInFolder = (fullPath) => {
|
|
82
|
+
try {
|
|
83
|
+
shell.showItemInFolder(fullPath)
|
|
84
|
+
} catch (err) {
|
|
85
|
+
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
exports.openPath = (fullPath) => {
|
|
89
|
+
try {
|
|
90
|
+
shell.openPath(fullPath)
|
|
91
|
+
} catch (err) {
|
|
92
|
+
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
exports.openExternal = (url) => {
|
|
96
|
+
try {
|
|
97
|
+
shell.openExternal(url)
|
|
98
|
+
} catch (err) {
|
|
99
|
+
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
exports.trashItem = (fullPath) => {
|
|
103
|
+
try {
|
|
104
|
+
shell.trashItem(fullPath)
|
|
105
|
+
} catch (err) {
|
|
106
|
+
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
exports.openItem = (fullPath) => {
|
|
110
|
+
try {
|
|
111
|
+
shell.openItem(fullPath)
|
|
112
|
+
} catch (err) {
|
|
113
|
+
|
|
114
|
+
}
|
|
115
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
function loadModule(paths) {
|
|
4
|
+
for (const p of paths) {
|
|
5
|
+
try {
|
|
6
|
+
require.resolve(p);
|
|
7
|
+
return require(p);
|
|
8
|
+
} catch (err) {
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
throw new Error(`所有模块路径均未找到: ${paths.join(', ')}`);
|
|
12
|
+
}
|
|
13
|
+
const possiblePaths = [
|
|
14
|
+
path.join(__dirname, '../electronClass/child_process.js'),
|
|
15
|
+
path.join(__dirname, './child_process.js')
|
|
16
|
+
];
|
|
17
|
+
let workerProcess;
|
|
18
|
+
try {
|
|
19
|
+
workerProcess = loadModule(possiblePaths);
|
|
20
|
+
} catch (err) {
|
|
21
|
+
console.error('无法加载 child_process.js 模块:', err.message);
|
|
22
|
+
}
|
|
23
|
+
exports.runExec = (Data, SetProcessYesMsg = undefined, SetProcessNoMsg = undefined, SetProcessEndMsg = undefined, encoding_ = "GBK", env = undefined, ifArr = false) => {
|
|
24
|
+
try {
|
|
25
|
+
workerProcess.runExec(Data["路径"], Data.code, SetProcessYesMsg, SetProcessNoMsg, SetProcessEndMsg, encoding_, env, ifArr);
|
|
26
|
+
} catch (error) {
|
|
27
|
+
console.error('执行 runExec 时出错:', error);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
exports.runExeckill = () => {
|
|
31
|
+
try {
|
|
32
|
+
workerProcess.kill();
|
|
33
|
+
} catch (error) {
|
|
34
|
+
console.error('执行 kill 时出错:', error);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
const { clipboard } = require('electron');
|
|
2
|
+
exports.readText = () => {
|
|
3
|
+
try {
|
|
4
|
+
if (process.platform == 'darwin' || process.platform == 'win32') {
|
|
5
|
+
return clipboard.readText();
|
|
6
|
+
} else {
|
|
7
|
+
return clipboard.readText("selection");
|
|
8
|
+
}
|
|
9
|
+
} catch (err) {
|
|
10
|
+
return "";
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.writeText = (text) => {
|
|
14
|
+
try {
|
|
15
|
+
if (process.platform == 'darwin' || process.platform == 'win32') {
|
|
16
|
+
clipboard.writeText(text)
|
|
17
|
+
} else {
|
|
18
|
+
clipboard.writeText(text, "selection")
|
|
19
|
+
}
|
|
20
|
+
} catch (err) {
|
|
21
|
+
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.readHTML = () => {
|
|
25
|
+
try {
|
|
26
|
+
if (process.platform == 'darwin' || process.platform == 'win32') {
|
|
27
|
+
return clipboard.readHTML();
|
|
28
|
+
} else {
|
|
29
|
+
return clipboard.readHTML("selection");
|
|
30
|
+
}
|
|
31
|
+
} catch (err) {
|
|
32
|
+
return "";
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.writeHTML = (text) => {
|
|
36
|
+
try {
|
|
37
|
+
if (process.platform == 'darwin' || process.platform == 'win32') {
|
|
38
|
+
clipboard.writeHTML(text)
|
|
39
|
+
} else {
|
|
40
|
+
clipboard.writeHTML(text, "selection")
|
|
41
|
+
}
|
|
42
|
+
} catch (err) {
|
|
43
|
+
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.readRTF = () => {
|
|
47
|
+
try {
|
|
48
|
+
if (process.platform == 'darwin' || process.platform == 'win32') {
|
|
49
|
+
return clipboard.readRTF();
|
|
50
|
+
} else {
|
|
51
|
+
return clipboard.readRTF("selection");
|
|
52
|
+
}
|
|
53
|
+
} catch (err) {
|
|
54
|
+
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.writeRTF = (text) => {
|
|
58
|
+
try {
|
|
59
|
+
if (process.platform == 'darwin' || process.platform == 'win32') {
|
|
60
|
+
clipboard.writeRTF(text)
|
|
61
|
+
} else {
|
|
62
|
+
clipboard.writeRTF(text, "selection")
|
|
63
|
+
}
|
|
64
|
+
} catch (err) {
|
|
65
|
+
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,484 @@
|
|
|
1
|
+
const http = require("http")
|
|
2
|
+
const https = require("https")
|
|
3
|
+
const urlData = require('url');
|
|
4
|
+
var zlib = require('zlib');
|
|
5
|
+
exports.httpsSend = (url, RetFun, method_ = "GET", POSTDATA = "", headers_ = {}, followAllRedirects_ = true, timeout_ = 5000) => {
|
|
6
|
+
let codeType = undefined;
|
|
7
|
+
let url_ = ""
|
|
8
|
+
if (url["协议"] != undefined) {
|
|
9
|
+
url["protocol"] = url["协议"]
|
|
10
|
+
}
|
|
11
|
+
if (url["主机域名"] != undefined) {
|
|
12
|
+
url["host"] = url["主机域名"]
|
|
13
|
+
}
|
|
14
|
+
if (url["端口"] != undefined) {
|
|
15
|
+
url["port"] = url["端口"]
|
|
16
|
+
}
|
|
17
|
+
if (url["路径"] != undefined) {
|
|
18
|
+
url["path"] = url["路径"]
|
|
19
|
+
}
|
|
20
|
+
if (url["编码"] != undefined) {
|
|
21
|
+
codeType = url["编码"]
|
|
22
|
+
}
|
|
23
|
+
if (url["protocol"] != undefined) {
|
|
24
|
+
var options = {
|
|
25
|
+
hostname: url["host"],
|
|
26
|
+
method: method_,
|
|
27
|
+
headers: headers_,
|
|
28
|
+
followAllRedirects: followAllRedirects_,
|
|
29
|
+
timeout: timeout_,
|
|
30
|
+
path: url["path"]
|
|
31
|
+
}
|
|
32
|
+
if (url["GZIP"] != undefined) {
|
|
33
|
+
if (url["GZIP"] == true) {
|
|
34
|
+
options["GZIP"] = true;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (url["字节流"] != undefined) {
|
|
38
|
+
if (url["字节流"] == true) {
|
|
39
|
+
options["字节流"] = true;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (url["port"] != 80) {
|
|
43
|
+
options["hostname"] = options["hostname"] + ":" + url["port"]
|
|
44
|
+
}
|
|
45
|
+
if (url["port"] == undefined) {
|
|
46
|
+
url["port"] = 80
|
|
47
|
+
}
|
|
48
|
+
} else {
|
|
49
|
+
if (url["链接地址"] != undefined) {
|
|
50
|
+
if (url["链接地址"]) {
|
|
51
|
+
url_ = url["链接地址"]
|
|
52
|
+
url = UrlSet(url["链接地址"])
|
|
53
|
+
}
|
|
54
|
+
if (url["url"]) {
|
|
55
|
+
url_ = url["url"]
|
|
56
|
+
url = UrlSet(url["url"])
|
|
57
|
+
}
|
|
58
|
+
} else {
|
|
59
|
+
url_ = url
|
|
60
|
+
url = UrlSet(url)
|
|
61
|
+
}
|
|
62
|
+
let Path_ = PathSet(url_)
|
|
63
|
+
var options = {
|
|
64
|
+
hostname: url,
|
|
65
|
+
method: method_,
|
|
66
|
+
headers: headers_,
|
|
67
|
+
followAllRedirects: followAllRedirects_,
|
|
68
|
+
timeout: timeout_,
|
|
69
|
+
path: Path_
|
|
70
|
+
}
|
|
71
|
+
if (url["GZIP"] != undefined) {
|
|
72
|
+
if (url["GZIP"] == true) {
|
|
73
|
+
options["GZIP"] = true;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (url["字节流"] != undefined) {
|
|
77
|
+
if (url["字节流"] == true) {
|
|
78
|
+
options["字节流"] = true;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
let IntUrl = []
|
|
83
|
+
if (url["重定向"] != undefined) {
|
|
84
|
+
options["重定向"] = url["重定向"]
|
|
85
|
+
}
|
|
86
|
+
httpsSendYes(options, POSTDATA, (endObj) => {
|
|
87
|
+
if (RetFun != undefined) {
|
|
88
|
+
RetFun(endObj)
|
|
89
|
+
}
|
|
90
|
+
}, IntUrl, codeType)
|
|
91
|
+
}
|
|
92
|
+
exports.httpSend = (url, RetFun, method_ = "GET", POSTDATA = "", headers_ = {}, followAllRedirects_ = true, timeout_ = 5000) => {
|
|
93
|
+
let url_ = ""
|
|
94
|
+
let codeType = undefined
|
|
95
|
+
if (url["协议"] != undefined) {
|
|
96
|
+
url["protocol"] = url["协议"]
|
|
97
|
+
}
|
|
98
|
+
if (url["主机域名"] != undefined) {
|
|
99
|
+
url["host"] = url["主机域名"]
|
|
100
|
+
}
|
|
101
|
+
if (url["端口"] != undefined) {
|
|
102
|
+
url["port"] = url["端口"]
|
|
103
|
+
}
|
|
104
|
+
if (url["路径"] != undefined) {
|
|
105
|
+
url["path"] = url["路径"]
|
|
106
|
+
}
|
|
107
|
+
if (url["编码"] != undefined) {
|
|
108
|
+
codeType = url["编码"]
|
|
109
|
+
}
|
|
110
|
+
if (url["protocol"] != undefined) {
|
|
111
|
+
var options = {
|
|
112
|
+
hostname: url["host"],
|
|
113
|
+
method: method_,
|
|
114
|
+
headers: headers_,
|
|
115
|
+
followAllRedirects: followAllRedirects_,
|
|
116
|
+
timeout: timeout_,
|
|
117
|
+
path: url["path"]
|
|
118
|
+
}
|
|
119
|
+
if (url["GZIP"] != undefined) {
|
|
120
|
+
if (url["GZIP"] == true) {
|
|
121
|
+
options["GZIP"] = true;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (url["字节流"] != undefined) {
|
|
125
|
+
if (url["字节流"] == true) {
|
|
126
|
+
options["字节流"] = true;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
if (url["port"] == undefined) {
|
|
130
|
+
url["port"] = 80
|
|
131
|
+
}
|
|
132
|
+
if (url["port"] != 80) {
|
|
133
|
+
options["hostname"] = options["hostname"] + ":" + url["port"]
|
|
134
|
+
}
|
|
135
|
+
if (url["编码"] != undefined) {
|
|
136
|
+
codeType = url["编码"]
|
|
137
|
+
}
|
|
138
|
+
} else {
|
|
139
|
+
if (url["链接地址"]) {
|
|
140
|
+
if (url["链接地址"]) {
|
|
141
|
+
url_ = url["链接地址"]
|
|
142
|
+
url = UrlSet(url["链接地址"])
|
|
143
|
+
}
|
|
144
|
+
if (url["url"]) {
|
|
145
|
+
url_ = url["url"]
|
|
146
|
+
url = UrlSet(url["url"])
|
|
147
|
+
}
|
|
148
|
+
} else {
|
|
149
|
+
url_ = url
|
|
150
|
+
url = UrlSet(url)
|
|
151
|
+
}
|
|
152
|
+
let Path_ = PathSet(url_)
|
|
153
|
+
var options = {
|
|
154
|
+
hostname: url,
|
|
155
|
+
method: method_,
|
|
156
|
+
headers: headers_,
|
|
157
|
+
followAllRedirects: followAllRedirects_,
|
|
158
|
+
timeout: timeout_,
|
|
159
|
+
path: Path_
|
|
160
|
+
}
|
|
161
|
+
if (url["GZIP"] != undefined) {
|
|
162
|
+
if (url["GZIP"] == true) {
|
|
163
|
+
options["GZIP"] = true;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
if (url["字节流"] != undefined) {
|
|
167
|
+
if (url["字节流"] == true) {
|
|
168
|
+
options["字节流"] = true;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
let IntUrl = []
|
|
173
|
+
if (url["重定向"] != undefined) {
|
|
174
|
+
options["重定向"] = url["重定向"]
|
|
175
|
+
}
|
|
176
|
+
httpSendYes(options, POSTDATA, (endObj) => {
|
|
177
|
+
if (RetFun != undefined) {
|
|
178
|
+
RetFun(endObj)
|
|
179
|
+
}
|
|
180
|
+
}, IntUrl, codeType)
|
|
181
|
+
}
|
|
182
|
+
function httpsSendYes(options, POSTDATA, RetFun, IntUrl = [], codeType) {
|
|
183
|
+
//使用http 发送
|
|
184
|
+
var req = https.request(options, function (res) {
|
|
185
|
+
//设置字符编码
|
|
186
|
+
if (codeType != undefined) {
|
|
187
|
+
res.setEncoding(codeType);
|
|
188
|
+
}
|
|
189
|
+
//返回数据流
|
|
190
|
+
var _data = "";
|
|
191
|
+
var _data_ = []
|
|
192
|
+
//数据
|
|
193
|
+
res.on('data', function (chunk) {
|
|
194
|
+
if (options["GZIP"] != undefined || options["字节流"] != undefined) {
|
|
195
|
+
if (options["GZIP"] == true || options["字节流"] == true) {
|
|
196
|
+
_data_.push(chunk);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
if (options["字节流"] == undefined) {
|
|
200
|
+
_data += chunk;
|
|
201
|
+
} else {
|
|
202
|
+
if (options["字节流"] == false) {
|
|
203
|
+
_data += chunk;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
// 结束回调
|
|
208
|
+
res.on('end', function () {
|
|
209
|
+
if (options["重定向"] == undefined || options["重定向"] == true) {
|
|
210
|
+
if (res.statusCode == 301 || res.statusCode == 302) {
|
|
211
|
+
if (res.headers["location"]) {
|
|
212
|
+
if (IntUrl.indexOf(res.headers["location"]) == -1) {
|
|
213
|
+
IntUrl[IntUrl.length] = res.headers["location"]
|
|
214
|
+
let location = locationSet(res.headers["location"], options, true)
|
|
215
|
+
options["hostname"] = UrlSet(location)
|
|
216
|
+
options["path"] = PathSet(res.headers["location"])
|
|
217
|
+
if (location.substring(0, 8).indexOf("https://") != -1) {
|
|
218
|
+
httpsSendYes(options, POSTDATA, RetFun, IntUrl, codeType)
|
|
219
|
+
} else {
|
|
220
|
+
httpSendYes(options, POSTDATA, RetFun, IntUrl, codeType)
|
|
221
|
+
}
|
|
222
|
+
return
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
if (options["GZIP"]) {
|
|
228
|
+
if (options["GZIP"] == true) {
|
|
229
|
+
var buffer = Buffer.concat(_data_);
|
|
230
|
+
let endObj = {
|
|
231
|
+
"返回协议头": res.headers,
|
|
232
|
+
"返回状态码": res.statusCode,
|
|
233
|
+
"整体状态": res
|
|
234
|
+
}
|
|
235
|
+
zlib.gunzip(buffer, function (err, decoded) {
|
|
236
|
+
endObj["数据"] = decoded.toString()
|
|
237
|
+
if (RetFun != undefined) {
|
|
238
|
+
RetFun(endObj)
|
|
239
|
+
}
|
|
240
|
+
})
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
let endObj = {
|
|
245
|
+
"数据": _data,
|
|
246
|
+
"返回协议头": res.headers,
|
|
247
|
+
"返回状态码": res.statusCode,
|
|
248
|
+
"整体状态": res
|
|
249
|
+
}
|
|
250
|
+
if (options["字节流"] != undefined) {
|
|
251
|
+
if (options["字节流"] == true) {
|
|
252
|
+
endObj["数据"] = _data_;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
if (RetFun != undefined) {
|
|
256
|
+
RetFun(endObj)
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
//错误回调
|
|
260
|
+
//这个必须有,不然会有不少"麻烦"
|
|
261
|
+
req.on('error', function (e) {
|
|
262
|
+
//console.log('网络请求错误:' + e.message);
|
|
263
|
+
let endObj = {
|
|
264
|
+
"数据": "",
|
|
265
|
+
"返回协议头": "失败,无协议头",
|
|
266
|
+
"返回状态码": 0,
|
|
267
|
+
"原因": e.message
|
|
268
|
+
}
|
|
269
|
+
if (RetFun != undefined) {
|
|
270
|
+
RetFun(endObj)
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
});
|
|
274
|
+
req.write(POSTDATA);
|
|
275
|
+
req.end();
|
|
276
|
+
}
|
|
277
|
+
function httpSendYes(options, POSTDATA, RetFun, IntUrl = [], codeType) {
|
|
278
|
+
//使用http 发送
|
|
279
|
+
let options_ = optionsIP(options);
|
|
280
|
+
var req = http.request(options_, function (res) {
|
|
281
|
+
//设置字符编码
|
|
282
|
+
if (codeType != undefined) {
|
|
283
|
+
res.setEncoding(codeType);
|
|
284
|
+
}
|
|
285
|
+
//返回数据流
|
|
286
|
+
var _data = "";
|
|
287
|
+
var _data_ = [];
|
|
288
|
+
//数据
|
|
289
|
+
res.on('data', function (chunk) {
|
|
290
|
+
if (options["GZIP"] != undefined || options["字节流"] != undefined) {
|
|
291
|
+
if (options["GZIP"] == true || options["字节流"] == true) {
|
|
292
|
+
_data_.push(chunk);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
if (options["字节流"] == undefined) {
|
|
296
|
+
_data += chunk;
|
|
297
|
+
} else {
|
|
298
|
+
if (options["字节流"] == false) {
|
|
299
|
+
_data += chunk;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
// 结束回调
|
|
304
|
+
res.on('end', function () {
|
|
305
|
+
if (options["重定向"] == undefined || options["重定向"] == true) {
|
|
306
|
+
if (res.statusCode == 301 || res.statusCode == 302) {
|
|
307
|
+
if (res.headers["location"]) {
|
|
308
|
+
if (IntUrl.indexOf(res.headers["location"]) == -1) {
|
|
309
|
+
IntUrl[IntUrl.length] = res.headers["location"]
|
|
310
|
+
let location = locationSet(res.headers["location"], options_, false)
|
|
311
|
+
options["hostname"] = UrlSet(location)
|
|
312
|
+
options["path"] = PathSet(res.headers["location"])
|
|
313
|
+
if (location.substring(0, 8).indexOf("https://") != -1) {
|
|
314
|
+
httpsSendYes(options, POSTDATA, RetFun, IntUrl, codeType)
|
|
315
|
+
} else {
|
|
316
|
+
httpSendYes(options, POSTDATA, RetFun, IntUrl, codeType)
|
|
317
|
+
}
|
|
318
|
+
return
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
if (options["GZIP"]) {
|
|
324
|
+
if (options["GZIP"] == true) {
|
|
325
|
+
var buffer = Buffer.concat(_data_);
|
|
326
|
+
let endObj = {
|
|
327
|
+
"返回协议头": res.headers,
|
|
328
|
+
"返回状态码": res.statusCode,
|
|
329
|
+
"整体状态": res
|
|
330
|
+
}
|
|
331
|
+
zlib.gunzip(buffer, function (err, decoded) {
|
|
332
|
+
endObj["数据"] = decoded.toString()
|
|
333
|
+
if (RetFun != undefined) {
|
|
334
|
+
RetFun(endObj)
|
|
335
|
+
}
|
|
336
|
+
})
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
let endObj = {
|
|
341
|
+
"数据": _data,
|
|
342
|
+
"返回协议头": res.headers,
|
|
343
|
+
"返回状态码": res.statusCode,
|
|
344
|
+
"整体状态": res
|
|
345
|
+
}
|
|
346
|
+
if (options["字节流"] != undefined) {
|
|
347
|
+
if (options["字节流"] == true) {
|
|
348
|
+
endObj["数据"] = _data_;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
if (RetFun != undefined) {
|
|
352
|
+
RetFun(endObj)
|
|
353
|
+
}
|
|
354
|
+
});
|
|
355
|
+
//错误回调
|
|
356
|
+
//这个必须有,不然会有不少"麻烦"
|
|
357
|
+
req.on('error', function (e) {
|
|
358
|
+
//console.log('网络请求错误:' + e.message);
|
|
359
|
+
let endObj = {
|
|
360
|
+
"数据": "",
|
|
361
|
+
"返回协议头": "失败,无协议头",
|
|
362
|
+
"返回状态码": 0,
|
|
363
|
+
"原因": e.message
|
|
364
|
+
}
|
|
365
|
+
if (RetFun != undefined) {
|
|
366
|
+
RetFun(endObj)
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
});
|
|
370
|
+
req.write(POSTDATA);
|
|
371
|
+
req.end();
|
|
372
|
+
}
|
|
373
|
+
function UrlSet(url) {
|
|
374
|
+
if (url.length >= 7) {
|
|
375
|
+
if (url.substring(0, "http://".length) == "http://") {
|
|
376
|
+
url = url.replace("http://", "")
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
if (url.length >= 8) {
|
|
380
|
+
if (url.substring(0, "https://".length) == "https://") {
|
|
381
|
+
url = url.replace("https://", "")
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
let path_ = "";
|
|
385
|
+
if (url.indexOf("/") != -1) {
|
|
386
|
+
let pathAll = url.split("/");
|
|
387
|
+
if (pathAll.length >= 1) {
|
|
388
|
+
let hostUrl = pathAll[0];
|
|
389
|
+
path_ = url.replace(hostUrl, "");
|
|
390
|
+
url = url.replace(path_, "")
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
return url;
|
|
394
|
+
}
|
|
395
|
+
function PathSet(url) {
|
|
396
|
+
if (url.length >= 7) {
|
|
397
|
+
if (url.substring(0, "http://".length) == "http://") {
|
|
398
|
+
url = url.replace("http://", "")
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
if (url.length >= 8) {
|
|
402
|
+
if (url.substring(0, "https://".length) == "https://") {
|
|
403
|
+
url = url.replace("https://", "")
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
let path_ = "";
|
|
407
|
+
if (url.indexOf("/") != -1) {
|
|
408
|
+
let pathAll = url.split("/");
|
|
409
|
+
if (pathAll.length >= 1) {
|
|
410
|
+
let hostUrl = pathAll[0];
|
|
411
|
+
path_ = url.replace(hostUrl, "");
|
|
412
|
+
url = url.replace(path_, "")
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
return path_;
|
|
416
|
+
}
|
|
417
|
+
function optionsIP(options_) {
|
|
418
|
+
let Url_ = urlData.parse("http://" + options_["hostname"] + options_["path"])
|
|
419
|
+
var options = {
|
|
420
|
+
method: options_["method"],
|
|
421
|
+
headers: options_["headers"],
|
|
422
|
+
followAllRedirects: options_["followAllRedirects"],
|
|
423
|
+
timeout: options_["timeout"]
|
|
424
|
+
}
|
|
425
|
+
options["protocol"] = "http:"
|
|
426
|
+
if (Url_["hostname"] == undefined || Url_["hostname"] == null) {
|
|
427
|
+
options["host"] = "0.0.0.0"
|
|
428
|
+
} else {
|
|
429
|
+
options["host"] = Url_["hostname"]
|
|
430
|
+
}
|
|
431
|
+
if (Url_["port"] == undefined || Url_["port"] == null) {
|
|
432
|
+
options["port"] = 80
|
|
433
|
+
} else {
|
|
434
|
+
options["port"] = parseInt(Url_["port"])
|
|
435
|
+
}
|
|
436
|
+
if (Url_["path"] == undefined || Url_["path"] == null) {
|
|
437
|
+
options["path"] = "/"
|
|
438
|
+
} else {
|
|
439
|
+
options["path"] = Url_["path"]
|
|
440
|
+
}
|
|
441
|
+
return options;
|
|
442
|
+
}
|
|
443
|
+
//options-使用optionsIP后的optionsIP
|
|
444
|
+
function locationSet(location, options, httpifhttps = false) {
|
|
445
|
+
if (location.indexOf("http://") == -1 && location.indexOf("https://") == -1) {
|
|
446
|
+
if (httpifhttps == false) {
|
|
447
|
+
//http
|
|
448
|
+
let Httpslocation = urlData.parse(options["hostname"])
|
|
449
|
+
if (Httpslocation["protocol"] == undefined || Httpslocation["protocol"] == null) {
|
|
450
|
+
Httpslocation["protocol"] = "http:"
|
|
451
|
+
}
|
|
452
|
+
if (Httpslocation["host"] == undefined || Httpslocation["host"] == null) {
|
|
453
|
+
Httpslocation["host"] = options["hostname"]
|
|
454
|
+
}
|
|
455
|
+
if (Httpslocation["port"] == undefined || Httpslocation["port"] == null) {
|
|
456
|
+
Httpslocation["port"] = 80
|
|
457
|
+
}
|
|
458
|
+
location = location.replace(Httpslocation["host"], "")
|
|
459
|
+
if (Httpslocation["port"] == 80) {
|
|
460
|
+
location = Httpslocation["protocol"] + "//" + Httpslocation["host"] + location
|
|
461
|
+
} else {
|
|
462
|
+
location = Httpslocation["protocol"] + "//" + Httpslocation["host"] + ":" + Httpslocation["port"] + location
|
|
463
|
+
}
|
|
464
|
+
} else {
|
|
465
|
+
let Httpslocation = urlData.parse(options["hostname"])
|
|
466
|
+
if (Httpslocation["protocol"] == undefined || Httpslocation["protocol"] == null) {
|
|
467
|
+
Httpslocation["protocol"] = "https:"
|
|
468
|
+
}
|
|
469
|
+
if (Httpslocation["host"] == undefined || Httpslocation["host"] == null) {
|
|
470
|
+
Httpslocation["host"] = options["hostname"]
|
|
471
|
+
}
|
|
472
|
+
if (Httpslocation["port"] == undefined || Httpslocation["port"] == null) {
|
|
473
|
+
Httpslocation["port"] = 80
|
|
474
|
+
}
|
|
475
|
+
location = location.replace(Httpslocation["host"], "")
|
|
476
|
+
if (Httpslocation["port"] == 80) {
|
|
477
|
+
location = Httpslocation["protocol"] + "//" + Httpslocation["host"] + location
|
|
478
|
+
} else {
|
|
479
|
+
location = Httpslocation["protocol"] + "//" + Httpslocation["host"] + ":" + Httpslocation["port"] + location
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
return location;
|
|
484
|
+
}
|