提交 99dec99f authored 作者: 吴德鹏's avatar 吴德鹏

用户区分注册国家

上级 0aeac2a4
......@@ -4,15 +4,17 @@ import com.platform.annotation.IgnoreAuth;
import com.platform.entity.BASE64DecodedMultipartFile;
import com.platform.utils.OssUtil;
import com.platform.utils.R;
import com.platform.utils.util.HttpUtils;
import com.platform.utils.util.UuidUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Map;
/**
......@@ -24,6 +26,10 @@ import java.util.Map;
@RequestMapping(value = "/api/upload", produces = "application/json;charset=UTF-8")
public class uploadController {
public static final String LOCAL_IP = "127.0.0.1";//本地ip地址
public static final String DEFAULT_IP = "0:0:0:0:0:0:0:1";//默认ip地址
public static final int DEFAULT_IP_LENGTH = 15;//默认ip地址长度
@IgnoreAuth
@ResponseBody
@RequestMapping(value = "/uploadFile", produces = "application/json;charset=UTF-8")
......@@ -65,6 +71,60 @@ public class uploadController {
return R.error().put("fail", "删除失败");
}
}
@IgnoreAuth
@GetMapping("/getRealIp")
@ResponseBody
public R getRealIp(HttpServletRequest request) {
String ip = this.getRealIpAddress(request);
return R.ok().put("ip",ip);
}
/**
* 获取合法ip地址
* @param request
* @return
*/
public static String getRealIpAddress(HttpServletRequest request) {
String ip = request.getHeader("x-forwarded-for");//squid 服务代理
if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("Proxy-Client-IP");//apache服务代理
}
if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("WL-Proxy-Client-IP");//weblogic 代理
}
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("X-Real-IP"); //nginx代理
}
/*
* 如果此时还是获取不到ip地址,那么最后就使用request.getRemoteAddr()来获取
* */
if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getRemoteAddr();
if (StringUtils.equals(ip, LOCAL_IP) || StringUtils.equals(ip, DEFAULT_IP)) {
//根据网卡取本机配置的IP
InetAddress iNet = null;
try {
iNet = InetAddress.getLocalHost();
} catch (UnknownHostException e) {
}
ip = iNet.getHostAddress();
}
}//对于通过多个代理的情况,第一个IP为客户端真实IP,多个IP按照','分割
//"***.***.***.***".length() = 15
if(!StringUtils.isEmpty(ip) && ip.length()> DEFAULT_IP_LENGTH){
if(ip.indexOf(",") > 0){
ip = ip.substring(0,ip.indexOf(","));
}
}
return ip;
}
//
// @IgnoreAuth
// @ResponseBody
......
......@@ -101,6 +101,16 @@ public class TbCfUserInfoEntity implements Serializable {
*/
private Integer emailFlag;
private String country;
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public Integer getSource() {
return source;
}
......
......@@ -25,6 +25,7 @@
<result property="invitedCount" column="invited_count"/>
<result property="enableFlag" column="enable_flag"/>
<result property="emailFlag" column="email_flag"/>
<result property="country" column="country"/>
</resultMap>
<select id="queryObject" resultType="com.platform.entity.TbCfUserInfoEntity">
......
......@@ -6,6 +6,7 @@ $(function () {
{label: '用户编号', name: 'userNo', index: 'user_no', width: 160},
{label: '用户类型', name: 'userType', index: 'user_type', width: 80, formatter: userTypeFormat},
{label: '账号', name: 'account', index: 'account', width: 120},
{label: '国家', name: 'country', index: 'country', width: 100},
{label: '注册来源', name: 'source', index: 'source', width: 60, formatter: signTypeFormat},
{label: '用户头像地址', name: 'avatar', index: 'avatar', width: 100, formatter: imageFormat},
{label: '用户名', name: 'nick', index: 'nick', width: 80},
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论