flutter_chaoxing 0.1.1
flutter_chaoxing: ^0.1.1 copied to clipboard
Typed Chaoxing (学习通) protocol clients, request signing, and classroom sign-in for Dart.
flutter_chaoxing #
Typed Chaoxing (学习通) protocol clients, request signing, and classroom sign-in
for Dart and Flutter. Every routine is a byte-exact port of the official
Android client 7.0.2, recovered from the decompiled sources in the
chaoxing-re research repo; the inline
citations in the source give the exact file:line each constant and algorithm
came from.
This package is an independent community project and is not affiliated with Chaoxing, 超星, or any 学习通 operator.
Features #
- Three request-signing schemes, ported exactly and never interchanged:
inf_encquery signing (both the declared-orderjui.V/Wvariant and the sorted-key OkHttp interceptor variant).cxsign/signTokenheader signing (sortedkey + valueconcatenation plus a per-installation secret).webRequestSign— the RSA-SHA256 half of theCLIENT_FORM_SIGNJS bridge, with the obfuscated private key extracted fromlibsecuritylib.so.
- Device registration:
CxDevice.getDeviceInfo/decryptDeviceInfo(chunked RSA, jsoncppFastWriteralignment, millisecond timestamps). - Login: passport2 password and SMS flows, AES-ECB
logininfo, manual SSO redirect walking, andclientIdharvest. - Classroom sign-in: the activity/mission surface, the native Fanya
usersign/addsignendpoint, and a fullCLIENT_FORM_SIGNimplementation. - Student data API: notices, grades, homework feed, live classes, course content, timetable, messages, and discussions.
- Typed domain models mirroring the official
StudentMission,Course, andClazzschemas, plus theactiveTypedispatch table.
The load-bearing finding #
The official Android client has no native sign-submit endpoint.
StudentMissionFragment.H9 dispatches a handful of activeTypes natively and
sends everything else — all sign flavours — to a WebView pointed at the
server-supplied mission.url. The words otherId, ifphoto,
ifopenAddress, ifrefreshewm, and signCode appear nowhere in the 69,685
recovered classes: they belong to the H5 page's own protocol, not to the app.
What the app does contribute to a sign is two JS bridges — CLIENT_FORM_SIGN
(RSA-signs the page's form fields) and CLIENT_USER_LOCATION (supplies GPS).
An implementation that wants official parity therefore drives the H5 page and
answers those bridges rather than inventing a submit URL.
ChaoxingSignService.handleFormSign is that bridge.
The one exception is the scanned Fanya code, which the client submits natively
via usersign/addsign — see submitFanyaSign.
Installation #
dart pub add flutter_chaoxing
For Flutter applications:
flutter pub add flutter_chaoxing
The package is pure Dart (no Flutter SDK dependency) and uses dio for HTTP,
so it runs on Android, iOS, Linux, macOS, Windows, and the web (subject to
CORS for the web).
Usage #
Log in #
import 'package:flutter_chaoxing/flutter_chaoxing.dart';
final auth = ChaoxingAuthService();
final session = await auth.login(
const ChaoxingCredentials(account: 'student', password: 'secret'),
);
// session.cookieHeader is replayed on every later call.
SMS login reuses the same call after auth.sendSmsCode(phone), with the code
in the password field and mode: ChaoxingLoginMode.sms.
When the server demands interactive verification it raises
ChaoxingCaptchaRequired; there is no headless bypass.
Device identity #
The cxsign secret is not a constant in the APK — it is issued per
installation. To obtain it, post a deviceInfo payload with the SSO follow so
the server returns a clientId, then resolve it:
final uniqueId = ChaoxingSignCrypto.newUniqueId(); // persist this!
final payload = ChaoxingSignService.buildDeviceInfoPayload(
ChaoxingDeviceProfile(deviceId: uniqueId, /* …hardware fields… */),
);
final session = await auth.login(credentials, deviceInfo: payload);
if (session.hasDeviceIdentity) {
final identity =
ChaoxingSignService.resolveDeviceIdentity(session.clientId);
// identity.cxcid / identity.sc feed cxsign and CLIENT_FORM_SIGN.
}
uniqueId is a dashless UUID v4 that the official client generates once and
reuses forever. Persist it (secure storage) and never rotate it — changing it
makes the server see a "new device".
List courses and sign-in activities #
final sign = ChaoxingSignService();
final courses = await sign.listCourses(session);
final missions = await sign.listMissions(
session,
courseId: courses.first.courseId,
classId: courses.first.classId,
);
final signIns = missions.where((m) => m.isWebViewDriven);
Answer the CLIENT_FORM_SIGN bridge #
When driving the H5 sign page in a WebView, intercept the bridge and return
handleFormSignJson verbatim:
final tokens = sign.handleFormSignJson(
rawJsonFromPage,
identity, // ChaoxingDeviceIdentity from resolveDeviceIdentity
);
// hand `tokens` back to the page's JS callback
Student data API #
final api = ChaoxingApiService();
final notices = await api.fetchNotices(session, pageSize: 20);
final unread = await api.fetchUnreadNoticeCount(session);
final tasks = await api.fetchTaskFeed(session, userid: session.puid);
final live = await api.fetchOngoingLive(session);
See lib/src/chaoxing_api_service.dart for the full surface: grades
(fetchSelfScoreDetail, fetchExamList, fetchWorkList), homework
(fetchUnfinishedJobs), live classes (fetchLiveDetail), course content
(fetchChapterTree, fetchKnowledgeCards), timetable (fetchLesson),
messages, and discussions.
API Overview #
| Type | Purpose |
|---|---|
ChaoxingAuthService |
passport2 login, SMS, SSO cookie harvest |
ChaoxingSignService |
Classroom activities, sign-in, CLIENT_FORM_SIGN, Fanya submit |
ChaoxingApiService |
Notices, grades, homework, live, courses, timetable, messages |
ChaoxingSignCrypto |
The three signing schemes, device RSA, jsoncpp alignment |
ChaoxingSession |
Cookie jar + parsed identity + clientId |
ChaoxingCredentials |
Account/password or phone/SMS pair |
ChaoxingCourse / ChaoxingMission |
Official course and activity schemas |
ChaoxingDeviceProfile / ChaoxingDeviceIdentity |
Device registration in, cxcid/sc out |
ChaoxingFormSignRequest / ChaoxingFormSignTokens |
The CLIENT_FORM_SIGN bridge contract |
ChaoxingFanyaSignResult / ChaoxingFanyaSignCode |
Native Fanya submit outcome |
ChaoxingLogger |
Injectable diagnostics sink (replaces debugPrint) |
Integration boundary #
The package owns the protocol: HTTP, signing, parsing, and typed models. The host application owns everything stateful:
- Credential/session persistence — store
ChaoxingSessionin secure storage; the package never touches disk. uniqueIdpersistence — generate once viaChaoxingSignCrypto .newUniqueId(), persist, and pass it into device registration and Fanya signs.- Dependency injection — construct the services yourself (or wire them into Riverpod/Bloc/providers as you see fit).
- Logging — inject a
ChaoxingLogger(e.g.debugPrint) intoChaoxingAuthServiceandChaoxingSignService. - WebView driving — the H5 sign page and the
CLIENT_FORM_SIGN/CLIENT_USER_LOCATIONbridges are the host's responsibility.
Security And Compatibility #
- Do not commit passwords, cookies,
clientId, or thecxcid/scpair. - The
cxsignsecret is per-installation; never hardcode a captured one. - Endpoints and constants are pinned to client 7.0.2. Chaoxing rotates these periodically — re-verify against a current capture before relying on them.
- Several device-fingerprint fields (
mediaDrmId,cdtype,cdid,platform/os_name) are built inside JNI and were not recoverable; they are modelled as caller-supplied and omitted when unset, never faked. - Test against a disposable account before enabling any write path.
Development #
dart format lib test example
dart analyze
dart test
dart pub publish --dry-run
License #
MIT. See LICENSE.