flutter_chaoxing 0.2.1
flutter_chaoxing: ^0.2.1 copied to clipboard
Typed Chaoxing (学习通) protocol clients for Dart: request signing, device registration, passport2 login, classroom sign-in across all nine sign flavours, and a solver for the captcha.chaoxing.com slider captcha.
example/main.dart
import 'package:flutter_chaoxing/flutter_chaoxing.dart';
/// Minimal end-to-end sketch: log in, list courses, list the sign-capable
/// activities of the first course, and build the device-registration payload.
///
/// The package performs no persistence; a real host application owns the
/// credential store and wires these clients into its own state management.
Future<void> main() async {
final auth = ChaoxingAuthService();
// 1. Log in with a password. The returned session carries the cookie jar
// replayed on every later call, plus the server-issued clientId when a
// deviceInfo payload was posted with the SSO follow.
final session = await auth.login(
const ChaoxingCredentials(account: 'student', password: 'secret'),
);
print('signed in as puid=${session.puid} fid=${session.fid}');
// 2. A stable per-installation device id. The official client persists a
// dashless UUID v4 and reuses it for the UA suffix, the deviceInfo
// payload, and the Fanya sign phoneId. Generate once, never rotate.
final uniqueId = ChaoxingSignCrypto.newUniqueId();
// 3. Build the device-registration payload the SSO call expects. In a full
// flow this is passed to `auth.login(..., deviceInfo: payload)` so the
// server returns a clientId, which `resolveDeviceIdentity` turns into the
// cxcid/sc pair that cxsign and CLIENT_FORM_SIGN need.
final deviceInfo = ChaoxingSignService.buildDeviceInfoPayload(
ChaoxingDeviceProfile(
deviceId: uniqueId,
appName: 'ChaoXingStudy',
appVer: '7.0.2',
osVer: '14',
osLang: 'zh',
cpuArch: 'arm64-v8a',
resolution: '1080x2400',
dpi: '440',
brand: 'google',
hardware: 'shiba',
board: 'shiba',
),
);
print('deviceInfo payload: ${deviceInfo.length} chars (base64 RSA)');
// 4. List enrolled courses, then the activities of the first one. Filtering
// on `isWebViewDriven` isolates the sign-ins: the official client opens
// those in a WebView and answers the CLIENT_FORM_SIGN bridge rather than
// posting a native submit.
final sign = ChaoxingSignService();
final courses = await sign.listCourses(session);
if (courses.isNotEmpty) {
final course = courses.first;
final missions = await sign.listMissions(
session,
courseId: course.courseId,
classId: course.classId,
);
final signIns = missions.where((m) => m.isWebViewDriven).toList();
print('${course.courseName}: ${signIns.length} sign-in activities');
}
// 5. The broader student data surface (notices, grades, homework, live).
final api = ChaoxingApiService();
final notices = await api.fetchNotices(session, pageSize: 5);
print('${notices.totalCount} notices, ${notices.notices.length} on page 1');
}