Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
eshiled-new
/
ne-shield-devicemonitor
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 6b494e08
authored
Jan 15, 2025
by
谢海旭
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
v1.77.1 通过wifi mac信息查询经纬度
1 parent
1d9957f2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
135 additions
and
9 deletions
src/main/java/cn/com/glsx/devicemonitor/modules/components/HdaoGpsComponent.java
src/main/java/cn/com/glsx/devicemonitor/modules/utils/MapUtil.java
src/main/java/cn/com/glsx/devicemonitor/modules/components/HdaoGpsComponent.java
View file @
6b494e0
...
@@ -850,15 +850,11 @@ public class HdaoGpsComponent {
...
@@ -850,15 +850,11 @@ public class HdaoGpsComponent {
return
null
;
return
null
;
}
}
wifiData
[]
wifiDataArr
=
wifiResponse
.
records
;
wifiData
[]
wifiDataArr
=
wifiResponse
.
records
;
StringBuffer
macStr
=
new
StringBuffer
();
String
macStr
=
Arrays
.
stream
(
wifiDataArr
).
map
(
wifiData
->
String
.
format
(
"%s,%d,"
,
wifiData
.
mac
,
wifiData
.
single
)).
collect
(
Collectors
.
joining
(
"|"
));
for
(
wifiData
data
:
wifiDataArr
)
{
String
mac
=
data
.
mac
;
log
.
info
(
"sn:"
+
sn
+
"mac:"
+
macStr
);
macStr
.
append
(
mac
);
macStr
.
append
(
"|"
);
}
log
.
info
(
"sn:"
+
sn
+
"mac:"
+
macStr
.
toString
());
//解析mac地址获取定位
//解析mac地址获取定位
WifiMapInfoModel
wifiMapInfoModel
=
MapUtil
.
getWifiLo
actionByMac
(
macStr
.
toString
()
);
WifiMapInfoModel
wifiMapInfoModel
=
MapUtil
.
getWifiLo
cationByMacWithBaidu
(
macStr
);
if
(
wifiMapInfoModel
==
null
||
wifiMapInfoModel
.
getLocation
()
==
null
||
wifiMapInfoModel
.
getType
().
equals
(
"0"
))
{
if
(
wifiMapInfoModel
==
null
||
wifiMapInfoModel
.
getLocation
()
==
null
||
wifiMapInfoModel
.
getType
().
equals
(
"0"
))
{
log
.
info
(
"解析mac 获取地址失败。定位数据:"
+
JSONUtil
.
toJsonStr
(
wifiMapInfoModel
));
log
.
info
(
"解析mac 获取地址失败。定位数据:"
+
JSONUtil
.
toJsonStr
(
wifiMapInfoModel
));
return
null
;
return
null
;
...
@@ -872,6 +868,8 @@ public class HdaoGpsComponent {
...
@@ -872,6 +868,8 @@ public class HdaoGpsComponent {
gpsLocation
.
setLat
(
lngLat
[
1
]);
gpsLocation
.
setLat
(
lngLat
[
1
]);
gpsLocation
.
setElng
(
lngLat
[
0
]);
gpsLocation
.
setElng
(
lngLat
[
0
]);
gpsLocation
.
setElat
(
lngLat
[
1
]);
gpsLocation
.
setElat
(
lngLat
[
1
]);
gpsLocation
.
setBlng
(
lngLat
[
0
]);
gpsLocation
.
setBlat
(
lngLat
[
1
]);
gpsLocation
.
setAddress
(
wifiMapInfoModel
.
getDesc
());
gpsLocation
.
setAddress
(
wifiMapInfoModel
.
getDesc
());
gpsLocation
.
setStoreTime
(
DateUtil
.
formatDateTime
(
date
));
gpsLocation
.
setStoreTime
(
DateUtil
.
formatDateTime
(
date
));
gpsLocation
.
setDateTime
(
DateUtil
.
formatDateTime
(
date
));
gpsLocation
.
setDateTime
(
DateUtil
.
formatDateTime
(
date
));
...
...
src/main/java/cn/com/glsx/devicemonitor/modules/utils/MapUtil.java
View file @
6b494e0
package
cn
.
com
.
glsx
.
devicemonitor
.
modules
.
utils
;
package
cn
.
com
.
glsx
.
devicemonitor
.
modules
.
utils
;
import
cn.com.glsx.devicemonitor.modules.model.WifiMapInfoModel
;
import
cn.com.glsx.devicemonitor.modules.model.WifiMapInfoModel
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.glsx.plat.common.utils.HttpUtils
;
import
com.glsx.plat.common.utils.HttpUtils
;
import
com.glsx.plat.context.utils.PropertiesUtils
;
import
com.glsx.plat.context.utils.PropertiesUtils
;
import
io.micrometer.core.instrument.util.JsonUtil
s
;
import
com.google.common.collect.List
s
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang.StringUtils
;
import
org.apache.commons.lang.StringUtils
;
...
@@ -21,6 +23,132 @@ public class MapUtil {
...
@@ -21,6 +23,132 @@ public class MapUtil {
* @return
* @return
*/
*/
public
static
WifiMapInfoModel
getWifiLoactionByMac
(
String
macs
)
{
public
static
WifiMapInfoModel
getWifiLoactionByMac
(
String
macs
)
{
return
getWifiLocationByMacWithAmap
(
macs
);
}
/**
* 通过百度地图解析wifi位置信息
* "macs": "34:47:d4:bb:90:75,66,|44:97:5a:d6:fc:70,66,"
*
* @param macs
* @return
*/
public
static
WifiMapInfoModel
getWifiLocationByMacWithBaidu
(
String
macs
)
{
String
key
=
PropertiesUtils
.
getProperty
(
"baidu.map.key"
);
Map
<
String
,
Object
>
body
=
new
HashMap
<>();
body
.
put
(
"key"
,
key
);
body
.
put
(
"ver"
,
"1.0"
);
body
.
put
(
"trace"
,
false
);
body
.
put
(
"prod"
,
"test_loc_api"
);
body
.
put
(
"src"
,
"baidu_loc_api"
);
Map
<
String
,
Object
>
dataForLngLat
=
new
HashMap
<>();
dataForLngLat
.
put
(
"output"
,
"JSON"
);
dataForLngLat
.
put
(
"accesstype"
,
1
);
dataForLngLat
.
put
(
"imei"
,
"xxxxxxxxxxxxxxx"
);
dataForLngLat
.
put
(
"macs"
,
macs
);
dataForLngLat
.
put
(
"ctime"
,
String
.
valueOf
(
System
.
currentTimeMillis
()));
dataForLngLat
.
put
(
"need_rgc"
,
"Y"
);
body
.
put
(
"body"
,
Lists
.
newArrayList
(
dataForLngLat
));
try
{
String
url
=
"https://api.map.baidu.com/locapi/v2"
;
String
result
=
HttpUtils
.
post
(
url
,
JSON
.
toJSONString
(
body
));
JSONObject
jsonObject
=
JSON
.
parseObject
(
result
);
int
errcode
=
jsonObject
.
getIntValue
(
"errcode"
);
if
(
errcode
!=
0
)
{
log
.
error
(
"getWifiLocationByMacWithBaidu error msg:{}"
,
jsonObject
.
getString
(
"msg"
));
return
null
;
}
else
{
JSONArray
models
=
jsonObject
.
getJSONArray
(
"body"
);
JSONObject
model
=
models
.
getJSONObject
(
0
);
WifiMapInfoModel
rModel
=
new
WifiMapInfoModel
();
rModel
.
setType
(
model
.
getString
(
"type"
));
rModel
.
setLocation
(
model
.
getString
(
"location"
));
rModel
.
setRadius
(
model
.
getString
(
"radius"
));
rModel
.
setCountry
(
model
.
getString
(
"country"
));
rModel
.
setProvince
(
model
.
getString
(
"province"
));
rModel
.
setCity
(
model
.
getString
(
"city"
));
rModel
.
setCitycode
(
model
.
getString
(
"citycode"
));
rModel
.
setRoad
(
model
.
getString
(
"road"
));
String
desc
=
rModel
.
getCountry
()
+
rModel
.
getProvince
()
+
rModel
.
getCity
()
+
model
.
getString
(
"district"
)
+
rModel
.
getRoad
();
rModel
.
setDesc
(
desc
);
return
rModel
;
}
}
catch
(
Exception
e
)
{
log
.
error
(
"getWifiLocationByMacWithBaidu error"
,
e
);
return
null
;
}
}
/**
* 使用百度地图查询经纬度对应的位置信息
*
* @param bLng
* @param BLat
* @return
*/
public
static
String
getAddressByLngLatWithBaiduMaps
(
String
bLng
,
String
BLat
)
{
if
(
StringUtils
.
isEmpty
(
bLng
)
||
StringUtils
.
isEmpty
(
BLat
))
{
return
null
;
}
String
key
=
PropertiesUtils
.
getProperty
(
"baidu.map.key"
);
StringBuilder
baiduMapUrl
=
new
StringBuilder
();
baiduMapUrl
.
append
(
"https://api.map.baidu.com/reverse_geocoding/v3/?output=json"
);
baiduMapUrl
.
append
(
"&ak="
).
append
(
key
);
baiduMapUrl
.
append
(
"&coordtype=wgs84ll"
);
baiduMapUrl
.
append
(
"&location="
).
append
(
BLat
).
append
(
","
).
append
(
bLng
);
String
resultStr
=
requestGeoByBaiduMapUrl
(
baiduMapUrl
.
toString
());
if
(
StringUtils
.
isBlank
(
resultStr
))
{
return
null
;
}
JSONObject
jo
=
JSON
.
parseObject
(
resultStr
);
JSONObject
ac
=
jo
.
getJSONObject
(
"result"
).
getJSONObject
(
"addressComponent"
);
return
ac
.
getString
(
"province"
)
+
ac
.
getString
(
"city"
)
+
ac
.
getString
(
"district"
)
+
ac
.
getString
(
"town"
)
+
ac
.
getString
(
"street"
)
+
ac
.
getString
(
"street_number"
);
}
/**
* 调用百度地图接口
*
* @param baiduMapUrl
* @return
*/
public
static
String
requestGeoByBaiduMapUrl
(
String
baiduMapUrl
)
{
String
result
=
""
;
try
{
result
=
HttpUtils
.
get
(
baiduMapUrl
);
}
catch
(
Exception
e
)
{
log
.
info
(
"Request 百度 parse address Exception, messeg:"
+
e
.
getMessage
());
e
.
printStackTrace
();
return
null
;
}
if
(
StringUtils
.
isEmpty
(
result
))
{
log
.
info
(
"Request 百度 parse address is empty, result:"
+
result
);
return
null
;
}
JSONObject
resultObj
=
JSON
.
parseObject
(
result
);
if
(!
resultObj
.
getString
(
"status"
).
equals
(
"0"
))
{
log
.
error
(
"Request 百度 parse address wrong, status:"
+
resultObj
.
get
(
"status"
)
+
" message:"
+
resultObj
.
get
(
"message"
));
return
null
;
}
return
result
;
}
/**
* 通过高德地图解析wifi位置信息
* "macs": "26:D7:EB:DA:30:CF|7A:91:E9:DC:F0:61|"
*
* @param macs
* @return
*/
private
static
WifiMapInfoModel
getWifiLocationByMacWithAmap
(
String
macs
)
{
String
url
=
"http://apilocate.amap.com/position"
;
String
url
=
"http://apilocate.amap.com/position"
;
String
gaoDeKey
=
PropertiesUtils
.
getProperty
(
"gao.de.map.key"
);
String
gaoDeKey
=
PropertiesUtils
.
getProperty
(
"gao.de.map.key"
);
if
(
StringUtils
.
isBlank
(
gaoDeKey
))
{
if
(
StringUtils
.
isBlank
(
gaoDeKey
))
{
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment