From d8a5191e3bb088b761f55488f4be883eaf319539 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 2 Jan 2026 12:58:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=BC=BA=E9=92=89=E9=92=89=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E5=9C=B0=E5=9D=80=E8=8E=B7=E5=8F=96=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=EF=BC=9A=E6=B7=BB=E5=8A=A0=E7=99=BB=E5=BD=95=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E5=90=AF=E7=94=A8=E6=A3=80=E6=9F=A5=E5=92=8C=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E5=A4=84=E7=90=86=EF=BC=8C=E5=A2=9E=E5=8A=A0=E8=AF=A6=E7=BB=86?= =?UTF-8?q?=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/DingTalkController.java | 58 +++++++++++++------ 1 file changed, 39 insertions(+), 19 deletions(-) diff --git a/backend/src/main/java/com/designhub/controller/DingTalkController.java b/backend/src/main/java/com/designhub/controller/DingTalkController.java index 9fa1a84..d18c461 100644 --- a/backend/src/main/java/com/designhub/controller/DingTalkController.java +++ b/backend/src/main/java/com/designhub/controller/DingTalkController.java @@ -7,6 +7,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.*; import java.util.HashMap; @@ -16,6 +17,7 @@ import java.util.Map; /** * 钉钉集成 Controller */ +@Slf4j @Tag(name = "钉钉集成", description = "钉钉集成管理API") @RestController @RequestMapping("/api/dingtalk") @@ -165,26 +167,44 @@ public class DingTalkController { @Operation(summary = "钉钉OAuth登录发起", description = "生成钉钉登录URL") @GetMapping("/oauth/login") public Result> initiateLogin(@RequestParam(required = false) String redirectUrl) { - if (!dingTalkService.isConfigured()) { - return Result.error("钉钉登录未配置或未启用,请联系管理员在系统设置中配置"); + try { + // 检查是否配置 + if (!dingTalkService.isConfigured()) { + return Result.error("钉钉登录未配置或未启用,请联系管理员在系统设置中配置"); + } + + // 检查登录功能是否启用 + if (!dingTalkService.isFeatureEnabled("login")) { + return Result.error("钉钉登录功能未启用,请在系统设置中启用钉钉登录功能"); + } + + DingTalkConfig config = dingTalkService.getConfig(); + if (config == null) { + return Result.error("钉钉配置不存在"); + } + + if (config.getAppKey() == null || config.getAppKey().isEmpty()) { + return Result.error("钉钉AppKey未配置"); + } + + // 构建回调URL + String callbackUrl = redirectUrl != null ? redirectUrl : "http://localhost:3000/auth/dingtalk/callback"; + + // 构建钉钉OAuth URL + String authUrl = String.format( + "https://login.dingtalk.com/oauth2/auth?redirect_uri=%s&response_type=code&client_id=%s&scope=openid&state=STATE&prompt=consent", + java.net.URLEncoder.encode(callbackUrl, java.nio.charset.StandardCharsets.UTF_8), + config.getAppKey() + ); + + Map result = new HashMap<>(); + result.put("authUrl", authUrl); + result.put("appKey", config.getAppKey()); + return Result.success(result); + } catch (Exception e) { + log.error("获取钉钉登录地址失败", e); + return Result.error("获取钉钉登录地址失败: " + e.getMessage()); } - - DingTalkConfig config = dingTalkService.getConfig(); - - // 构建回调URL - String callbackUrl = redirectUrl != null ? redirectUrl : "http://localhost:3000/auth/dingtalk/callback"; - - // 构建钉钉OAuth URL - String authUrl = String.format( - "https://login.dingtalk.com/oauth2/auth?redirect_uri=%s&response_type=code&client_id=%s&scope=openid&state=STATE&prompt=consent", - java.net.URLEncoder.encode(callbackUrl, java.nio.charset.StandardCharsets.UTF_8), - config.getAppKey() - ); - - Map result = new HashMap<>(); - result.put("authUrl", authUrl); - result.put("appKey", config.getAppKey()); - return Result.success(result); } @Operation(summary = "检查钉钉登录是否已配置")