|
@@ -0,0 +1,65 @@
|
|
|
+package com.zjugis.ai.knowledge.controller.auth;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import org.dromara.hutool.core.text.StrUtil;
|
|
|
+import org.dromara.hutool.http.HttpUtil;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.web.bind.annotation.CrossOrigin;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author: Fuwb
|
|
|
+ * @date: 2025/3/10
|
|
|
+ * @time: 10:55
|
|
|
+ * @description: 用户登录接口层
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@RequestMapping("/auth")
|
|
|
+public class AuthController {
|
|
|
+ private static final int TIME_OUT = 30 * 1000;
|
|
|
+ @Value("${syUrl: }")
|
|
|
+ private String syUrl;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过携带ticket的url获取用户信息
|
|
|
+ *
|
|
|
+ * @param ticket
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ @CrossOrigin(origins = "*")
|
|
|
+ @GetMapping("/ticket")
|
|
|
+ public Map getUserBySyToken(String ticket) throws Exception {
|
|
|
+ if (StrUtil.isBlank(ticket)) {
|
|
|
+ Map hashMap = new HashMap<>(3);
|
|
|
+ hashMap.put("syUser", "");
|
|
|
+ hashMap.put("zjugisUser", "");
|
|
|
+ hashMap.put("error", "ticket不能为空");
|
|
|
+ return hashMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ String newUrl = syUrl + "?ticket=" + ticket;
|
|
|
+ System.out.println(newUrl);
|
|
|
+ String json = HttpUtil.get(newUrl, TIME_OUT);
|
|
|
+ JSONObject syResult = JSONObject.parseObject(json);
|
|
|
+ String syUserStr = (String) syResult.get("result");
|
|
|
+ JSONObject syUser = null;
|
|
|
+ Map rMap = new HashMap();
|
|
|
+ if (StrUtil.isBlank(syUserStr)) {
|
|
|
+ rMap.put("syUser", "");
|
|
|
+ rMap.put("zjugisUser", "");
|
|
|
+ rMap.put("error", syResult.get("message"));
|
|
|
+ } else {
|
|
|
+ syUser = JSONObject.parseObject(syUserStr);
|
|
|
+ rMap.put("syUser", syUser);
|
|
|
+ rMap.put("zjugisUser", "");
|
|
|
+ }
|
|
|
+ return rMap;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|