bug--ip归属地查询改为用太平洋IP地址查询接口
This commit is contained in:
7
pom.xml
7
pom.xml
@ -157,12 +157,7 @@
|
||||
<artifactId>hutool-all</artifactId>
|
||||
<version>${hutool.version}</version>
|
||||
</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>
|
||||
|
@ -13,5 +13,5 @@ public enum LimitType {
|
||||
// 默认
|
||||
CUSTOMER,
|
||||
// by ip addr
|
||||
IP;
|
||||
IP
|
||||
}
|
||||
|
@ -143,7 +143,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();
|
||||
|
@ -5,17 +5,13 @@
|
||||
*/
|
||||
package co.yixiang.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;
|
||||
@ -150,35 +146,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(YshopConstant.REGION)?"内网IP":address;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
if(searcher!=null){
|
||||
try {
|
||||
searcher.close();
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return "";
|
||||
String api = String.format(YshopConstant.Url.IP_URL,ip);
|
||||
JSONObject object = JSONUtil.parseObj(HttpUtil.get(api));
|
||||
return object.get("addr", String.class);
|
||||
}
|
||||
|
||||
public static String getBrowser(HttpServletRequest request){
|
||||
|
@ -16,15 +16,14 @@ public class YshopConstant {
|
||||
|
||||
public static final String RESET_MAIL = "重置邮箱";
|
||||
|
||||
/**
|
||||
* 用于IP定位转换
|
||||
*/
|
||||
static final String REGION = "内网IP|内网IP";
|
||||
|
||||
/**
|
||||
* 常用接口
|
||||
*/
|
||||
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";
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
Reference in New Issue
Block a user