diff --git a/hai-cweb/src/main/java/com/cweb/config/AuthConfig.java b/hai-cweb/src/main/java/com/cweb/config/AuthConfig.java index 262691f1..01a1ca7b 100644 --- a/hai-cweb/src/main/java/com/cweb/config/AuthConfig.java +++ b/hai-cweb/src/main/java/com/cweb/config/AuthConfig.java @@ -114,6 +114,7 @@ public class AuthConfig implements WebMvcConfigurer { .excludePathPatterns("/user/login") .excludePathPatterns("/user/unionPhoneLogin") .excludePathPatterns("/user/getUnionId") + .excludePathPatterns("/user/ip") .excludePathPatterns("/highUser/setCacheParam") .excludePathPatterns("/highUser/getCacheParam") .excludePathPatterns("/highUser/delCacheParam") diff --git a/hai-cweb/src/main/java/com/cweb/controller/HighUserCommonController.java b/hai-cweb/src/main/java/com/cweb/controller/HighUserCommonController.java index e9ee316e..53098386 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/HighUserCommonController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/HighUserCommonController.java @@ -5,10 +5,7 @@ import com.hai.common.exception.ErrorCode; import com.hai.common.exception.ErrorHelp; import com.hai.common.exception.SysCode; import com.hai.common.security.*; -import com.hai.common.utils.IDGenerator; -import com.hai.common.utils.RedisUtil; -import com.hai.common.utils.ResponseMsgUtil; -import com.hai.common.utils.UnionUtils; +import com.hai.common.utils.*; import com.hai.config.UnionUserConfig; import com.hai.entity.HighUser; import com.hai.model.HighUserModel; @@ -182,6 +179,22 @@ public class HighUserCommonController { } } + + @RequestMapping(value = "/ip", method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "退出登录") + public ResponseData ip(HttpServletRequest request, HttpServletResponse response) { + try { + // 113.205.199.32 + // ; + // return ResponseMsgUtil.success(RequestUtils.getRequestIp()); + return ResponseMsgUtil.success(HttpsUtils.doGet("https://api.map.baidu.com/location/ip?ak=X4sSdXsohVOMb1tNiLZloD9ows5FaNjq&ip=113.205.199.32&coor=gcj02")); + + } catch (Exception e) { + return ResponseMsgUtil.exception(e); + } + } + } diff --git a/hai-service/src/main/java/com/hai/common/utils/RequestUtils.java b/hai-service/src/main/java/com/hai/common/utils/RequestUtils.java index 7802084b..481606b7 100644 --- a/hai-service/src/main/java/com/hai/common/utils/RequestUtils.java +++ b/hai-service/src/main/java/com/hai/common/utils/RequestUtils.java @@ -1,4 +1,7 @@ package com.hai.common.utils; +import org.springframework.web.context.request.RequestAttributes; +import org.springframework.web.context.request.RequestContextHolder; + import javax.servlet.http.HttpServletRequest; public class RequestUtils { @@ -18,4 +21,34 @@ public class RequestUtils { return ip; } + + /** + * 获取请求的ip + */ + public static String getRequestIp() { + + RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes(); + + // 从获取RequestAttributes中获取HttpServletRequest的信息 + HttpServletRequest request = (HttpServletRequest) requestAttributes.resolveReference(RequestAttributes.REFERENCE_REQUEST); + + String ip = request.getHeader("x-forwarded-for"); + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("Proxy-Client-IP"); + } + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("WL-Proxy-Client-IP"); + } + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("HTTP_CLIENT_IP"); + } + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("HTTP_X_FORWARDED_FOR"); + } + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getRemoteAddr(); + } + + return ip; + } }