mirror of https://github.com/elunez/eladmin
[代码完善](v2.5): v2.5 beta ip归属地查询改为用太平洋IP地址查询接口
2.5 Beta 详情:https://www.ydyno.com/archives/1225.htmlpull/361/head^2
parent
a51aeb604b
commit
3095f3730e
|
@ -23,5 +23,5 @@ public enum LimitType {
|
|||
// 默认
|
||||
CUSTOMER,
|
||||
// by ip addr
|
||||
IP;
|
||||
IP
|
||||
}
|
||||
|
|
|
@ -3,14 +3,13 @@ package me.zhengjie.base;
|
|||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Field;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @Date 2019年10月24日20:48:53
|
||||
* @date 2019年10月24日20:48:53
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
|
|
|
@ -21,10 +21,9 @@ import org.springframework.stereotype.Component;
|
|||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @描述 : 设置审计
|
||||
* @description : 设置审计
|
||||
* @author : Dong ZhaoYang
|
||||
* @日期 : 2019/10/28
|
||||
* @时间 : 10:29
|
||||
* @date : 2019/10/28
|
||||
*/
|
||||
@Component("auditorAware")
|
||||
public class AuditorConfig implements AuditorAware<String> {
|
||||
|
|
|
@ -153,7 +153,7 @@ public class RedisConfig extends CachingConfigurerSupport {
|
|||
*/
|
||||
class FastJsonRedisSerializer<T> implements RedisSerializer<T> {
|
||||
|
||||
private Class<T> clazz;
|
||||
private final Class<T> clazz;
|
||||
|
||||
FastJsonRedisSerializer(Class<T> clazz) {
|
||||
super();
|
||||
|
|
|
@ -22,11 +22,6 @@ package me.zhengjie.utils;
|
|||
*/
|
||||
public class ElAdminConstant {
|
||||
|
||||
/**
|
||||
* 用于IP定位转换
|
||||
*/
|
||||
public static final String REGION = "内网IP|内网IP";
|
||||
|
||||
/**
|
||||
* win 系统
|
||||
*/
|
||||
|
@ -41,6 +36,9 @@ public class ElAdminConstant {
|
|||
* 常用接口
|
||||
*/
|
||||
public static class Url{
|
||||
// 免费图床
|
||||
public static final String SM_MS_URL = "https://sm.ms/api";
|
||||
// IP归属地查询
|
||||
public static final String IP_URL = "http://whois.pconline.com.cn/ipJson.jsp?ip=%s&json=true";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
*/
|
||||
package me.zhengjie.utils;
|
||||
|
||||
import cn.hutool.core.codec.Base64;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.poi.excel.BigExcelWriter;
|
||||
|
@ -23,7 +22,6 @@ import cn.hutool.poi.excel.ExcelUtil;
|
|||
import me.zhengjie.exception.BadRequestException;
|
||||
import org.apache.poi.util.IOUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import javax.activation.MimetypesFileTypeMap;
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
@ -126,26 +124,6 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
|
|||
return resultSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* inputStream 转 File
|
||||
*/
|
||||
static File inputStreamToFile(InputStream ins, String name) throws Exception{
|
||||
File file = new File(System.getProperty("java.io.tmpdir") + File.separator + name);
|
||||
if (file.exists()) {
|
||||
return file;
|
||||
}
|
||||
OutputStream os = new FileOutputStream(file);
|
||||
int bytesRead;
|
||||
int len = 8192;
|
||||
byte[] buffer = new byte[len];
|
||||
while ((bytesRead = ins.read(buffer, 0, len)) != -1) {
|
||||
os.write(buffer, 0, bytesRead);
|
||||
}
|
||||
os.close();
|
||||
ins.close();
|
||||
return file;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将文件名解析成文件的上传路径
|
||||
*/
|
||||
|
@ -173,16 +151,6 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
|
|||
return null;
|
||||
}
|
||||
|
||||
public static String fileToBase64(File file) throws Exception {
|
||||
FileInputStream inputFile = new FileInputStream(file);
|
||||
String base64;
|
||||
byte[] buffer = new byte[(int)file.length()];
|
||||
inputFile.read(buffer);
|
||||
inputFile.close();
|
||||
base64=Base64.encode(buffer);
|
||||
return base64.replaceAll("[\\s*\t\n\r]", "");
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出excel
|
||||
*/
|
||||
|
@ -222,11 +190,6 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
|
|||
}
|
||||
}
|
||||
|
||||
public static String getFileTypeByMimeType(String type) {
|
||||
String mimeType = new MimetypesFileTypeMap().getContentType("." + type);
|
||||
return mimeType.split("/")[0];
|
||||
}
|
||||
|
||||
public static void checkSize(long maxSize, long size) {
|
||||
// 1M
|
||||
int len = 1024 * 1024;
|
||||
|
|
|
@ -15,16 +15,12 @@
|
|||
*/
|
||||
package me.zhengjie.utils;
|
||||
|
||||
import cn.hutool.core.io.resource.ClassPathResource;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import eu.bitwalker.useragentutils.Browser;
|
||||
import eu.bitwalker.useragentutils.UserAgent;
|
||||
import org.lionsoul.ip2region.DataBlock;
|
||||
import org.lionsoul.ip2region.DbConfig;
|
||||
import org.lionsoul.ip2region.DbSearcher;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Calendar;
|
||||
|
@ -159,35 +155,9 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
|||
* 根据ip获取详细地址
|
||||
*/
|
||||
public static String getCityInfo(String ip) {
|
||||
DbSearcher searcher = null;
|
||||
try {
|
||||
String path = "ip2region/ip2region.db";
|
||||
String name = "ip2region.db";
|
||||
DbConfig config = new DbConfig();
|
||||
File file = FileUtil.inputStreamToFile(new ClassPathResource(path).getStream(), name);
|
||||
searcher = new DbSearcher(config, file.getPath());
|
||||
Method method;
|
||||
method = searcher.getClass().getMethod("btreeSearch", String.class);
|
||||
DataBlock dataBlock;
|
||||
dataBlock = (DataBlock) method.invoke(searcher, ip);
|
||||
String address = dataBlock.getRegion().replace("0|","");
|
||||
char symbol = '|';
|
||||
if(address.charAt(address.length()-1) == symbol){
|
||||
address = address.substring(0,address.length() - 1);
|
||||
}
|
||||
return address.equals(ElAdminConstant.REGION)?"内网IP":address;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
if(searcher!=null){
|
||||
try {
|
||||
searcher.close();
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return "";
|
||||
String api = String.format(ElAdminConstant.Url.IP_URL,ip);
|
||||
JSONObject object = JSONUtil.parseObj(HttpUtil.get(api));
|
||||
return object.get("addr", String.class);
|
||||
}
|
||||
|
||||
public static String getBrowser(HttpServletRequest request){
|
||||
|
|
Binary file not shown.
6
pom.xml
6
pom.xml
|
@ -140,12 +140,6 @@
|
|||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<!--https://gitee.com/lionsoul/ip2region/tree/v1.4-release/-->
|
||||
<dependency>
|
||||
<groupId>org.lionsoul</groupId>
|
||||
<artifactId>ip2region</artifactId>
|
||||
<version>1.7.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>poi</artifactId>
|
||||
|
|
Loading…
Reference in New Issue