Skip to content

Commit

Permalink
【待测试】日期获取周课表接口支持教师账号&教师获取课程列表花名册
Browse files Browse the repository at this point in the history
  • Loading branch information
Airmole committed Mar 6, 2024
1 parent 33a871a commit 536c8d6
Show file tree
Hide file tree
Showing 2 changed files with 139 additions and 9 deletions.
30 changes: 21 additions & 9 deletions src/CourseTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,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 @@ -445,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
118 changes: 118 additions & 0 deletions src/Teacher.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<?php

namespace Airmole\TjustbEdusys;

use Airmole\TjustbEdusys\Exception\Exception;

/**
* 教师账号相关功能
*/
class Teacher extends Base
{
/**
* 初始化
* @throws Exception
*/
public function __construct(string $usercode = '', string $cookie = '')
{
parent::__construct();
$this->cookie = $cookie;
$this->usercode = $usercode;
if (empty($this->cookie)) throw new Exception('cookie不得为空');
if (empty($this->usercode)) throw new Exception('学号参数不得为空');
}

/**
* 查询我的课程列表
* @return array
* @throws Exception
*/
public function courseList(): array
{
$url = '/jsxsd/framework/jsMain_new.jsp?t1=1';
$referer = $this->edusysUrl . '/jsxsd/framework/jsMain.jsp';
$html = $this->httpGet($url, $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->formatCourseList($html['data']);
}

/**
* 匹配解析我的课程列表
* @param string $html
* @return array
*/
public function formatCourseList(string $html): array
{
preg_match_all('/list-group-item.*?<\/span>/s', $html, $courseListHtmls);
$courseListHtmls = $courseListHtmls ? $courseListHtmls[0] : [];

$courses = [];
foreach ($courseListHtmls as $courseListHtml) {
preg_match('/title="(.*?)"/', $courseListHtml, $title);
$title = $title ? $title[1] : '';

preg_match('/>课堂名称:(.*?)</', $courseListHtml, $className);
$className = $className ? $className[1] : '';

preg_match('/frdy_laosha\(\'(.*?)\'/', $courseListHtml, $queryCode);
$queryCode = $queryCode ? $queryCode[1] : '';
$courses[] = [
'title' => $title,
'className' => $className,
'queryCode' => $queryCode,
];
}

return $courses;
}

/**
* 查询学生花名册
* @param string $queryCode
* @return array
* @throws Exception
*/
public function queryStudentList(string $queryCode): array
{
if (empty($queryCode)) throw new Exception('查询码不得为空');
$referer = $this->edusysUrl . '/jsxsd/framework/jsMain.jsp';
$url = "/jsxsd/framework/jsMain_hmc.jsp?jx0404id={$queryCode}";
$html = $this->httpGet($url, $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->formatStudentList($html['data']);
}

/**
* 匹配解析学生花名册
* @param string $html
* @return array
*/
public function formatStudentList(string $html): array
{
preg_match_all('/<tr>(.*?)<\/tr>/',$html,$rows);
$rows = $rows ? $rows[0] : [];

$studentList = [];
foreach ($rows as $index => $row) {
if ($index == 0) continue;
$tempArray = explode("</td>",$row);
$studentList[] = [
'no' => $tempArray[0],
'major' => $tempArray[1],
'profession' => $tempArray[2],
'grade' => $tempArray[3],
'className' => $tempArray[4],
'usercode' => $tempArray[5],
'name' => $tempArray[6],
'gender' => $tempArray[7],
];
}

return $studentList;
}

}

0 comments on commit 536c8d6

Please sign in to comment.