fix: 心跳摘要改为在线 GetEncryptRequest 不再写死密钥

This commit is contained in:
2026-11-15 01:40:12 +08:00
parent caa79d79b7
commit ecd774507f
5 changed files with 344 additions and 56 deletions
+11 -13
View File
@@ -24,7 +24,7 @@ from datetime import datetime, timezone
import httpx
from sqlalchemy import select
from euniv.client import EUNIV, STUDY_API, USER_AGENT, EunivClient, SessionExpired, study_encryption
from euniv.client import EUNIV, STUDY_API, USER_AGENT, EunivClient, SessionExpired, _load_cookies
from euniv.models import Account, Course
from euniv.study_window import window_open
@@ -100,10 +100,6 @@ def _jitter(seconds: int) -> float:
return max(5.0, seconds + delta)
def _scorm_md5(body_json: str) -> str:
return study_encryption(body_json)
def _parse_minutes(value: str) -> int:
if not value:
return 0
@@ -194,8 +190,7 @@ class StudySession:
proxy=self._proxy,
headers={"User-Agent": USER_AGENT},
)
for name, value, domain, path in self._initial_cookies:
self._client.cookies.set(name, value, domain=domain, path=path)
_load_cookies(self._client, self._initial_cookies)
return self
async def __aexit__(self, *args: object) -> None:
@@ -246,7 +241,11 @@ class StudySession:
return resp.json()
async def get_encrypt_request(self, body_json: str) -> str:
return study_encryption(body_json)
from euniv.encrypt import fetch_encryption_async
assert self._client is not None
return await fetch_encryption_async(
self._client, body_json, origin=EUNIV, user_agent=USER_AGENT
)
async def submit_video_heartbeat(self, kid: str, pkg_id: str,
study_time: int, view_schedule: int) -> dict:
@@ -295,11 +294,8 @@ class StudySession:
"end": end, "care": True, "deviceId": "",
"studyChapterIds": sco_id, "viewSchedule": 0,
}
if end:
encryption = _scorm_md5(json.dumps(param, separators=(",", ":")))
else:
encrypt_body = json.dumps(param, separators=(",", ":"))
encryption = await self.get_encrypt_request(encrypt_body)
encrypt_body = json.dumps(param, separators=(",", ":"))
encryption = await self.get_encrypt_request(encrypt_body)
param["multiple"] = 1
param["realHour"] = study_time
await self._api("POST", f"{STUDY_API}/v1/study/submit?encryption={encryption}",
@@ -332,6 +328,8 @@ class StudySession:
headers={"User-Agent": USER_AGENT, "Referer": EUNIV + "/"},
)
html = resp.text
from euniv.encrypt import note_play_html
note_play_html(html, EUNIV)
def _var(name: str, default: str = "") -> str:
m = re.search(rf'(?:var\s+)?{name}\s*=\s*["\']?([^"\';\r\n]+)', html)