Skip to content

Commit

Permalink
支持教师查询授课列表&学生花名册
Browse files Browse the repository at this point in the history
  • Loading branch information
Airmole committed Mar 7, 2024
1 parent 536c8d6 commit 07d57e8
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 12 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
102 changes: 101 additions & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
- [教学地点列表](#教学地点列表)
- [教室状态查询及详情所需参数](#教室状态查询及详情所需参数)
- [获取教室借用详情信息](#获取教室借用详情信息)
- [教师授课列表获取](#教师授课列表获取)
- [教师查询学生花名册](#教师查询学生花名册)

---

Expand Down Expand Up @@ -7908,4 +7910,102 @@ echo json_encode($list);
]
```

</details>
</details>

---

### 教师授课列表获取

> 仅教师账号可使用此方法,获取授课列表
方法:`teacherCourseList()`

调用示例:

```php
use Airmole\TjustbEdusys\Edusys;

$usercode = '1234'; // 教师账号
$password = '*********'; // 系统密码
$edusys = new Edusys();
$edusys->autoLogin($usercode, $password);
$list = $edusys->teacherCourseList();
echo json_encode($list);
```

<details>
<summary>返回参数示例</summary>

```json
[
{
"title": "XXXX(H01312344)[10102]",
"className": "XX2202班",
"queryCode": "2023XXXXXXXXXX0"
},
{
"title": "XXXX(H01312344)[10304]",
"className": "XX2202班",
"queryCode": "2023XXXXXXXXXX0"
}
]
```

</details>

---

### 教师查询学生花名册

> 仅教师账号可用,传入教师授课列表接口返回的queryCode,获取课堂学生花名册
方法:`classroomList()`

所需参数:

| para | type | nullable | default | tips |
| ---- | ------ |:--------:| --------- | ------------------------------------- |
| code | string || null | 传入教师授课列表接口返回的queryCode |

调用示例:

```php
use Airmole\TjustbEdusys\Edusys;

$usercode = '1234'; // 系统账号
$password = '*********'; // 系统密码
$edusys = new Edusys();
$edusys->autoLogin($usercode, $password);
$list = $edusys->teacherQueryStudentList('2023XXXXXXXXXX0');
echo json_encode($list);
```

<details>
<summary>返回参数示例</summary>

```json
[
{
"no": "1",
"major": "XXXXX系",
"profession": "视觉传达设计",
"grade": "2023",
"className": "视传230X",
"usercode": "23621XXXX",
"name": "陈**",
"gender": ""
},
{
"no": "2",
"major": "XXXXX系",
"profession": "视觉传达设计",
"grade": "2023",
"className": "视传230X",
"usercode": "23621XXXX",
"name": "陈**",
"gender": ""
}
]
```

</details>
24 changes: 24 additions & 0 deletions src/Edusys.php
Original file line number Diff line number Diff line change
Expand Up @@ -590,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);
}

}
23 changes: 12 additions & 11 deletions src/Teacher.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function __construct(string $usercode = '', string $cookie = '')
$this->cookie = $cookie;
$this->usercode = $usercode;
if (empty($this->cookie)) throw new Exception('cookie不得为空');
if (empty($this->usercode)) throw new Exception('学号参数不得为空');
if (empty($this->usercode)) throw new Exception('账号参数不得为空');
}

/**
Expand All @@ -45,7 +45,7 @@ public function courseList(): array
*/
public function formatCourseList(string $html): array
{
preg_match_all('/list-group-item.*?<\/span>/s', $html, $courseListHtmls);
preg_match_all('/list-group-item.*?&nbsp;/s', $html, $courseListHtmls);
$courseListHtmls = $courseListHtmls ? $courseListHtmls[0] : [];

$courses = [];
Expand Down Expand Up @@ -79,6 +79,7 @@ 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']);
Expand All @@ -93,22 +94,22 @@ public function queryStudentList(string $queryCode): array
*/
public function formatStudentList(string $html): array
{
preg_match_all('/<tr>(.*?)<\/tr>/',$html,$rows);
preg_match_all('/<tr>(.*?)<\/tr>/s',$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],
'no' => $this->stripHtmlTagAndBlankspace($tempArray[0]),
'major' => $this->stripHtmlTagAndBlankspace($tempArray[1]),
'profession' => $this->stripHtmlTagAndBlankspace($tempArray[2]),
'grade' => $this->stripHtmlTagAndBlankspace($tempArray[3]),
'className' => $this->stripHtmlTagAndBlankspace($tempArray[4]),
'usercode' => $this->stripHtmlTagAndBlankspace($tempArray[5]),
'name' => $this->stripHtmlTagAndBlankspace($tempArray[6]),
'gender' => $this->stripHtmlTagAndBlankspace($tempArray[7]),
];
}

Expand Down

0 comments on commit 07d57e8

Please sign in to comment.