提交代码

dev-discount
胡锐 2 years ago
parent 589f5e096d
commit 27f3e6992e
  1. 1
      hai-cweb/src/main/java/com/cweb/config/AuthConfig.java
  2. 21
      hai-cweb/src/main/java/com/cweb/controller/HighUserCommonController.java
  3. 33
      hai-service/src/main/java/com/hai/common/utils/RequestUtils.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")

@ -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);
}
}
}

@ -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;
}
}

Loading…
Cancel
Save