Explorar el Código

1.调整用户登录接口参数,及返回格式

fuwb hace 3 meses
padre
commit
3f0a0a9029

+ 34 - 12
ais_auth/src/main/java/com/zjugis/auth/controller/AuthController.java

@@ -3,6 +3,7 @@ package com.zjugis.auth.controller;
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.http.HttpUtil;
 import cn.hutool.json.JSONUtil;
+import com.alibaba.fastjson.JSONObject;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.web.bind.annotation.CrossOrigin;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -28,29 +29,50 @@ public class AuthController {
     /**
      * 通过携带ticket的url获取用户信息
      *
-     * @param url
+     * @param ticket
      * @return
      * @throws Exception
      */
     @CrossOrigin(origins = "*")
     @GetMapping("/ticket")
-    public Map getUserBySyToken(String url) throws Exception {
-        if (StrUtil.isBlank(url)) {
+    public Map getUserBySyToken(String ticket) throws Exception {
+        if (StrUtil.isBlank(ticket)) {
             Map hashMap = new HashMap<>(3);
-            hashMap.put("result", "");
-            hashMap.put("success", false);
-            hashMap.put("message", "url地址无效");
+            hashMap.put("syUser","");
+            hashMap.put("zjugisUser","");
+            hashMap.put("error", "ticket不能为空");
             return hashMap;
         }
 
-        int lastIndexOf = url.lastIndexOf("?");
-        String ticketParam = url.substring(lastIndexOf);
-        String[] tickets = ticketParam.split("=");
-        String ticket = tickets[1];
         String newUrl = syUrl + "?ticket=" + ticket;
         String json = HttpUtil.get(newUrl, TIME_OUT);
-        Map map = JSONUtil.toBean(json, Map.class);
-        return map;
+//        Map map = JSONUtil.toBean(json, Map.class);
+        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", "");
+//            String thirdId = (String) syUser.get("Account");
+//            if (StrUtil.isNotBlank(thirdId)) {
+////                String userId = userService.selectUserByThirdUserId(thirdId);
+//                if (StrUtil.isBlank(userId)) {
+//                    rMap.put("zjugisUser", "");
+//                } else {
+//                    Map param = new HashMap();
+//                    param.put("id", userId);
+//                    String userRst = ServiceApiUtils.getDataFromServiceApi(YamlConfig.getValue("application-project.yml", "serviceUrl.z_user_org_right") + "/UsersApi/getUserById", param);
+//                    rMap.put("zjugisUser", JSONObject.parseObject(userRst));
+//                }
+//            }
+        }
+        return rMap;
     }
 
 }