优化示例脚本,新增测试脚本

This commit is contained in:
江雨
2025-12-22 22:44:34 +08:00
parent 31ab13dab0
commit 3a47ae4aa4
4 changed files with 50 additions and 37 deletions

View File

@@ -92,6 +92,7 @@ curl -X PUT \
"https://m-zjt.kefang.net/api/zms/attendance/attendanceRecord/punchCourseByStudent"
```
您可在项目文件 main.py 中查看示例脚本
返回结果若包含“操作成功”的 `message`,则表示打卡成功。
## 4. 常见问题

View File

@@ -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:

32
put.py Normal file
View File

@@ -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")

35
sign.py
View File

@@ -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)