Skip to content

Commit

Permalink
Merge pull request #12 from Airmole/airmole
Browse files Browse the repository at this point in the history
v1.1.0 支持教师身份
  • Loading branch information
Airmole authored Mar 7, 2024
2 parents 3edb929 + 07d57e8 commit e5e0063
Show file tree
Hide file tree
Showing 11 changed files with 513 additions and 49 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ print_r($score);
- [教学地点列表](docs/api.md#教学地点列表)
- [教室状态查询及详情所需参数](docs/api.md#教室状态查询及详情所需参数)
- [获取教室借用详情信息](docs/api.md#获取教室借用详情信息)
- [教师授课列表获取](docs/api.md#教师授课列表获取)
- [教师查询学生花名册](docs/api.md#教师查询学生花名册)

## 适用学校系统

Expand Down
133 changes: 129 additions & 4 deletions docs/api.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/ClassCourseTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct(string $usercode = '', string $cookie = '')
*/
public function options(): array
{
$referer = $this->edusysUrl . '/jsxsd/framework/xsMain.jsp';
$referer = $this->edusysUrl . ($this->isStudent($this->usercode) ? '/jsxsd/framework/xsMain.jsp' : '/jsxsd/framework/jsMain.jsp');
$html = $this->httpGet('/jsxsd/kbcx/kbxx_xzb', $this->cookie, $referer, 50);
$vaildHtml = $this->checkCookieByHtml($html['data']);
if ($vaildHtml !== true) throw new Exception($vaildHtml['data']);
Expand Down
2 changes: 1 addition & 1 deletion src/Classroom.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct(string $usercode = '', string $cookie = '')
*/
public function options(): array
{
$referer = $this->edusysUrl . '/jsxsd/framework/xsMain.jsp';
$referer = $this->edusysUrl . ($this->isStudent($this->usercode) ? '/jsxsd/framework/xsMain.jsp' : '/jsxsd/framework/jsMain.jsp');
$html = $this->httpGet('/jsxsd/kbxx/jsjy_query', $this->cookie, $referer);
$vaildHtml = $this->checkCookieByHtml($html['data']);
if ($vaildHtml !== true) throw new Exception($vaildHtml['data']);
Expand Down
117 changes: 99 additions & 18 deletions src/CourseTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ public function __construct(string $usercode = '', string $cookie = '')
*/
public function myCourseQueryOptions(): array
{
$referer = $this->edusysUrl . '/jsxsd/framework/xsMain.jsp';
$html = $this->httpGet('/jsxsd/xskb/xskb_list.do', $this->cookie, $referer);
$referer = $this->edusysUrl . ($this->isStudent($this->usercode) ? '/jsxsd/framework/xsMain.jsp' : '/jsxsd/framework/jsMain.jsp');
$url = $this->isStudent($this->usercode) ? '/jsxsd/xskb/xskb_list.do' : '/jsxsd/jskb/jskb_list.do';
$html = $this->httpGet($url, $this->cookie, $referer);
$vaildHtml = $this->checkCookieByHtml($html['data']);
if ($vaildHtml !== true) throw new Exception($vaildHtml['data']);
if ($html['code'] !== self::CODE_SUCCESS) throw new Exception('获取失败');
Expand Down Expand Up @@ -86,12 +87,17 @@ public function formatMyCourseQueryOptions(string $html): array
public function semesterCourse(string $week = '', string $semester = ''): array
{
$post = "zc={$week}&xnxq01id={$semester}";
$referer = $this->edusysUrl . '/jsxsd/xskb/xskb_list.do';
$html = $this->httpPost('/jsxsd/xskb/xskb_list.do', $post, $this->cookie, $referer);
$vaildHtml = $this->checkCookieByHtml($html['data']);
if ($vaildHtml !== true) throw new Exception($vaildHtml['data']);
if ($this->isStudent($this->usercode)) {
$referer = $this->edusysUrl . '/jsxsd/xskb/xskb_list.do';
$html = $this->httpPost('/jsxsd/xskb/xskb_list.do', $post, $this->cookie, $referer);
} else {
$referer = $this->edusysUrl . '/jsxsd/jskb/jskb_list.do';
$html = $this->httpPost('/jsxsd/jskb/jskb_list.do', $post, $this->cookie, $referer);
}
$validHtml = $this->checkCookieByHtml($html['data']);
if ($validHtml !== true) throw new Exception($validHtml['data']);
if ($html['code'] !== self::CODE_SUCCESS) throw new Exception('获取失败');
return $this->formatMyCourse($html['data']);
return $this->formatMyCourse($html['data'], $this->isTeacher($this->usercode));
}

/**
Expand Down Expand Up @@ -155,7 +161,11 @@ public function formatMyCourse(string $html): array
$cellHtml = $cellHtml ? $cellHtml[0] : '';
// 非课程单元格
if (empty($cellHtml)) continue;
$coursesList[] = $this->formatCellHtmlCourse($cellHtml, $startAt, $endAt);
if ($this->isStudent($this->usercode)) {
$coursesList[] = $this->formatStudentCellHtmlCourse($cellHtml, $startAt, $endAt);
} else {
$coursesList[] = $this->formatTeacherCellHtmlCourse($cellHtml, $startAt, $endAt);
}
}
}

Expand Down Expand Up @@ -193,7 +203,7 @@ public function getSelectedWeekValue(string $html): string
* @param string $endAt 下课时间
* @return array
*/
public function formatCellHtmlCourse(string $html, string $startAt = '', string $endAt = ''): array
public function formatStudentCellHtmlCourse(string $html, string $startAt = '', string $endAt = ''): array
{
// 空课程单元格
if (empty($this->stripHtmlTagAndBlankspace($html))) return [];
Expand Down Expand Up @@ -237,6 +247,65 @@ public function formatCellHtmlCourse(string $html, string $startAt = '', string
return $courses;
}

/**
* 解析匹配教师课表单元格内课程信息
* @param string $html
* @param string $startAt
* @param string $endAt
* @return array
*/
public function formatTeacherCellHtmlCourse(string $html, string $startAt = '', string $endAt = ''): array
{
// 空课程单元格
if (empty($this->stripHtmlTagAndBlankspace($html))) return [];
// 匹配课程名
preg_match_all('/[r" ]>(.*?)周次?/', $html, $courseNames);
$courseNames = $courseNames ? $courseNames[1] : [];
// 匹配周
preg_match_all('/周次.*?>(.*?)</', $html, $weeks);
$weeks = $weeks ? $weeks[1] : [];
// 匹配教室
preg_match_all('/教室.*?>(.*?)\[/', $html, $places);
$places = $places ? $places[1] : [];
// 匹配节次
preg_match_all('/\[([\d-]*?)]节/', $html, $serialNos);
$serialNos = $serialNos ? $serialNos[1] : [];
// 匹配班级
preg_match_all('/节<\/font><br\/>(.*?):\d*?<br/', $html, $classNames);
$classNames = $classNames ? $classNames[1] : [];
// 匹配上课人数
preg_match_all('/班:(\d*?)<br/', $html, $people);
$people = $people ? $people[1] : [];
// 匹配考核方式
preg_match_all('/:\d*?<br\/>(.*?)<br\/>总学时/', $html, $accessMethod);
$accessMethod = $accessMethod ? $accessMethod[1] : [];
// 总学时
preg_match_all('/>总学时:(\d*?)</', $html, $period);
$period = $period ? $period[1] : [];

$courses = [];
foreach ($courseNames as $index => $courseName) {
$courseName = $this->stripHtmlTagAndBlankspace($courseName);
// P备注带括号,否则容易出现 xxx学P,例如:康复护理学P
$courseName = preg_replace('/P$/', '(P)', $courseName);
$courseName = preg_replace('/O$/', '(O)', $courseName);
$item = [
'courseName' => $courseName,
'teachWeek' => isset($weeks[$index]) ? (string)$weeks[$index] : '',
'teachNo' => isset($serialNos[$index]) ? (string)$serialNos[$index] : '',
'place' => isset($places[$index]) ? (string)$places[$index] : '',
'className' => isset($classNames[$index]) ? (string)$classNames[$index] : '',
'people' => isset($people[$index]) ? (string)$people[$index] : '',
'accessMethod' => isset($accessMethod[$index]) ? (string)$accessMethod[$index] : '',
'period' => isset($period[$index]) ? (string)$period[$index] : '',
];
if (!empty($startAt)) $item['startAt'] = $startAt;
if (!empty($endAt)) $item['endAt'] = $endAt;
$courses[] = $item;
}
return $courses;
}

/**
* 按星期分类课表
* @param array $coursesList 6x7列表课表
Expand Down Expand Up @@ -265,7 +334,7 @@ public function dateCourse(string $date = ''): array
{
if (empty($date)) $date = date('Y-m-d');
$post = "rq={$date}";
$referer = $this->edusysUrl . '/jsxsd/framework/xsMain_new.jsp?t1=1';
$referer = $this->edusysUrl . ($this->isStudent($this->usercode) ? '/jsxsd/framework/xsMain_new.jsp?t1=1' : '/jsxsd/framework/jsMain_new.jsp?t1=1');
$html = $this->httpPost('/jsxsd/framework/main_index_loadkb.jsp', $post, $this->cookie, $referer);
$vaildHtml = $this->checkCookieByHtml($html['data']);
if ($vaildHtml !== true) throw new Exception($vaildHtml['data']);
Expand Down Expand Up @@ -376,33 +445,45 @@ public function formatDateCellHtmlCourse(string $html, string $startAt = '', str
preg_match('/课程属性:(.*?)课程名称/', $html, $classType);
$classType = $classType ? $classType[1] : '';

preg_match('/课程名称:(.*?)上课时间/', $html, $courseName);
$courseName = $courseName ? $courseName[1] : '';

preg_match('/上课时间:(.*?)上课地点/', $html, $teachTime);
$teachTime = $teachTime ? $teachTime[1] : '';

preg_match('/上课时间:(.*?)星期/', $html, $teachWeek);
$teachWeek = $teachWeek ? $teachWeek[1] : '';

preg_match('/上课时间.*? (.*?) .*?上课地点/', $html, $dayOfWeek);
$dayOfWeek = $dayOfWeek ? $dayOfWeek[1] : '';

preg_match('/上课时间.*?\[(.*?)\]节/', $html, $teachNo);
preg_match('/上课时间.*?\[(.*?)]节/', $html, $teachNo);
$teachNo = $teachNo ? $teachNo[1] : '';

preg_match('/上课地点:(.*?)\'.*?>/', $html, $place);
$place = $place ? $place[1] : '';

preg_match('/上课时间.*? (.*?) .*?上课地点/', $html, $dayOfWeek);
$dayOfWeek = $dayOfWeek ? $dayOfWeek[1] : '';

$course = [
'courseName' => $courseName,
'teachTime' => $teachTime,
'teachWeek' => $teachWeek,
'teachNo' => $teachNo,
'place' => $place,
'dayOfWeek' => $dayOfWeek
];

if ($this->isStudent($this->usercode)) {
preg_match('/课程名称:(.*?)上课时间/', $html, $courseName);
$courseName = $courseName ? $courseName[1] : '';

$course['courseName'] = $courseName;
} else {
preg_match('/课程名称:(.*?)上课班级/', $html, $courseName);
$courseName = $courseName ? $courseName[1] : '';

preg_match('/上课班级:(.*?)上课时间/', $html, $className);
$className = $className ? $className[1] : '';

$course['courseName'] = $courseName;
$course['className'] = $className;
}

if (!empty($startAt)) $course['startAt'] = $startAt;
if (!empty($endAt)) $course['endAt'] = $endAt;

Expand Down
41 changes: 38 additions & 3 deletions src/Edusys.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,24 @@ class Edusys
*/
public string $cookie;

/**
* @var string 登录模式: new,old
*/
public string $mode;

public function __construct(string $mode = 'new')
{
if (empty($this->mode)) $this->mode = $mode;
}

/**
* 获取登录所需参数
* @return array
* @throws Exception
*/
public function getLoginPara(): array
{
$login = new Login();
$login = new Login($this->mode);
return $login->getLoginPara();
}

Expand All @@ -40,7 +51,7 @@ public function getLoginPara(): array
*/
public function selfLogin(string $usercode, string $password, string $captcha, string $cookie): array
{
$login = new Login();
$login = new Login($this->mode);
$result = $login->login($usercode, $password, $captcha, $cookie);
if ($result['code'] === Base::CODE_SUCCESS) {
$this->usercode = $usercode;
Expand All @@ -59,7 +70,7 @@ public function selfLogin(string $usercode, string $password, string $captcha, s
*/
public function autoLogin(string $usercode, string $password, int $retry = 1): array
{
$login = new Login();
$login = new Login($this->mode);
$result = $login->autoLogin($usercode, $password, $retry);
if ($result['code'] === Base::CODE_SUCCESS) {
$this->usercode = $usercode;
Expand Down Expand Up @@ -579,4 +590,28 @@ public function classroomDetail(
);
}

/**
* 教师查询授课列表
* @throws Exception
*/
public function teacherCourseList(): array
{
if (empty($this->usercode) || empty($this->cookie)) throw new Exception('账号未登录');
$teacher = new Teacher($this->usercode, $this->cookie);
return $teacher->courseList();
}

/**
* 教师查询学生花名册
* @param string $queryCode 查询码
* @return array
* @throws Exception
*/
public function teacherQueryStudentList(string $queryCode): array
{
if (empty($this->usercode) || empty($this->cookie)) throw new Exception('账号未登录');
$teacher = new Teacher($this->usercode, $this->cookie);
return $teacher->queryStudentList($queryCode);
}

}
2 changes: 1 addition & 1 deletion src/LessonCourseTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct(string $usercode = '', string $cookie = '')
*/
public function options(): array
{
$referer = $this->edusysUrl . '/jsxsd/framework/xsMain.jsp';
$referer = $this->edusysUrl . ($this->isStudent($this->usercode) ? '/jsxsd/framework/xsMain.jsp' : '/jsxsd/framework/jsMain.jsp');
$html = $this->httpGet('/jsxsd/kbcx/kbxx_kc', $this->cookie, $referer);
$vaildHtml = $this->checkCookieByHtml($html['data']);
if ($vaildHtml !== true) throw new Exception($vaildHtml['data']);
Expand Down
Loading

0 comments on commit e5e0063

Please sign in to comment.