-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.js
161 lines (145 loc) · 3.43 KB
/
lib.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
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
152
153
154
155
156
157
158
159
160
161
/**
* Xinkao Temperature Daily Upload
* Single User Function v1.0
* Copyright (c) HZGeek 2022.
* Author: JupiterJun
*/
const axios = require('axios')
const qs = require("querystring");
const XkApis = {
getUserInfo: "https://usr.xinkaoyun.com/api/HSCPC/Login",
getToken: "https://usr.xinkaoyun.com/api/HSCApp/NewLogin_jiami",
sendReport: "https://twsb.xinkaoyun.com:8099/temp/report/studentSaveTemp",
};
// 主干
async function main({
// 解构入参对象
mobile,
password,
childnum,
dorm,
address,
headteacher,
}) {
// 调用userInfo以及判断是否出错
let userInfo = await getUserInfo(mobile, password, childnum);
if (userInfo.resultCode !== 0)
return {
code: -3,
msg: userInfo.data,
};
userInfo = userInfo.data;
// 调用getToken以及判断是否出错
let token = await getToken(mobile, password);
if (token.resultCode !== 0)
return {
code: -4,
msg: "鑫考云App登录失败",
};
token = token.token;
// 调用sendReport以及返回响应
let res = await sendReport(
{ mobile, address, headteacher, dorm },
userInfo,
token
);
console.log(res);
return res;
}
// 获取用户信息,对应鑫考电脑端登录API
async function getUserInfo(mobile, password, childnum) {
// 发送POST请求
let res = await axios.post(
XkApis.getUserInfo,
qs.stringify({
// JS对象转表单body
userName: mobile,
password,
})
);
// 非零错误码
if (res.data.resultCode != 0) {
return res.data;
}
// 正常状态码
return {
resultCode: 0,
data: res.data.data.pardt[childnum],
};
}
// 获取Token,对应鑫考手机端登录API
async function getToken(mobile, password) {
// POST登录API
let res = await axios.post(
XkApis.getToken,
qs.stringify({
phone: Buffer.from(mobile).toString("base64"),
password: Buffer.from(password).toString("base64"),
})
);
if (res.data.resultCode != 0) {
return res.data;
}
return {
resultCode: 0,
token: res.data.data.token,
};
}
// 上报体温
async function sendReport(
{ mobile, address, headteacher, dorm }, // 第一个入参,解构提供的基本信息
{
// 第二个入参,解构第一步获取的信息
SchoolId: schoolId,
GradeId: grade_id,
GradeName: grade,
JiBuId: jibu_id,
JiBuName: jibu,
ClassId: clazz_id,
ClassName: clazz,
StuName: student_name,
StuSex: sex,
UserId: userId,
StudyCode: student_id,
},
token // 第三个入参,第二步获取的Token
) {
let temperature = (35.8 + Math.random()).toFixed(1); // 随机体温35.8-36.8保留一位小数
let data = {
// 拼接请求体
// 常量部分
iscontact_patients: 0,
hasto_riskareas: 0,
iscontact_foreigner: 0,
isfever_family: 0,
// 第一步获取的学生信息
sex,
grade_id,
jibu_id,
schoolId,
grade,
jibu,
clazz,
student_name,
userId,
clazz_id,
student_id,
// 入参学生提供的信息
mobile,
teacher_header: headteacher,
dormitory: dorm,
address,
temperature, // 体温
userToken: token, // 第二步获取的Token
};
// console.log(data)
let res = await axios.post(XkApis.sendReport, qs.stringify(data)); // 发送请求
// 处理异常
if (res.data.state === "fail") return { code: -5, msg: res.data.msg };
// 正常返回
return {
code: 0,
temperature,
};
}
module.exports = main;