Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
T
topology
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
姜立玮
topology
Commits
f3d0bf6c
提交
f3d0bf6c
authored
5月 13, 2020
作者:
RuoYi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
更换IP地址查询接口
上级
ddcabaa6
变更
2
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
21 行增加
和
11 行删除
+21
-11
HttpUtils.java
.../src/main/java/com/ruoyi/common/utils/http/HttpUtils.java
+1
-1
AddressUtils.java
...src/main/java/com/ruoyi/common/utils/ip/AddressUtils.java
+20
-10
没有找到文件。
ruoyi/src/main/java/com/ruoyi/common/utils/http/HttpUtils.java
浏览文件 @
f3d0bf6c
...
@@ -49,7 +49,7 @@ public class HttpUtils
...
@@ -49,7 +49,7 @@ public class HttpUtils
connection
.
setRequestProperty
(
"connection"
,
"Keep-Alive"
);
connection
.
setRequestProperty
(
"connection"
,
"Keep-Alive"
);
connection
.
setRequestProperty
(
"user-agent"
,
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"
);
connection
.
setRequestProperty
(
"user-agent"
,
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"
);
connection
.
connect
();
connection
.
connect
();
in
=
new
BufferedReader
(
new
InputStreamReader
(
connection
.
getInputStream
()));
in
=
new
BufferedReader
(
new
InputStreamReader
(
connection
.
getInputStream
()
,
"GBK"
));
String
line
;
String
line
;
while
((
line
=
in
.
readLine
())
!=
null
)
while
((
line
=
in
.
readLine
())
!=
null
)
{
{
...
...
ruoyi/src/main/java/com/ruoyi/common/utils/ip/AddressUtils.java
浏览文件 @
f3d0bf6c
...
@@ -16,11 +16,15 @@ public class AddressUtils
...
@@ -16,11 +16,15 @@ public class AddressUtils
{
{
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
AddressUtils
.
class
);
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
AddressUtils
.
class
);
public
static
final
String
IP_URL
=
"http://ip.taobao.com/service/getIpInfo.php"
;
// IP地址查询
public
static
final
String
IP_URL
=
"http://whois.pconline.com.cn/ipJson.jsp"
;
// 未知地址
public
static
final
String
UNKNOWN
=
"XX XX"
;
public
static
String
getRealAddressByIP
(
String
ip
)
public
static
String
getRealAddressByIP
(
String
ip
)
{
{
String
address
=
"XX XX"
;
String
address
=
UNKNOWN
;
// 内网不查询
// 内网不查询
if
(
IpUtils
.
internalIp
(
ip
))
if
(
IpUtils
.
internalIp
(
ip
))
{
{
...
@@ -28,17 +32,23 @@ public class AddressUtils
...
@@ -28,17 +32,23 @@ public class AddressUtils
}
}
if
(
RuoYiConfig
.
isAddressEnabled
())
if
(
RuoYiConfig
.
isAddressEnabled
())
{
{
String
rspStr
=
HttpUtils
.
sendPost
(
IP_URL
,
"ip="
+
ip
);
try
if
(
StringUtils
.
isEmpty
(
rspStr
))
{
String
rspStr
=
HttpUtils
.
sendGet
(
IP_URL
,
"ip="
+
ip
+
"&json=true"
);
if
(
StringUtils
.
isEmpty
(
rspStr
))
{
log
.
error
(
"获取地理位置异常 {}"
,
ip
);
return
UNKNOWN
;
}
JSONObject
obj
=
JSONObject
.
parseObject
(
rspStr
);
String
region
=
obj
.
getString
(
"pro"
);
String
city
=
obj
.
getString
(
"city"
);
return
String
.
format
(
"%s %s"
,
region
,
city
);
}
catch
(
Exception
e
)
{
{
log
.
error
(
"获取地理位置异常 {}"
,
ip
);
log
.
error
(
"获取地理位置异常 {}"
,
ip
);
return
address
;
}
}
JSONObject
obj
=
JSONObject
.
parseObject
(
rspStr
);
JSONObject
data
=
obj
.
getObject
(
"data"
,
JSONObject
.
class
);
String
region
=
data
.
getString
(
"region"
);
String
city
=
data
.
getString
(
"city"
);
address
=
region
+
" "
+
city
;
}
}
return
address
;
return
address
;
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论