From 69a3c374ca3afb770e3b9ffcbdda07ce362cbf58 Mon Sep 17 00:00:00 2001
From: 1 <1@123>
Date: 星期五, 09 一月 2026 19:59:29 +0800
Subject: [PATCH] #

---
 rsf-open-api/src/main/java/com/vincent/rsf/openApi/controller/AuthController.java |  174 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 174 insertions(+), 0 deletions(-)

diff --git a/rsf-open-api/src/main/java/com/vincent/rsf/openApi/controller/AuthController.java b/rsf-open-api/src/main/java/com/vincent/rsf/openApi/controller/AuthController.java
new file mode 100644
index 0000000..ca9040c
--- /dev/null
+++ b/rsf-open-api/src/main/java/com/vincent/rsf/openApi/controller/AuthController.java
@@ -0,0 +1,174 @@
+package com.vincent.rsf.openApi.controller;
+
+import com.vincent.rsf.framework.common.Cools;
+import com.vincent.rsf.openApi.entity.constant.Constants;
+import com.vincent.rsf.openApi.entity.dto.CommonResponse;
+import com.vincent.rsf.openApi.entity.AppAuthParam;
+import com.vincent.rsf.openApi.security.service.AppAuthService;
+import com.vincent.rsf.openApi.security.utils.TokenUtils;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.web.bind.annotation.*;
+
+import javax.annotation.Resource;
+
+/**
+ * App璁よ瘉鎺у埗鍣�
+ * 
+ * 鎻愪緵AppId鍜孉ppSecret鐨勭櫥褰曡璇佸姛鑳�
+ * 
+ * @author vincent
+ * @since 2026-01-05
+ */
+@RestController
+//@RequestMapping("/auth")
+@Api(tags = "搴旂敤璁よ瘉绠$悊")
+@Slf4j
+public class AuthController {
+
+    // 寮�鍚ā鎷熸暟鎹�
+    @Value("${foreign.api.data.simulated}")
+    public static String SIMULATED_DATA_ENABLE = "1";
+
+    @Resource
+    private AppAuthService appAuthService;
+
+
+    /**
+     * 鑾峰彇App璁よ瘉Token
+     *
+     * @param param 搴旂敤ID鍜屽簲鐢ㄥ瘑閽�
+     * @return 璁よ瘉Token
+     */
+    @ApiOperation("鑾峰彇App璁よ瘉Token")
+    @PostMapping("/getToken")
+    public CommonResponse getToken(@RequestBody AppAuthParam param) {
+        String appId = param.getAppId();
+        String appSecret = param.getAppSecret();
+
+        if (Cools.isEmpty(appId, appSecret)) {
+            return CommonResponse.error("AppId鍜孉ppSecret涓嶈兘涓虹┖");
+        }
+
+        boolean isValid = appAuthService.validateApp(appId, appSecret);
+        if (isValid) {
+            String token = Constants.TOKEN_PREFIX + TokenUtils.generateToken(appId, appSecret);  //appAuthService.generateAppToken(appId, appSecret);
+            return CommonResponse.ok()
+                    .setMsg("鑾峰彇Token鎴愬姛")
+                    .setData(token);
+        } else {
+            return CommonResponse.error("AppId鎴朅ppSecret鏃犳晥");
+        }
+    }
+
+//    /**
+//     * 楠岃瘉Token鐨勬帴鍙�
+//     *
+//     * @param token 瑕侀獙璇佺殑Token
+//     * @return Token楠岃瘉缁撴灉
+//     */
+//    @PostMapping("/validateToken")
+//    public Map<String, Object> validateToken(@RequestHeader(name = "authorization") String token) {
+//        log.info("楠岃瘉Token: {}", token.substring(0, Math.min(10, token.length())) + "...");
+//
+//        boolean isValid = TokenUtils.validateToken(token);
+//
+//        Map<String, Object> response = new HashMap<>();
+//        response.put("code", "200");
+//        response.put("message", isValid ? "Token鏈夋晥" : "Token鏃犳晥");
+//        response.put("data", Map.of(
+//                "valid", isValid,
+//                "appId", isValid ? TokenUtils.getAppIdFromToken(token) : null,
+//                "userId", isValid ? TokenUtils.getUserIdFromToken(token) : null
+//        ));
+//        response.put("success", isValid);
+//
+//        return response;
+//    }
+
+//    /**
+//     * AppId鍜孉ppSecret鐧诲綍璁よ瘉
+//     *
+//     * @param param 璁よ瘉鍙傛暟
+//     * @return 璁よ瘉缁撴灉
+//     */
+//    @ApiOperation("AppId鍜孉ppSecret鐧诲綍璁よ瘉")
+//    @PostMapping("/login")
+//    public CommonResponse login(@RequestBody AppAuthParam param) {
+//        String appId = param.getAppId();
+//        String appSecret = param.getAppSecret();
+//
+//        if (Cools.isEmpty(appId, appSecret)) {
+//            return CommonResponse.error("AppId鍜孉ppSecret涓嶈兘涓虹┖");
+//        }
+//
+//        boolean isValid = appAuthService.validateApp(appId, appSecret);
+//        if (isValid) {
+//            // 鐢熸垚Token
+//            String token = appAuthService.generateAppToken(appId, appSecret);
+//            return CommonResponse.ok()
+//                    .setMsg("鐧诲綍鎴愬姛")
+//                    .setData(token);
+//        } else {
+//            return CommonResponse.error("AppId鎴朅ppSecret鏃犳晥");
+//        }
+//    }
+//
+//
+//
+//    /**
+//     * 楠岃瘉App璁よ瘉
+//     *
+//     * @param request HTTP璇锋眰
+//     * @return 楠岃瘉缁撴灉
+//     */
+//    @ApiOperation("楠岃瘉App璁よ瘉")
+//    @PostMapping("/validate")
+//    public CommonResponse validate(HttpServletRequest request) {
+//        String appId = request.getHeader(Constants.HEADER_APP_ID);
+//        String appSecret = request.getHeader(Constants.HEADER_APP_SECRET);
+//
+//        if (Cools.isEmpty(appId, appSecret)) {
+//            return CommonResponse.error("缂哄皯AppId鎴朅ppSecret");
+//        }
+//
+//        boolean isValid = appAuthService.validateApp(appId, appSecret);
+//        if (isValid) {
+//            return CommonResponse.ok()
+//                    .setMsg("楠岃瘉鎴愬姛")
+//                    .setData(appAuthService.getAppInfo(appId));
+//        } else {
+//            return CommonResponse.error("楠岃瘉澶辫触");
+//        }
+//    }
+//
+//    /**
+//     * 鑾峰彇褰撳墠璁よ瘉鐨凙pp淇℃伅
+//     *
+//     * @param request HTTP璇锋眰
+//     * @return App淇℃伅
+//     */
+//    @ApiOperation("鑾峰彇褰撳墠璁よ瘉鐨凙pp淇℃伅")
+//    @GetMapping("/info")
+//    public CommonResponse getAppInfo(HttpServletRequest request) {
+//        String appId = (String) request.getAttribute("APP_ID");
+//        if (appId == null) {
+//            appId = request.getHeader(Constants.HEADER_APP_ID);
+//        }
+//
+//        if (appId == null) {
+//            return CommonResponse.error("鏈壘鍒癆ppId");
+//        }
+//
+//        var appInfo = appAuthService.getAppInfo(appId);
+//        if (appInfo != null) {
+//            return CommonResponse.ok()
+//                    .setMsg("鑾峰彇App淇℃伅鎴愬姛")
+//                    .setData(appInfo);
+//        } else {
+//            return CommonResponse.error("鏈壘鍒癆pp淇℃伅");
+//        }
+//    }
+}

--
Gitblit v1.9.1