package com.njzscloud.supervisory.wxPay.utils;

import cn.hutool.extra.servlet.ServletUtil;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.util.Objects;

public class RequestHolder {

    public static HttpServletRequest getHttpServletRequest() {
        return ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
    }

    public static String getClientIP() {
        HttpServletRequest request = getHttpServletRequest();
        if (request == null) {
            return null;
        }
        return ServletUtil.getClientIP(request);
    }
}
