Skip to content

Commit

Permalink
Merge branch 'main' into feature/check-in-captcha
Browse files Browse the repository at this point in the history
  • Loading branch information
Rockytkg authored Jan 10, 2025
2 parents 44eb647 + 5f93263 commit 982ce33
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 23 deletions.
63 changes: 49 additions & 14 deletions coreApi/MainLogicApi.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ def _post_request(
response.raise_for_status()
rsp = response.json()

if rsp.get("code") == 200 and rsp.get("msg", "未知错误") == "302":
raise ValueError("打卡失败,触发行为验证码")

if rsp.get("code") == 200 or rsp.get("code") == 6111:
return rsp

Expand Down Expand Up @@ -277,8 +280,9 @@ def get_job_info(self) -> Dict[str, Any]:
"t": aes_encrypt(str(int(time.time() * 1000))),
}
headers = self._get_authenticated_headers()
rsp = self._post_request(url, headers, data)
return rsp.get("data", {})
rsp = self._post_request(url, headers, data, "获取岗位信息失败")
data = rsp.get("data", {})
return {} if data is None else data

def get_submitted_reports_info(self, report_type: str) -> Dict[str, Any]:
"""
Expand Down Expand Up @@ -386,7 +390,7 @@ def submit_report(self, report_info: Dict[str, Any]) -> None:
"compState": None,
"apply": None,
"levelEntity": None,
"formFieldDtoList": [],
"formFieldDtoList": report_info.get("formFieldDtoList", []),
"fieldEntityList": [],
"feedback": None,
"handleWay": None,
Expand All @@ -409,6 +413,30 @@ def get_weeks_date(self) -> list[Dict[str, Any]]:
rsp = self._post_request(url, headers, data)
return rsp.get("data", [])

def get_from_info(self, formType: int) -> list[Dict[str, Any]]:
"""
获取子表单(问卷),并设置值
Args:
formType (int): 表单类型。日报:7,周报:8,月报:9
Returns:
list[Dict[str, Any]]: 问卷
"""
url = "practice/paper/v2/info"
data = {"formType": formType, "t": aes_encrypt(str(int(time.time() * 1000)))}
headers = self._get_authenticated_headers()
rsp = self._post_request(url, headers, data, "获取问卷失败").get("data", {})
formFieldDtoList = rsp.get("formFieldDtoList", [])
# 没有问卷就直接返回
if not formFieldDtoList:
return formFieldDtoList
logger.info("检测到问卷,已自动填写")
# 有问卷就自动填写
for item in formFieldDtoList:
# 默认暂时就先选个 b 吧
item["value"] = "b"

return formFieldDtoList

def get_checkin_info(self) -> Dict[str, Any]:
"""
获取用户的打卡信息。
Expand All @@ -422,6 +450,8 @@ def get_checkin_info(self) -> Dict[str, Any]:
ValueError: 如果获取打卡信息失败,抛出包含详细错误信息的异常。
"""
url = "attendence/clock/v2/listSynchro"
if self.config.get_value("userInfo.userType") == "teacher":
url = "attendence/clock/teacher/v1/listSynchro"
headers = self._get_authenticated_headers()
data = {
**get_current_month_info(),
Expand All @@ -443,7 +473,20 @@ def submit_clock_in(self, checkin_info: Dict[str, Any]) -> None:
Raises:
ValueError: 如果打卡提交失败,抛出包含详细错误信息的异常。
"""
url = "attendence/clock/v5/save"
url = "attendence/clock/teacher/v2/save"
sign_data = None
planId = self.config.get_value("planInfo.planId")

if self.config.get_value("userInfo.userType") != "teacher":
url = "attendence/clock/v5/save"
sign_data = [
self.config.get_value("config.device"),
checkin_info.get("type"),
planId,
self.config.get_value("userInfo.userId"),
self.config.get_value("config.clockIn.location.address"),
]

logger.info(f'打卡类型:{checkin_info.get("type")}')

