From e046dba174365eb8934ee1e4206f09821145e876 Mon Sep 17 00:00:00 2001 From: skyouc Date: 星期四, 21 八月 2025 13:23:22 +0800 Subject: [PATCH] no message --- zy-asrs-wms/src/main/java/com/zy/asrs/wms/utils/HttpUtils.java | 79 ++++++++++++++++++++++++++------------- 1 files changed, 53 insertions(+), 26 deletions(-) diff --git a/zy-asrs-wms/src/main/java/com/zy/asrs/wms/utils/HttpUtils.java b/zy-asrs-wms/src/main/java/com/zy/asrs/wms/utils/HttpUtils.java index bbb8864..0639cde 100644 --- a/zy-asrs-wms/src/main/java/com/zy/asrs/wms/utils/HttpUtils.java +++ b/zy-asrs-wms/src/main/java/com/zy/asrs/wms/utils/HttpUtils.java @@ -1,26 +1,53 @@ -package com.zy.asrs.wms.utils; - -import com.alibaba.fastjson.JSON; -import com.zy.asrs.framework.common.R; - -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.io.PrintWriter; - -/** - * Created by vincent on 1/29/2024 - */ -public class HttpUtils { - - public static void responseError(HttpServletResponse response, Integer code, String message, String error) { - response.setContentType("application/json;charset=UTF-8"); - try { - PrintWriter out = response.getWriter(); - out.write(JSON.toJSONString(R.parse(code + "-" + message))); - out.flush(); - } catch (IOException e) { - e.printStackTrace(); - } - } - -} +package com.zy.asrs.wms.utils; + +import com.alibaba.fastjson.JSON; +import com.zy.asrs.framework.common.R; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.PrintWriter; + +/** + * Created by vincent on 1/29/2024 + */ +public class HttpUtils { + + public static void responseError(HttpServletResponse response, Integer code, String message, String error) { + response.setContentType("application/json;charset=UTF-8"); + try { + PrintWriter out = response.getWriter(); + out.write(JSON.toJSONString(R.parse(code + "-" + message))); + out.flush(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static String getClientIpAddress(HttpServletRequest 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(); + } + + // 瀵逛簬閫氳繃澶氫釜浠g悊鐨勬儏鍐碉紝绗竴涓狪P涓哄鎴风鐪熷疄IP锛屽涓狪P鎸夌収','鍒嗗壊 + if (ip != null && ip.contains(",")) { + ip = ip.split(",")[0].trim(); + } + return ip; + } + +} -- Gitblit v1.9.1