|
|
|
@ -4,7 +4,10 @@ import com.mashibing.api.enums.SmsCodeEnum;
|
|
|
|
|
import com.mashibing.api.from.SingleSendForm;
|
|
|
|
|
import com.mashibing.api.util.R;
|
|
|
|
|
import com.mashibing.api.vo.ResultVO;
|
|
|
|
|
import com.mashibing.common.model.StandardSubmit;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
import org.springframework.validation.BindingResult;
|
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
@ -23,8 +26,23 @@ import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("/sms")
|
|
|
|
|
@Slf4j
|
|
|
|
|
@RefreshScope //方便动态加载配置文件
|
|
|
|
|
public class SmsController {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Value("${headers}")
|
|
|
|
|
private String headers;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 当前请求头获取信息是,可能获取到未知信息
|
|
|
|
|
*/
|
|
|
|
|
private final String UNKNOW = "unknow";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 如果是当前请求头获取IP地址,需截取到第一个IP
|
|
|
|
|
*/
|
|
|
|
|
private final String X_FORWARDED_FOR = "x-forwarded-for";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param singleSendForm
|
|
|
|
|
* @return
|
|
|
|
@ -43,6 +61,7 @@ public class SmsController {
|
|
|
|
|
String ip = this.getRealIP(request);
|
|
|
|
|
System.out.println("ip = " + ip);
|
|
|
|
|
|
|
|
|
|
StandardSubmit standardSubmit = new StandardSubmit();
|
|
|
|
|
|
|
|
|
|
//===============发送到MQ,交给策略模块处理==================
|
|
|
|
|
|
|
|
|
@ -57,27 +76,41 @@ public class SmsController {
|
|
|
|
|
*/
|
|
|
|
|
private String getRealIP(HttpServletRequest request) {
|
|
|
|
|
String ip;
|
|
|
|
|
String ips = request.getHeader("x-forwarded-for");
|
|
|
|
|
if (StringUtils.isEmpty(ips) || "unknow".equalsIgnoreCase(ips)) {
|
|
|
|
|
return ips.substring(0, ips.indexOf(","));
|
|
|
|
|
for (String header : headers.split(",")) {
|
|
|
|
|
if (!StringUtils.isEmpty(header)) {
|
|
|
|
|
ip = request.getHeader(header);
|
|
|
|
|
if (!StringUtils.isEmpty(ip) && !UNKNOW.equalsIgnoreCase(ip)) {
|
|
|
|
|
if (X_FORWARDED_FOR.equalsIgnoreCase(header) && ip.indexOf(",") > 0) {
|
|
|
|
|
ip = ip.substring(0, ip.indexOf(","));
|
|
|
|
|
}
|
|
|
|
|
return ip;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 8. 基于传统方式获取IP
|
|
|
|
|
ip = request.getRemoteAddr();
|
|
|
|
|
|
|
|
|
|
ip = request.getHeader("x-real-ip");
|
|
|
|
|
if (StringUtils.isEmpty(ip) || "unknow".equalsIgnoreCase(ip)) {
|
|
|
|
|
ip = request.getHeader("Proxy-client-ip");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isEmpty(ip) || "unknow".equalsIgnoreCase(ip)) {
|
|
|
|
|
ip = request.getHeader("wl-proxy-client-ip");
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isEmpty(ip) || "unknow".equalsIgnoreCase(ip)) {
|
|
|
|
|
//7. 基于其他代理服务器的方式获取请求头的IP地址
|
|
|
|
|
ip = request.getHeader("http_client_ip");
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isEmpty(ip) || "unknow".equalsIgnoreCase(ip)) {
|
|
|
|
|
//8. 基于传统方式获取IP
|
|
|
|
|
ip = request.getRemoteAddr();
|
|
|
|
|
}
|
|
|
|
|
// String ips = request.getHeader("x-forwarded-for");
|
|
|
|
|
// if (StringUtils.isEmpty(ips) || "unknow".equalsIgnoreCase(ips)) {
|
|
|
|
|
// return ips.substring(0, ips.indexOf(","));
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// ip = request.getHeader("x-real-ip");
|
|
|
|
|
// if (StringUtils.isEmpty(ip) || "unknow".equalsIgnoreCase(ip)) {
|
|
|
|
|
// ip = request.getHeader("Proxy-client-ip");
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
// if (StringUtils.isEmpty(ip) || "unknow".equalsIgnoreCase(ip)) {
|
|
|
|
|
// ip = request.getHeader("wl-proxy-client-ip");
|
|
|
|
|
// }
|
|
|
|
|
// if (StringUtils.isEmpty(ip) || "unknow".equalsIgnoreCase(ip)) {
|
|
|
|
|
// //7. 基于其他代理服务器的方式获取请求头的IP地址
|
|
|
|
|
// ip = request.getHeader("http_client_ip");
|
|
|
|
|
// }
|
|
|
|
|
// if (StringUtils.isEmpty(ip) || "unknow".equalsIgnoreCase(ip)) {
|
|
|
|
|
// //8. 基于传统方式获取IP
|
|
|
|
|
// ip = request.getRemoteAddr();
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
return ip;
|
|
|
|
|
}
|
|
|
|
|