From 3a47ae4aa40bb59e8a609958b153bfa26a0af439 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=9F=E9=9B=A8?= <89396931+NCJOAQ@users.noreply.github.com> Date: Mon, 22 Dec 2025 22:44:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=A4=BA=E4=BE=8B=E8=84=9A?= =?UTF-8?q?=E6=9C=AC=EF=BC=8C=E6=96=B0=E5=A2=9E=E6=B5=8B=E8=AF=95=E8=84=9A?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + get.py => main.py | 19 +++++++++++++++++-- put.py | 32 ++++++++++++++++++++++++++++++++ sign.py | 35 ----------------------------------- 4 files changed, 50 insertions(+), 37 deletions(-) rename get.py => main.py (78%) create mode 100644 put.py delete mode 100644 sign.py diff --git a/README.md b/README.md index 168ecb5..b33eea6 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,7 @@ curl -X PUT \ "https://m-zjt.kefang.net/api/zms/attendance/attendanceRecord/punchCourseByStudent" ``` +您可在项目文件 main.py 中查看示例脚本 返回结果若包含“操作成功”的 `message`,则表示打卡成功。 ## 4. 常见问题 diff --git a/get.py b/main.py similarity index 78% rename from get.py rename to main.py index bc0fa7e..ca51633 100644 --- a/get.py +++ b/main.py @@ -1,6 +1,5 @@ import requests from typing import Optional -from sign import punch # 在脚本顶端维护可用的 token 数组(按顺序尝试) TOKENS = [ @@ -8,12 +7,27 @@ TOKENS = [ ] HOME_URL = "https://m-zjt.kefang.net/api/zms/zhijiaotong/page/homePageData" +PUNCH_URL = "https://m-zjt.kefang.net/api/zms/attendance/attendanceRecord/punchCourseByStudent" + + +def punch(attendance_id: str, token: str) -> requests.Response: + payload = { + "attendanceId": attendance_id + } + headers = { + "User-Agent": "Dart/3.6 (dart:io)", + "Accept-Encoding": "gzip", + "Content-Type": "application/x-www-form-urlencoded", + "content-length": "32", + "Cookie": f"token={token}", + "Host": "m-zjt.kefang.net", + } + return requests.put(PUNCH_URL, data=payload, headers=headers, verify=False) def extract_content_id(payload: dict) -> Optional[str]: data = payload.get("data", {}) # Prefer messages array for attendance - messages = data.get("messages") if isinstance(messages, list): for msg in messages: @@ -34,6 +48,7 @@ def main(): "Accept-Encoding": "gzip", "content-type": "application/x-www-form-urlencoded", "Cookie": f"token={token}", + "host": "m-zjt.kefang.net", } try: diff --git a/put.py b/put.py new file mode 100644 index 0000000..e06ce21 --- /dev/null +++ b/put.py @@ -0,0 +1,32 @@ +from main import punch +import requests + +def debug_punch(attendance_id: str, token: str) -> None: + """ + 调试打卡功能的函数 + + Args: + attendance_id: 考勤ID + token: 用户认证令牌 + """ + print(f"开始调试打卡功能...") + print(f"Attendance ID: {attendance_id}") + print(f"Token: {token}") + + try: + # 调用main.py中的punch函数发送打卡请求 + response = punch(attendance_id, token) + + print(f"请求状态码: {response.status_code}") + print(f"响应内容: {response.text}") + + if response.status_code == 200: + print("打卡成功!") + else: + print("打卡失败!") + + except Exception as e: + print(f"发生异常: {e}") + +# 使用示例 (请替换为实际的值进行测试) +# debug_punch("your_attendance_id_here", "your_token_here") \ No newline at end of file diff --git a/sign.py b/sign.py deleted file mode 100644 index 4693928..0000000 --- a/sign.py +++ /dev/null @@ -1,35 +0,0 @@ -import os -import sys -import requests - -PUNCH_URL = "https://m-zjt.kefang.net/api/zms/attendance/attendanceRecord/punchCourseByStudent" - - -def punch(attendance_id: str, token: str) -> requests.Response: - payload = { - "attendanceId": attendance_id - } - headers = { - "User-Agent": "Dart/3.6 (dart:io)", - "Accept-Encoding": "gzip", - "Cookie": f"token={token}" - } - return requests.put(PUNCH_URL, data=payload, headers=headers, verify=False) - - -if __name__ == "__main__": - # attendance_id from argv[1], else env ATTENDANCE_ID - attendance_id = (sys.argv[1] if len(sys.argv) > - 1 else os.getenv("ATTENDANCE_ID")) - token = os.getenv("TOKEN", "48db6cdf9a2c4f58a189436cb5429659") - - if not attendance_id: - print("缺少 attendanceId 内容,无法打卡") - raise SystemExit(1) - - try: - resp = punch(attendance_id, token) - print(resp.text) - except Exception as e: - print(f"打卡失败: {e}") - raise SystemExit(1)