-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
115 lines (107 loc) · 3.02 KB
/
index.ts
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
import axios, { AxiosRequestHeaders } from "axios";
import { isAfter, format } from "date-fns";
/**
* headers
*/
const getHeaders = (cookie: string): AxiosRequestHeaders => {
return {
Host: "miao.ydysoft.com",
Accept: "*/*",
"X-Requested-With": "XMLHttpRequest",
"Accept-Language": "en-US,en;q=0.9",
"Accept-Encoding": "gzip",
"Content-Type": "application/x-www-form-urlencoded",
Origin: "http://miao.ydysoft.com",
"User-Agent":
"Mozilla/5.0 (iPhone; CPU iPhone OS 15_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/8.0.18(0x1800123c) NetType/WIFI Language/zh_CN",
Connection: "keep-alive",
Referer:
"http://miao.ydysoft.com/u-huodonginfo-3da855920c07408cb8e7a6c4fffd77c9.shtml",
cookie,
};
};
/**
*获取id
*/
const guid = () => {
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
var r = (Math.random() * 16) | 0,
v = c == "x" ? r : (r & 0x3) | 0x8;
return v.toString(16);
});
};
interface IQueueProps {
params: URLSearchParams;
cookie: string;
}
const queue = async ({ params, cookie }: IQueueProps): Promise<boolean> => {
try {
const res = await axios({
withCredentials: true,
method: "POST",
url: "http://miao.ydysoft.com/a/u.ashx",
params,
headers: getHeaders(cookie),
});
console.log(res.data);
if (res?.data?.Code === 200) {
return true;
} else {
return false;
}
} catch (error) {
if (error instanceof Error) {
console.log(error);
}
return false;
}
};
const getCode = async ({ cookie }: { cookie: string }): Promise<string> => {
try {
const res = await axios({
withCredentials: true,
method: "GET",
url: "http://miao.ydysoft.com/a/code.ashx",
params: {
str: guid(),
},
headers: getHeaders(cookie),
});
console.log(res.data);
return "";
} catch (error) {
if (error instanceof Error) {
console.log(error);
}
return "";
}
};
const commandArgument = process?.argv?.slice?.(2) || [];
const [queryString, cookie] = commandArgument;
const startDate = new Date("2022-04-29 08:59:57");
const endDate = new Date("2022-04-29 09:10:00");
const getLogTimeString = () => format(new Date(), "yyyy-MM-dd HH:mm:ss");
const log = (msg: string) => console.log(`${msg}(${getLogTimeString()})`);
if (queryString && cookie) {
const timer: NodeJS.Timer = globalThis.setInterval(async () => {
if (isAfter(new Date(), endDate)) {
log(`Activity ended`);
return timer && clearInterval(timer);
}
if (isAfter(new Date(), startDate)) {
// release resources
const params = new URLSearchParams(`${queryString}`);
const weMadeIt = await queue({ params, cookie });
if (weMadeIt) {
log(`We made it!!!!!!!`);
timer && clearInterval(timer);
} else {
log(`Don't worry, try again`);
}
} else {
log(`Activity not start yet`);
}
}, 666);
} else {
console.warn("Missing arguments");
}