data = {
Expand All @@ -468,7 +511,7 @@ def submit_clock_in(self, checkin_info: Dict[str, Any]) -> None:
"teacherNumber": None,
"type": checkin_info.get("type"),
"stuId": None,
"planId": self.config.get_value("planInfo.planId"),
"planId": planId,
"attendanceType": None,
"username": None,
"attachments": checkin_info.get("attachments", None),
Expand All @@ -492,15 +535,7 @@ def submit_clock_in(self, checkin_info: Dict[str, Any]) -> None:

data.update(self.config.get_value("config.clockIn.location"))

headers = self._get_authenticated_headers(
sign_data=[
self.config.get_value("config.device"),
checkin_info.get("type"),
self.config.get_value("planInfo.planId"),
self.config.get_value("userInfo.userId"),
self.config.get_value("config.clockIn.location.address"),
]
)
headers = self._get_authenticated_headers(sign_data)

if self._post_request(url, headers, data).get("msg") == "302":
logger.info("检测到行为验证码,正在通过···")
Expand Down
27 changes: 18 additions & 9 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def perform_clock_in(api_client: ApiClient, config: ConfigManager) -> Dict[str,

# 判断是否为节假日模式并跳过打卡
if config.get_value("config.clockIn.mode") == "holiday" and is_holiday():
if config.get_value("config.clockIn.specialClockIn"):
if not config.get_value("config.clockIn.specialClockIn"):
return {
"status": "skip",
"message": "今天是休息日,已跳过打卡",
Expand All @@ -62,7 +62,7 @@ def perform_clock_in(api_client: ApiClient, config: ConfigManager) -> Dict[str,
elif config.get_value("config.clockIn.mode") == "custom":
today = datetime.today().weekday() + 1 # 获取星期几(1-7)
if today not in config.get_value("config.clockIn.customDays"):
if config.get_value("config.clockIn.specialClockIn"):
if not config.get_value("config.clockIn.specialClockIn"):
return {
"status": "skip",
"message": "今天不在设置打卡时间范围内,已跳过打卡",
Expand Down Expand Up @@ -118,7 +118,7 @@ def perform_clock_in(api_client: ApiClient, config: ConfigManager) -> Dict[str,
"message": f"{display_type}打卡成功",
"task_type": "打卡",
"details": {
"姓名": user_name,
"姓名": config.get_value("userInfo.nikeName"),
"打卡类型": display_type,
"打卡时间": current_time.strftime("%Y-%m-%d %H:%M:%S"),
"打卡地点": config.get_value("config.clockIn.location.address"),
Expand Down Expand Up @@ -193,8 +193,9 @@ def submit_daily_report(api_client: ApiClient, config: ConfigManager) -> Dict[st
"content": content,
"attachments": attachments,
"reportType": "day",
"jobId": job_info.get("jobId"),
"jobId": job_info.get("jobId", None),
"reportTime": current_time.strftime("%Y-%m-%d %H:%M:%S"),
"formFieldDtoList": api_client.get_from_info(7),
}
api_client.submit_report(report_info)

Expand Down Expand Up @@ -293,8 +294,9 @@ def submit_weekly_report(
"reportType": "week",
"endTime": current_week_info.get("endTime"),
"startTime": current_week_info.get("startTime"),
"jobId": job_info.get("jobId"),
"jobId": job_info.get("jobId", None),
"weeks": current_week_string,
"formFieldDtoList": api_client.get_from_info(8),
}
api_client.submit_report(report_info)

Expand Down Expand Up @@ -396,7 +398,8 @@ def submit_monthly_report(
"attachments": attachments,
"yearmonth": current_yearmonth,
"reportType": "month",
"jobId": job_info.get("jobId"),
"jobId": job_info.get("jobId", None),
"formFieldDtoList": api_client.get_from_info(9),
}
api_client.submit_report(report_info)

Expand Down Expand Up @@ -439,12 +442,18 @@ def run(config: ConfigManager) -> None:

try:
api_client = ApiClient(config)
# 检查是否登录
if not config.get_value("userInfo.token"):
api_client.login()
if not config.get_value("planInfo.planId"):

logger.info("获取用户信息成功")
# 检查用户类型和计划信息
if config.get_value("userInfo.userType") == "teacher":
logger.info("用户身份为教师,跳过计划信息检查")
elif not config.get_value("planInfo.planId"):
api_client.fetch_internship_plan()
else:
logger.info("使用本地数据")
logger.info("已获取实习计划信息")

except Exception as e:
error_message = f"获取API客户端失败: {str(e)}"
logger.error(error_message)
Expand Down

0 comments on commit 982ce33

Please sign in to comment.