|
@@ -1,6 +1,7 @@
|
|
|
package com.qingjian.common.utils;
|
|
package com.qingjian.common.utils;
|
|
|
|
|
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
|
|
+import cn.hutool.core.util.ReUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.qingjian.common.constants.PathConst;
|
|
import com.qingjian.common.constants.PathConst;
|
|
|
import com.sun.jna.ptr.DoubleByReference;
|
|
import com.sun.jna.ptr.DoubleByReference;
|
|
@@ -24,8 +25,10 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
@Slf4j
|
|
@Slf4j
|
|
|
public class TowerUtils {
|
|
public class TowerUtils {
|
|
|
|
|
|
|
|
- private static final int ADDRESS_BUFFER_SIZE = 2048;
|
|
|
|
|
|
|
+ private static final int ADDRESS_BUFFER_SIZE = 1024;
|
|
|
private static final AtomicBoolean FLAG = new AtomicBoolean(false);
|
|
private static final AtomicBoolean FLAG = new AtomicBoolean(false);
|
|
|
|
|
+ // 16进制判断正则
|
|
|
|
|
+ private static final String lacCellReg = ".*[A-Fa-f].*";
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 根据操作系统类型返回对应的动态链接库路径
|
|
* 根据操作系统类型返回对应的动态链接库路径
|
|
@@ -93,12 +96,15 @@ public class TowerUtils {
|
|
|
* 返回示例:[35.994564, 12.468795, 123, "北京市朝阳xxx4号楼;望京街xx163米"]
|
|
* 返回示例:[35.994564, 12.468795, 123, "北京市朝阳xxx4号楼;望京街xx163米"]
|
|
|
* </p>
|
|
* </p>
|
|
|
*/
|
|
*/
|
|
|
- public static Object[] getCells(int mcc, int mnc, int lac, int ci) {
|
|
|
|
|
|
|
+ public static Object[] getCells(int mcc, int mnc, String lac, String ci) {
|
|
|
Object[] result = new Object[4];
|
|
Object[] result = new Object[4];
|
|
|
if (!FLAG.get()) {
|
|
if (!FLAG.get()) {
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+ Radix radix = convertRadix(lac, ci);
|
|
|
|
|
+ if (!radix.status) {
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
// 创建用于接收查询结果的引用对象
|
|
// 创建用于接收查询结果的引用对象
|
|
|
DoubleByReference latitude = new DoubleByReference(0.0); // WGS84 纬度
|
|
DoubleByReference latitude = new DoubleByReference(0.0); // WGS84 纬度
|
|
|
DoubleByReference longitude = new DoubleByReference(0.0); // WGS84 经度
|
|
DoubleByReference longitude = new DoubleByReference(0.0); // WGS84 经度
|
|
@@ -106,7 +112,7 @@ public class TowerUtils {
|
|
|
|
|
|
|
|
|
|
|
|
|
// 调用本地库查询基站信息
|
|
// 调用本地库查询基站信息
|
|
|
- int queryResult = CellDll.INSTANCE_DLL.cell_query_combined(mcc, mnc, lac, ci,
|
|
|
|
|
|
|
+ int queryResult = CellDll.INSTANCE_DLL.cell_query_combined(mcc, mnc, radix.lac, radix.cid,
|
|
|
CellDll.COORD_WGS84, latitude, longitude, combined, combined.length);
|
|
CellDll.COORD_WGS84, latitude, longitude, combined, combined.length);
|
|
|
// 如果查询失败,返回空数组
|
|
// 如果查询失败,返回空数组
|
|
|
if (queryResult != 0) {
|
|
if (queryResult != 0) {
|
|
@@ -122,7 +128,36 @@ public class TowerUtils {
|
|
|
result[2] = 0;
|
|
result[2] = 0;
|
|
|
|
|
|
|
|
// 逆地理编码依旧使用原始 WGS84 坐标,保持与现有 native 接口行为一致。
|
|
// 逆地理编码依旧使用原始 WGS84 坐标,保持与现有 native 接口行为一致。
|
|
|
- result[3] = StrUtil.str(combined, StandardCharsets.UTF_8);
|
|
|
|
|
|
|
+ String str = StrUtil.str(combined, StandardCharsets.UTF_8);
|
|
|
|
|
+ if (StrUtil.isNotEmpty(str)) {
|
|
|
|
|
+ result[3] = str.trim();
|
|
|
|
|
+ }
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ private static Radix convertRadix(String lacStr, String ci) {
|
|
|
|
|
+ // 判断是否为16进制
|
|
|
|
|
+ boolean lacMatch = ReUtil.isMatch(lacCellReg, lacStr);
|
|
|
|
|
+ boolean ciMatch = ReUtil.isMatch(lacCellReg, ci);
|
|
|
|
|
+ long lac;
|
|
|
|
|
+ if (lacMatch) {
|
|
|
|
|
+ lac = Long.parseLong(lacStr, 16);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ lac = Long.parseLong(lacStr);
|
|
|
|
|
+ }
|
|
|
|
|
+ long cid;
|
|
|
|
|
+ if (ciMatch) {
|
|
|
|
|
+ cid = Long.parseLong(ci, 16);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ cid = Long.parseLong(ci);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (cid <= Integer.MAX_VALUE) {
|
|
|
|
|
+ return new Radix(true, (int) lac, (int) cid);
|
|
|
|
|
+ }
|
|
|
|
|
+ return new Radix(false, 0, 0);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private record Radix(boolean status, int lac, int cid) {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|