Browse Source

登录response传递token

lirong 2 năm trước cách đây
mục cha
commit
56b64b1766

+ 3 - 3
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/service/rest/RedirectApi.java

@@ -14,14 +14,14 @@ import javax.servlet.http.HttpServletResponse;
 public class RedirectApi {
 
 	@PostMapping(path = { "/redirect", "/zkt-sdk/redirect" }, produces = "application/json;charset=UTF-8")
-	public String redirect(@RequestBody String param, HttpServletRequest request) {
-		String result = RedirectUtil.redirect(param, false,request);
+	public String redirect(@RequestBody String param, HttpServletRequest request,HttpServletResponse response) {
+		String result = RedirectUtil.redirect(param, false,request,response);
 		return result;
 	}
 
 	@PostMapping(path = { "/redirect_wrapper", "/zkt-sdk/redirect_wrapper" }, produces = "application/json;charset=UTF-8")
 	public String redirect_wrapper(@RequestBody String param, HttpServletRequest request) {
-		String result = RedirectUtil.redirect(param, true,request);
+		String result = RedirectUtil.redirect(param, true,request,null);
 		return result;
 	}
 

+ 12 - 5
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/service/rest/RedirectUtil.java

@@ -20,7 +20,7 @@ import javax.servlet.http.HttpServletResponse;
 
 @Slf4j
 public class RedirectUtil {
-    public static String redirect(String param, boolean wrapper, HttpServletRequest request) {
+    public static String redirect(String param, boolean wrapper, HttpServletRequest request,HttpServletResponse response) {
         JSONObject sql_json = JSON.parseObject(param);
         String code = sql_json.getString("code");
         ConfigRedirect ConfigRedirect = Constant.ConfigRedirectMap.get(code);
@@ -34,7 +34,7 @@ public class RedirectUtil {
         String resultString;
         try {
             Map<String, String> otherMap = new ConcurrentHashMap<String, String>();
-            Object result = RedirectUtil.redirectInner(ConfigRedirect, sql_json, otherMap,request);
+            Object result = RedirectUtil.redirectInner(ConfigRedirect, sql_json, otherMap,request,response);
             if (wrapper) {
                 JSONObject resultJSON = new JSONObject();
                 resultJSON.put("Result", "success");
@@ -64,7 +64,7 @@ public class RedirectUtil {
         return resultString;
     }
 
-    public static Object redirectInner(ConfigRedirect ConfigRedirect, JSONObject sql_json, Map<String, String> otherMap,HttpServletRequest request) throws Exception {
+    public static Object redirectInner(ConfigRedirect ConfigRedirect, JSONObject sql_json, Map<String, String> otherMap,HttpServletRequest request,HttpServletResponse response) throws Exception {
         String resultString;
         String url = ConfigRedirect.url;
         String url_ori = url;
@@ -106,10 +106,17 @@ public class RedirectUtil {
             }
             //这里添加日志,重试手动,并设置成短链接
             try {
-                resultString = HttpClientUtil.instance("redirect").post(url, postString, null, ConfigRedirect.headerMap,null,request);
+                if(url.contains("login"))
+                {
+                    resultString = HttpClientUtil.instance("redirect").post(url, postString, null, ConfigRedirect.headerMap,response,request);
+                }
+                else
+                {
+                    resultString = HttpClientUtil.instance("redirect").post(url, postString, null, ConfigRedirect.headerMap,null,request);
+                }
             } catch (Exception e) {
                 log.error("redirect异常", e);
-                resultString = HttpClientUtil.instance("redirect").post(url, postString, null, ConfigRedirect.headerMap,null,request);
+                resultString = HttpClientUtil.instance("redirect").post(url, postString, null, ConfigRedirect.headerMap,response,request);
             }
         }
         Object result;

+ 2 - 2
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/util/HttpClientUtil.java

@@ -173,7 +173,7 @@ public class HttpClientUtil {
             timeout = 300000;
         }
         //登录这里设置成短连接
-        if (url.contains("getCaptchaBase64") || url.contains("/person-center/user/login")) {
+        if (url.contains("getCaptchaBase64") || url.contains("login")) {
             httpost.setProtocolVersion(HttpVersion.HTTP_1_0);
             httpost.setHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_CLOSE);
         }
@@ -186,7 +186,7 @@ public class HttpClientUtil {
         httpost.setEntity(entity);
         entity.setContentType("application/json");
         HttpResponse httpResponse = client.execute(httpost);
-        if (url.contains("/person-center/user/login")) {
+        if (url.contains("login")) {
             if (httpResponse != null) {
                 Header responseFirstHeader = httpResponse.getFirstHeader("Authorization");
                 if (responseFirstHeader != null) {