This repository has been archived by the owner on Jun 13, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
115 lines (96 loc) · 2.65 KB
/
index.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
var express = require('express');
var cet = require('./cet');
var app = express();
var bodyParser = require('body-parser');
var date=new Date();
Y = date.getFullYear() + '-';
M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
D = date.getDay() + ' ';
h = date.getHours() + ':';
m = date.getMinutes() + ':';
s = date.getSeconds();
var time=Y+M+D+h+m+s;
var success=function (r,info,data) {
var return_data={
"status":200,
"info":info,
"data":data
};
r.json(return_data);
console.log("INFO:[time: "+time+"]"+info);
return true;
};
var error =function (r,info) {
var return_data={
"status":500,
"info":info
};
r.json(return_data);
//控制台输出错误信息
console.log("INFO:[time: "+time+"]"+info);
return false;
};
app.use(bodyParser.json()); // for parsing application/json
app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded
app.post('/gradeNoId',function (req,res) {
//姓名验证
if(!req.body.name){
return error(res,"姓名必须!");
}
var name=req.body.name;
if(name.length<2||name.length>4){
return error(res,"姓名长度参数错误!");
}
//学校验证
if(!req.body.school){
return error(res,"学校必须!");
}
var school=req.body.school;
//类型验证
if(!req.body.type){
return error(res,"考试等级必须!");
}
var type=req.body.type;
if(type!=1&&type!=2){
return error(res,"考试类型参数错误!");
}
cet.getGradeNoId(name,school,type,function (e,g) {
if(e){
return error(res,e);
}
return success(res,"成绩获取成功!",g);
});
});
/**
* 有准考证号获取成绩
*/
app.post('/grade', function (req, res) {
console.log(req.body);
//姓名验证
if(!req.body.name){
return error(res,"姓名必须!");
}
var name=req.body.name;
if(name.length<2||name.length>4){
return error(res,"姓名长度参数错误!");
}
//准考证号验证
if(!req.body.id){
return error(res,'准考证号必须!');
}
var id= req.body.id;
if(id.length!=15){
return error(res,"准考证号参数错误!");
}
cet.getGrade(name,id,function (e,g) {
if(e){
return error(res,e);
}
return success(res,"成绩获取成功!",g);
});
});
var server = app.listen(3001, function () {
var host = server.address().address;
var port = server.address().port;
console.log('Example app listening at http://%s:%s', host, port);
});