diff --git a/backend/services/check_in_service.py b/backend/services/check_in_service.py index 7af0e75..130664a 100644 --- a/backend/services/check_in_service.py +++ b/backend/services/check_in_service.py @@ -80,6 +80,11 @@ class CheckInService: # 执行打卡 result = perform_check_in(task, user_token) + # 如果是 Token 过期导致的失败,标记用户的 token_expired_notified 标志 + if result["status"] == "token_expired" and task.user: + task.user.token_expired_notified = True + logger.info(f"标记用户 {task.user.alias} 的 token_expired_notified 为 True") + # 更新记录 db.query(CheckInRecord).filter(CheckInRecord.id == record_id).update({ "status": result["status"], @@ -264,6 +269,11 @@ class CheckInService: logger.info(f"🤖 调用 Selenium Worker 执行打卡...") result = perform_check_in(task, user.authorization) + # 如果是 Token 过期导致的失败,标记用户的 token_expired_notified 标志 + if result["status"] == "token_expired" and user: + user.token_expired_notified = True + logger.info(f"标记用户 {user.alias} 的 token_expired_notified 为 True") + # 保存打卡记录 record = CheckInRecord( task_id=task.id, diff --git a/backend/services/email_service.py b/backend/services/email_service.py index f80639d..2085629 100644 --- a/backend/services/email_service.py +++ b/backend/services/email_service.py @@ -666,6 +666,33 @@ class EmailService: subject = f"【接龙自动打卡】打卡{status_text} - {user.alias}" + # 判断是否是 Token 失效导致的失败 + is_token_error = not success and message and ( + "Token" in message or "token" in message or + "失效" in message or "授权" in message or "登录" in message + ) + + # Token 失效时的额外提示内容 + token_error_section = "" + if is_token_error: + token_error_section = f""" +
打卡凭证已过期,无法自动打卡。所有自动打卡任务已暂停,请尽快刷新 Token 以恢复服务。
+如何刷新 Token:
++ 立即登录刷新 +
+ """ + body_html = f""" @@ -714,6 +741,21 @@ class EmailService: color: #999; font-size: 12px; }} + .error-box {{ + background-color: #f8d7da; + border-left: 4px solid #dc3545; + padding: 15px; + margin: 15px 0; + }} + .btn {{ + display: inline-block; + padding: 12px 24px; + background-color: #667eea; + color: white; + text-decoration: none; + border-radius: 5px; + margin: 10px 0; + }} @@ -738,10 +780,10 @@ class EmailService:如有问题,请及时检查您的打卡配置。
+ {token_error_section if is_token_error else '如有问题,请及时检查您的打卡配置。
'}