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/example/ApiAuthExampleController.java | 96 ++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 96 insertions(+), 0 deletions(-)
diff --git a/rsf-open-api/src/main/java/com/vincent/rsf/openApi/controller/example/ApiAuthExampleController.java b/rsf-open-api/src/main/java/com/vincent/rsf/openApi/controller/example/ApiAuthExampleController.java
new file mode 100644
index 0000000..15cb949
--- /dev/null
+++ b/rsf-open-api/src/main/java/com/vincent/rsf/openApi/controller/example/ApiAuthExampleController.java
@@ -0,0 +1,96 @@
+package com.vincent.rsf.openApi.controller.example;
+
+import com.vincent.rsf.openApi.entity.constant.Constants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * API璁よ瘉绀轰緥鎺у埗鍣�
+ * 婕旂ず濡備綍浣跨敤缁熶竴鐨勮璇佹満鍒讹紙鏀寔AppId/AppSecret鍜孴oken锛�
+ */
+@RestController
+@RequestMapping("/api/example/auth")
+public class ApiAuthExampleController {
+ private static final Logger log = LoggerFactory.getLogger(ApiAuthExampleController.class);
+
+ /**
+ * 鑾峰彇鍙椾繚鎶ょ殑鏁版嵁 - 鏀寔AppId/AppSecret鎴朤oken璁よ瘉
+ *
+ * @param request HTTP璇锋眰
+ * @return 鍙椾繚鎶ょ殑鏁版嵁
+ */
+ @GetMapping("/protected-data")
+ public Map<String, Object> getProtectedData(HttpServletRequest request) {
+ // 浠庤姹傚睘鎬т腑鑾峰彇璁よ瘉淇℃伅锛堢敱AppIdAuthenticationFilter璁剧疆锛�
+ String appId = (String) request.getAttribute(Constants.REQUEST_ATTR_APP_ID);
+ String userId = (String) request.getAttribute(Constants.REQUEST_ATTR_USER_ID);
+
+ log.info("璁块棶鍙椾繚鎶ゆ帴鍙o紝AppId: {}, UserId: {}", appId, userId);
+
+ Map<String, Object> response = new HashMap<>();
+ response.put("code", "200");
+ response.put("message", "璁块棶鎴愬姛");
+ response.put("data", Map.of(
+ "appId", appId,
+ "userId", userId,
+ "protectedInfo", "杩欐槸鍙椾繚鎶ょ殑鏁版嵁",
+ "authType", userId != null ? "Token" : "AppId/AppSecret",
+ "timestamp", System.currentTimeMillis()
+ ));
+ response.put("success", true);
+
+ return response;
+ }
+
+ /**
+ * 鑾峰彇璁よ瘉淇℃伅 - 鏀寔AppId/AppSecret鎴朤oken璁よ瘉
+ *
+ * @param request HTTP璇锋眰
+ * @return 璁よ瘉淇℃伅
+ */
+ @GetMapping("/auth-info")
+ public Map<String, Object> getAuthInfo(HttpServletRequest request) {
+ // 浠庤姹傚睘鎬т腑鑾峰彇璁よ瘉淇℃伅
+ String appId = (String) request.getAttribute(Constants.REQUEST_ATTR_APP_ID);
+ String userId = (String) request.getAttribute(Constants.REQUEST_ATTR_USER_ID);
+
+ log.info("鑾峰彇璁よ瘉淇℃伅锛孉ppId: {}, UserId: {}", appId, userId);
+
+ Map<String, Object> response = new HashMap<>();
+ response.put("code", "200");
+ response.put("message", "鑾峰彇璁よ瘉淇℃伅鎴愬姛");
+ response.put("data", Map.of(
+ "appId", appId,
+ "userId", userId,
+ "authType", userId != null ? "Token" : "AppId/AppSecret",
+ "authenticated", appId != null
+ ));
+ response.put("success", true);
+
+ return response;
+ }
+
+ /**
+ * 娴嬭瘯鎺ュ彛 - 涓嶉渶瑕佽璇�
+ *
+ * @return 娴嬭瘯鏁版嵁
+ */
+ @GetMapping("/public-test")
+ public Map<String, Object> getPublicTest() {
+ Map<String, Object> response = new HashMap<>();
+ response.put("code", "200");
+ response.put("message", "鍏紑鎺ュ彛璁块棶鎴愬姛");
+ response.put("data", Map.of(
+ "info", "杩欐槸涓�涓笉闇�瑕佽璇佺殑鍏紑鎺ュ彛",
+ "timestamp", System.currentTimeMillis()
+ ));
+ response.put("success", true);
+
+ return response;
+ }
+}
\ No newline at end of file
--
Gitblit v1.9.1