Skip to content

Commit

Permalink
[代码完善](v2.5): v2.5 beta ip归属地查询改为用太平洋IP地址查询接口
Browse files Browse the repository at this point in the history
  • Loading branch information
elunez committed May 11, 2020
1 parent a51aeb6 commit 3095f37
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ public enum LimitType {
// 默认
CUSTOMER,
// by ip addr
IP;
IP
}
3 changes: 1 addition & 2 deletions eladmin-common/src/main/java/me/zhengjie/base/BaseDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@
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> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public void handleCacheClearError(RuntimeException e, Cache cache) {
*/
class FastJsonRedisSerializer<T> implements RedisSerializer<T> {

private Class<T> clazz;
private final Class<T> clazz;

FastJsonRedisSerializer(Class<T> clazz) {
super();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@
*/
public class ElAdminConstant {

/**
* 用于IP定位转换
*/
public static final String REGION = "内网IP|内网IP";

/**
* win 系统
*/
Expand All @@ -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";
}
}
37 changes: 0 additions & 37 deletions eladmin-common/src/main/java/me/zhengjie/utils/FileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@
*/
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;
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;
Expand Down Expand Up @@ -126,26 +124,6 @@ public static String getSize(long size){
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;
}

/**
* 将文件名解析成文件的上传路径
*/
Expand Down Expand Up @@ -173,16 +151,6 @@ public static File upload(MultipartFile file, String filePath) {
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
*/
Expand Down Expand Up @@ -222,11 +190,6 @@ public static String getFileType(String type) {
}
}

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;
Expand Down
42 changes: 6 additions & 36 deletions eladmin-common/src/main/java/me/zhengjie/utils/StringUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -159,35 +155,9 @@ public static String getIp(HttpServletRequest request) {
* 根据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){
Expand Down
Binary file not shown.
6 changes: 0 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit 3095f37

Please sign in to comment.