3
3
using System . Linq ;
4
4
using System . Net ;
5
5
using System . Net . Http ;
6
+ using System . Net . Http . Json ;
6
7
using System . Net . Sockets ;
7
8
using System . Text . RegularExpressions ;
8
9
using System . Threading . Tasks ;
@@ -168,29 +169,18 @@ public async Task<Schedule> GetScheduleAsync(string username, string termId, ISi
168
169
throw new ArgumentException ( "Sign in context is not for undergraduate." ) ;
169
170
}
170
171
171
- HttpRequestMessage request = new HttpRequestMessage ( HttpMethod . Post , "https://my.cqu.edu.cn/api/enrollment/enrollment-batch/user-switch-batch" ) ;
172
- request . Content = new FormUrlEncodedContent ( new [ ]
173
- {
174
- new KeyValuePair < string , string > ( "sessionId" , termId )
175
- } ) ;
176
- request . Headers . Authorization = new System . Net . Http . Headers . AuthenticationHeaderValue ( "Bearer" , token ) ;
177
- HttpResponseMessage response = await httpClient . SendAsync ( request ) ;
178
- response . EnsureSuccessStatusCode ( ) ;
179
-
180
172
string examStudentId = examStudentIdService . GetExamStudentId ( username ) ;
181
173
Task < HttpResponseMessage > examTask = httpClient . GetAsync ( $ "https://my.cqu.edu.cn/api/exam/examTask/get-student-exam-list-outside?studentId={ examStudentId } ") ;
182
174
183
- request = new HttpRequestMessage ( HttpMethod . Get , $ "https://my.cqu.edu.cn/api/enrollment/timetable/student/{ username } ") ;
175
+ var request = new HttpRequestMessage ( HttpMethod . Post , $ "https://my.cqu.edu.cn/api/timetable/class/timetable/student/my-table-detail?sessionId={ termId } ") ;
176
+ request . Content = JsonContent . Create < string [ ] > ( [ username ] ) ;
184
177
request . Headers . Authorization = new System . Net . Http . Headers . AuthenticationHeaderValue ( "Bearer" , token ) ;
185
- response = await httpClient . SendAsync ( request ) ;
178
+ HttpResponseMessage response = await httpClient . SendAsync ( request ) ;
186
179
var responseModel = await UpstreamScheduleResponseModelSerializerContext . Default . DeserializeFromStringAsync ( await response . Content . ReadAsStreamAsync ( ) ) ;
187
180
Schedule schedule = new Schedule ( username ) ;
188
- if ( ! responseModel . Status . Equals ( "success" , StringComparison . Ordinal ) || responseModel . Data == null )
181
+ if ( responseModel . Data == null )
189
182
{
190
- throw new UpstreamRequestException ( "Upstream server did not return success status for schedule request." )
191
- {
192
- ErrorDescription = responseModel . Message
193
- } ;
183
+ throw new UpstreamRequestException ( "Upstream server did not return success status for schedule request." ) ;
194
184
}
195
185
foreach ( var responseEntry in responseModel . Data )
196
186
{
@@ -201,9 +191,22 @@ public async Task<Schedule> GetScheduleAsync(string username, string termId, ISi
201
191
string name = responseEntry . Name ;
202
192
if ( expClassTypes . Contains ( responseEntry . ClassType ) )
203
193
{
194
+ // This is empirically dead code. The site does not return valid ClassType anymore.
204
195
name = name . Contains ( "实验" ) ? name : $ "{ name } 实验";
205
196
}
206
- string lecturer = responseEntry . Lecturers == null ? string . Empty : responseEntry . Lecturers . FirstOrDefault ( ) . Lecturer ;
197
+ string lecturer = string . Empty ;
198
+ if ( ! string . IsNullOrEmpty ( responseEntry . LecturersNotation ) )
199
+ {
200
+ Match lecturerMatch = lecturerExtractionRegex . Match ( responseEntry . LecturersNotation ) ;
201
+ if ( lecturerMatch . Success )
202
+ {
203
+ lecturer = lecturerMatch . Groups [ 1 ] . Value ;
204
+ }
205
+ else
206
+ {
207
+ lecturer = responseEntry . LecturersNotation ;
208
+ }
209
+ }
207
210
ScheduleEntry entry = new ScheduleEntry ( )
208
211
{
209
212
Name = name ,
@@ -406,6 +409,7 @@ private struct SigninInfo
406
409
private readonly IUpstreamCredentialEncryptionService encryptionService ;
407
410
private readonly IExamStudentIdService examStudentIdService ;
408
411
private readonly int vacationServeDays ;
412
+ private static readonly Regex lecturerExtractionRegex = new Regex ( "(.*?)-\\ d" ) ;
409
413
private static readonly Regex roomSimplifyRegex = new Regex ( "(室|机房|中心|分析系统|创新设计|展示与分析).*?-(.*?)$" ) ;
410
414
private static readonly string [ ] expClassTypes = new [ ] { "上机" , "实验" } ;
411
415
}
0 commit comments