本项目是与@nameoverflow同窗合做。该同窗负责vue
前端的设计,我负责php
后台的接口实现。本文将主要记录php
后台。
本项目的Github地址:https://github.com/He11oLiu/Student_Information_management_system
本项目仅做为尝试用途,不少功能还没有实现。
php
PHP
链接MySQL
数据库利用MySQLi
接口库来链接MySQL
数据库,链接测试以下:html
<html>
<body>
<?php
//phpinfo();
$con = mysqli_connect("127.0.0.1","root","","C_test");
if(!$con){
dir('Cannot connect "' . mysql_error());
}
echo "Connect Sucess!";
echo "<br/>";
$result = mysqli_query($con,"Select * from student");
while($row = mysqli_fetch_array($result)){
echo $row['student_no']." ".$row['student_name'];
echo "<br/>";
}
mysqli_close($con);
echo "Cannect Close!";
?>
</body>
</html>
服务器端PHP
提供RESTful
接口的框架主要以下:前端
<?php
session_start();
$func = $_GET['func'];
switch($func){
case 'func1':func1();break;
case 'func2':func2();break;
default: echo 'wrong func code';break;
}
function func1(){
//func1 code
}
function func2(){
//func2 code
}
?>
.
├── adminQuery.php #管理员功能
├── loginFunc.php #登入登出控制
├── studentQuery.php #学生功能
├── teacherQuery.php #老师功能
├── test.py #测试
└── util.php
其中功能的设计大体框架如上RESTful
框架所述,接口定义见接口文件。vue
为了防止出现越权调用接口,每一个功能利用Session
作了权限检测。python
学生/loginFunc.php?func=stuLogin
mysql
老师/loginFunc.php?func=isTeacherLoggedIn
git
管理员/loginFunc.php?func=isTeacherLoggedIn
github
/loginFunc.php?func=isXXXLoggedIn 其中 XXX=Stu | Teacher | Admin
sql
若是用户为学生用户则只能查同班同窗
为管理员则能够查任意学号
教师用户不容许使用shell
参数名 | 类型 | 语义 |
---|---|---|
stuid(可选) | String | 学号,无则返回本身成绩 |
semid(可选) | number | 学期id,无则返回全部条目 |
返回值:
字段名 | 类型 | 语义 |
---|---|---|
cname | String | 课程名 |
cno | String | 课程编号 |
teacher | String | 教师姓名 |
grade | Number | 成绩(百分制) |
/studentQuery.php?func=stuGrade&stuid='201408010115'&semid=2
返回登陆用户的我的信息
返回值:
字段名 | 类型 | 语义 |
---|---|---|
sname | String | 学生姓名 |
/studentQuery.php?func=stuInfo
用户当前可用的选课列表
若是当前不能选课,返回空[]
。
返回值(数组):
字段名 | 类型 | 语义 |
---|---|---|
cid | Number | 课程数据库索引号 |
cno | String | 课程编号 |
cname | String | 课程名 |
teacher | String | 任课教师 |
/studentQuery.php?func=stuSel
/studentQuery.php?func=courseList
返回值:
Course.idCourse,Course.Cno,Course.Cname,Course.Ccredit,Course.Cplace,Course.Cnum,Dept.Dname,Teacher.Tname
参数名 | 类型 | 语义 |
---|---|---|
cid | Number | 课程索引号 |
返回值:
字段名 | 类型 | 语义 |
---|---|---|
status | Number | 0为成功;其它为失败 |
msg | String | 提示信息(失败缘由) |
/studentQuery.php?func=selCourse&cid=3
返回用户指定学期的课程安排列表
参数名 | 类型 | 语义 |
---|---|---|
seid | Number | 学期索引号 |
返回值(数组):
字段名 | 类型 | 语义 |
---|---|---|
cname | String | 课程名 |
cno | String | 课程号 |
teacher | String | 教师名 |
times | [Time] | 时间安排列表 |
其中 Time 格式为
字段名 | 类型 | 语义 |
---|---|---|
day | Number | 一周中的天序号 |
tstart | Number | 第几节课开始 |
tend | Number | 第几节课结束 |
wstart | Number | 开始周数 |
wend | Number | 结束周数 |
sel | Number | 单双周;0 为所有,1 为单周,2 为双周 |
loc | String | 上课地点 |
/studentQuery.php?func=courseTime
返回当前用户入学时间之后全部的学期列表
返回值(数组):
字段名 | 类型 | 语义 |
---|---|---|
year | String | 年份 |
term | String | 春夏秋学期 |
seid | Number | 学期索引id |
url:/student/studentQuery.php?func=classmate
返回值:Sno,Sname
url : /student/teacherQuery.php?func=stuGrade`
返回值: Sno,Sname,Class.Cno,Class.Cyear,Grade
url : /student/teacherQuery.php?func=courseTime
返回值:Course.Cno,Course.Cname,Time.ds,Time.Week,Time.day,Time.section,Building,Room
url:/student/teacherQuery.php?func=updateGrade
字段名 | 类型 | 语义 |
---|---|---|
idcourseset | int | Courseset的索引 |
sno | String | 学生学号 |
grade | int | 学生成绩 |
返回值
status | |
---|---|
0 | 成功 |
-1 | 不成功带msg 字段 |
url:/student/adminQuery.php?func=addStu
POST数据内容:
字段名 | 语义 |
---|---|
sname | 姓名 |
sno | 学号 |
idclass | 班级 能够用getclass获取可选id |
sage | 年龄 |
ssex | 性别 |
iddept | 专业 能够用getdept获取可选dept |
idsemester | 学期 能够用getSemester获取可选学期 |
返回值
status | |
---|---|
0 | 成功 |
-1 | 不成功带msg 字段 |
url:/student/adminQuery.php?func=getSemester
返回值:idSemester,Semyear,Semseason
url:/student/adminQuery.php?func=getClass&iddept=1
iddept为获取的专业
返回值:idClass,Cno,Cyear,Dept_idDept
url:/student/adminQuery.php?func=getSemester
返回值:idSemester,Semyear,Semseason
利用Python
写了接口测试脚本,相似以下:
import urllib2
import urllib
import cookielib
##########################
# student test #
##########################
print ('=========student test==========')
data = {}
data['sno'] = '201408010113'
data['spd'] = '123'
post_data = urllib.urlencode(data)
cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
print('Check Login Status...')
resp = opener.open("http://localhost/student/loginFunc.php?func=isStuLoggedIn")
print (resp.read() )
print ('\n')
详细见源代码。