From 73b3673758611efb0ec89a2d9ce51a43ed79d7a0 Mon Sep 17 00:00:00 2001
From: Frank <3224536684@qq.com>
Date: Tue, 18 Jul 2023 17:27:49 +0800
Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E5=AE=8C=E5=96=84VCS,LBS,OTA?=
=?UTF-8?q?=E7=AD=89API=E6=93=8D=E4=BD=9C?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../net/javase/onenet/api/ApiResponse.java | 2 +
.../java/net/javase/onenet/api/FuseApi.java | 306 ++++++++++++++++++
.../net/javase/onenet/model/FuseLbsModel.java | 83 +++++
.../net/javase/onenet/model/FuseOtaModel.java | 69 ++++
.../model/RegistDeviceIdentityModel.java | 39 +++
.../javase/onenet/model/VoiceNotifyModel.java | 107 ++++++
.../net/javase/onenet/utils/RequestUtil.java | 44 +++
7 files changed, 650 insertions(+)
create mode 100644 src/main/java/net/javase/onenet/api/FuseApi.java
create mode 100644 src/main/java/net/javase/onenet/model/FuseLbsModel.java
create mode 100644 src/main/java/net/javase/onenet/model/FuseOtaModel.java
create mode 100644 src/main/java/net/javase/onenet/model/RegistDeviceIdentityModel.java
create mode 100644 src/main/java/net/javase/onenet/model/VoiceNotifyModel.java
diff --git a/src/main/java/net/javase/onenet/api/ApiResponse.java b/src/main/java/net/javase/onenet/api/ApiResponse.java
index 5874d1d..43326c2 100644
--- a/src/main/java/net/javase/onenet/api/ApiResponse.java
+++ b/src/main/java/net/javase/onenet/api/ApiResponse.java
@@ -17,6 +17,8 @@ import java.util.Map;
@Setter
public class ApiResponse implements Serializable {
+ private static final long serialVersionUID = -1380654611024977212L;
+
private Integer code;
private String msg;
diff --git a/src/main/java/net/javase/onenet/api/FuseApi.java b/src/main/java/net/javase/onenet/api/FuseApi.java
new file mode 100644
index 0000000..bb66312
--- /dev/null
+++ b/src/main/java/net/javase/onenet/api/FuseApi.java
@@ -0,0 +1,306 @@
+package net.javase.onenet.api;
+
+import cn.hutool.http.ContentType;
+import cn.hutool.http.Method;
+import net.javase.onenet.config.Config;
+import net.javase.onenet.enums.ApiEnum;
+import net.javase.onenet.enums.SignMethod;
+import net.javase.onenet.model.FuseLbsModel;
+import net.javase.onenet.model.FuseOtaModel;
+import net.javase.onenet.model.RegistDeviceIdentityModel;
+import net.javase.onenet.model.VoiceNotifyModel;
+import net.javase.onenet.utils.RequestUtil;
+
+import java.io.File;
+import java.util.Map;
+
+/**
+ * FuseApi
+ *
+ * @author Frank
+ */
+public class FuseApi {
+
+ /**
+ * 批量自动注册标识
+ *
+ * @param config {@link Config}
+ * @param body http body参数
+ * @return {@link ApiResponse}
+ */
+ public static ApiResponse batchAutoRegistDeviceIdentity(Config config, Map body) {
+ return ApiRequest.builder()
+ .api(ApiEnum.FUSE_IDENTITY_DEVICE.api())
+ .method(Method.POST)
+ .contentType(ContentType.JSON)
+ .signMethod(SignMethod.MD5)
+ .body(body)
+ .userid(config.getUserid())
+ .build()
+ .send(config.getAccessKey());
+ }
+
+ /**
+ * 批量自动注册标识
+ *
+ * @param config {@link Config}
+ * @param model {@link RegistDeviceIdentityModel}
+ * @return {@link ApiResponse}
+ */
+ public static ApiResponse batchAutoRegistDeviceIdentity(Config config, RegistDeviceIdentityModel model) {
+ return batchAutoRegistDeviceIdentity(config, model.toMap());
+ }
+
+ /**
+ * 批量自动注册标识
+ *
+ * @param config {@link Config}
+ * @param body http body参数
+ * @return {@link ApiResponse}
+ */
+ public static ApiResponse voiceNotify(Config config, Map body) {
+ return ApiRequest.builder()
+ .api(ApiEnum.VOICE_NOTIFY.api())
+ .method(Method.POST)
+ .contentType(ContentType.JSON)
+ .signMethod(SignMethod.MD5)
+ .body(body)
+ .userid(config.getUserid())
+ .build()
+ .send(config.getAccessKey());
+ }
+
+ /**
+ * 批量自动注册标识
+ *
+ * @param config {@link Config}
+ * @param model {@link VoiceNotifyModel}
+ * @return {@link ApiResponse}
+ */
+ public static ApiResponse voiceNotify(Config config, VoiceNotifyModel model) {
+ return voiceNotify(config, model.toMap());
+ }
+
+ /**
+ * 基站定位获取最新位置
+ *
+ * @param config {@link Config}
+ * @param query http query参数
+ * @return {@link ApiResponse}
+ */
+ public static ApiResponse latestLocation(Config config, Map query) {
+ return ApiRequest.builder()
+ .api(ApiEnum.LBS_LATEST_LOCATION.api())
+ .method(Method.GET)
+ .signMethod(SignMethod.MD5)
+ .query(query)
+ .userid(config.getUserid())
+ .build()
+ .send(config.getAccessKey());
+ }
+
+ /**
+ * 基站定位获取最新位置
+ *
+ * @param config {@link Config}
+ * @param model {@link FuseLbsModel}
+ * @return {@link ApiResponse}
+ */
+ public static ApiResponse latestLocation(Config config, FuseLbsModel model) {
+ return latestLocation(config, model.toMap());
+ }
+
+ /**
+ * 基站定位历史轨迹查询
+ *
+ * @param config {@link Config}
+ * @param query http query参数
+ * @return {@link ApiResponse}
+ */
+ public static ApiResponse getTrail(Config config, Map query) {
+ return ApiRequest.builder()
+ .api(ApiEnum.LBS_GET_TRAIL.api())
+ .method(Method.GET)
+ .signMethod(SignMethod.MD5)
+ .query(query)
+ .userid(config.getUserid())
+ .build()
+ .send(config.getAccessKey());
+ }
+
+ /**
+ * 基站定位历史轨迹查询
+ *
+ * @param config {@link Config}
+ * @param model {@link FuseLbsModel}
+ * @return {@link ApiResponse}
+ */
+ public static ApiResponse getTrail(Config config, FuseLbsModel model) {
+ return getTrail(config, model.toMap());
+ }
+
+ /**
+ * WIFI定位获取最新位置
+ *
+ * @param config {@link Config}
+ * @param query http query参数
+ * @return {@link ApiResponse}
+ */
+ public static ApiResponse latestWifiLocation(Config config, Map query) {
+ return ApiRequest.builder()
+ .api(ApiEnum.LBS_LATEST_WIFI_LOCATION.api())
+ .method(Method.GET)
+ .signMethod(SignMethod.MD5)
+ .query(query)
+ .userid(config.getUserid())
+ .build()
+ .send(config.getAccessKey());
+ }
+
+ /**
+ * WIFI定位获取最新位置
+ *
+ * @param config {@link Config}
+ * @param model {@link FuseLbsModel}
+ * @return {@link ApiResponse}
+ */
+ public static ApiResponse latestWifiLocation(Config config, FuseLbsModel model) {
+ return latestWifiLocation(config, model.toMap());
+ }
+
+ /**
+ * WIFI定位历史轨迹查询
+ *
+ * @param config {@link Config}
+ * @param query http query参数
+ * @return {@link ApiResponse}
+ */
+ public static ApiResponse getWifiTrail(Config config, Map query) {
+ return ApiRequest.builder()
+ .api(ApiEnum.LBS_GET_WIFI_TRAIL.api())
+ .method(Method.GET)
+ .signMethod(SignMethod.MD5)
+ .query(query)
+ .userid(config.getUserid())
+ .build()
+ .send(config.getAccessKey());
+ }
+
+ /**
+ * WIFI定位历史轨迹查询
+ *
+ * @param config {@link Config}
+ * @param model {@link FuseLbsModel}
+ * @return {@link ApiResponse}
+ */
+ public static ApiResponse getWifiTrail(Config config, FuseLbsModel model) {
+ return getWifiTrail(config, model.toMap());
+ }
+
+ /**
+ * 检测升级任务
+ *
+ * @param config {@link Config}
+ * @param model {@link FuseOtaModel}
+ * @return {@link ApiResponse}
+ */
+ public static ApiResponse otaCheck(Config config, FuseOtaModel model) {
+ return ApiRequest.builder()
+ .api(ApiEnum.OTA_CHECK.api(model.getProId(), model.getDevName()))
+ .method(Method.GET)
+ .signMethod(SignMethod.MD5)
+ .query(model.toMap())
+ .userid(config.getUserid())
+ .build()
+ .send(config.getAccessKey());
+ }
+
+ /**
+ * 下载升级包
+ *
+ * @param config {@link Config}
+ * @param model {@link FuseOtaModel}
+ * @param target {@link File}
+ */
+ public static void otaDownload(Config config, FuseOtaModel model, File target) {
+ RequestUtil.download(ApiRequest.builder()
+ .api(ApiEnum.OTA_DOWNLOAD.api(model.getProId(), model.getDevName(), model.getTid()))
+ .method(Method.GET)
+ .signMethod(SignMethod.MD5)
+ .query(model.toMap())
+ .userid(config.getUserid())
+ .build(), config.getAccessKey(), target);
+ }
+
+ /**
+ * 上报升级状态
+ *
+ * @param config {@link Config}
+ * @param model {@link FuseOtaModel}
+ * @return {@link ApiResponse}
+ */
+ public static ApiResponse otaStatus(Config config, FuseOtaModel model) {
+ return ApiRequest.builder()
+ .api(ApiEnum.OTA_STATUS.api(model.getProId(), model.getDevName(), model.getTid()))
+ .method(Method.POST)
+ .signMethod(SignMethod.MD5)
+ .query(model.toMap())
+ .userid(config.getUserid())
+ .build()
+ .send(config.getAccessKey());
+ }
+
+
+ /**
+ * 检测升级状态
+ *
+ * @param config {@link Config}
+ * @param model {@link FuseOtaModel}
+ * @return {@link ApiResponse}
+ */
+ public static ApiResponse otaTidCheck(Config config, FuseOtaModel model) {
+ return ApiRequest.builder()
+ .api(ApiEnum.OTA_TID_CHECK.api(model.getProId(), model.getDevName(), model.getTid()))
+ .method(Method.GET)
+ .signMethod(SignMethod.MD5)
+ .query(model.toMap())
+ .userid(config.getUserid())
+ .build()
+ .send(config.getAccessKey());
+ }
+
+ /**
+ * 查看设备版本号
+ *
+ * @param config {@link Config}
+ * @param model {@link FuseOtaModel}
+ * @return {@link ApiResponse}
+ */
+ public static ApiResponse otaVersion(Config config, FuseOtaModel model) {
+ return ApiRequest.builder()
+ .api(ApiEnum.OTA_VERSION.api(model.getProId(), model.getDevName()))
+ .method(Method.GET)
+ .signMethod(SignMethod.MD5)
+ .userid(config.getUserid())
+ .build()
+ .send(config.getAccessKey());
+ }
+
+ /**
+ * 上报设备版本号
+ *
+ * @param config {@link Config}
+ * @param model {@link FuseOtaModel}
+ * @return {@link ApiResponse}
+ */
+ public static ApiResponse otaVersionUp(Config config, FuseOtaModel model) {
+ return ApiRequest.builder()
+ .api(ApiEnum.OTA_VERSION.api(model.getProId(), model.getDevName()))
+ .method(Method.POST)
+ .signMethod(SignMethod.MD5)
+ .userid(config.getUserid())
+ .build()
+ .send(config.getAccessKey());
+ }
+
+}
diff --git a/src/main/java/net/javase/onenet/model/FuseLbsModel.java b/src/main/java/net/javase/onenet/model/FuseLbsModel.java
new file mode 100644
index 0000000..1d4f4b4
--- /dev/null
+++ b/src/main/java/net/javase/onenet/model/FuseLbsModel.java
@@ -0,0 +1,83 @@
+package net.javase.onenet.model;
+
+import lombok.Builder;
+import lombok.Getter;
+import lombok.Setter;
+import net.javase.onenet.annotation.ApiParam;
+import net.javase.onenet.model.base.BaseModel;
+
+/**
+ * FuseLbsModel
+ *
+ * @author Frank
+ */
+@Getter
+@Setter
+@Builder
+public class FuseLbsModel extends BaseModel {
+
+ /**
+ * 产品名称
+ */
+ @ApiParam(name = "product_id")
+ private String productId;
+
+ /**
+ * 设备名称
+ */
+ @ApiParam(name = "device_name")
+ private String deviceName;
+
+ /**
+ * NB设备的imei号
+ */
+ private String imei;
+
+ /**
+ * 表示查询轨迹的开始时间,默认起始时间为本周一零点,可选,精确到毫秒级别
+ */
+ private String start;
+
+ /**
+ * 表示查询轨迹的结束时间,默认结束时间为当前时间,可选,精确到毫秒级别
+ */
+ private String end;
+
+ /**
+ * 指定页码,可选
+ */
+ private String page;
+
+ /**
+ * 指定每页输出设备个数,可选,默认10,可选
+ */
+ private String per_page;
+
+ /**
+ * 最大经度,可选
+ */
+ private String max_lon;
+
+ /**
+ * 最小经度,可选
+ */
+ private String min_lon;
+
+ /**
+ * 最大纬度,可选
+ */
+ private String max_lat;
+
+ /**
+ * 最小纬度,可选
+ */
+ private String min_lat;
+
+ /**
+ * 可选,默认为ASC(升序)
+ */
+ private String sort;
+
+
+
+}
diff --git a/src/main/java/net/javase/onenet/model/FuseOtaModel.java b/src/main/java/net/javase/onenet/model/FuseOtaModel.java
new file mode 100644
index 0000000..bfd02ac
--- /dev/null
+++ b/src/main/java/net/javase/onenet/model/FuseOtaModel.java
@@ -0,0 +1,69 @@
+package net.javase.onenet.model;
+
+import lombok.Builder;
+import lombok.Getter;
+import lombok.Setter;
+import net.javase.onenet.annotation.ApiParam;
+import net.javase.onenet.model.base.BaseModel;
+
+/**
+ * FuseOtaModel
+ *
+ * @author Frank
+ */
+@Getter
+@Setter
+@Builder
+public class FuseOtaModel extends BaseModel {
+
+ /**
+ * 产品id
+ */
+ @ApiParam(ignore = true)
+ private String proId;
+
+ /**
+ * 设备名称
+ */
+ @ApiParam(ignore = true)
+ private String devName;
+
+ /**
+ * tid
+ */
+ @ApiParam(ignore = true)
+ private String tid;
+
+ /**
+ * 1:fota任务,2:sota任务
+ */
+ private Integer type;
+
+ /**
+ * 设备当前版本
+ */
+ private String version;
+
+ /**
+ * 分片下载字段
+ */
+ private Integer range;
+
+ /**
+ * 状态码
+ */
+ private Integer step;
+
+ /**
+ * 模组版本号
+ */
+ @ApiParam(name = "f_version")
+ private String fVersion;
+
+ /**
+ * 应用服务版本号
+ */
+ @ApiParam(name = "s_version")
+ private String sVersion;
+
+}
diff --git a/src/main/java/net/javase/onenet/model/RegistDeviceIdentityModel.java b/src/main/java/net/javase/onenet/model/RegistDeviceIdentityModel.java
new file mode 100644
index 0000000..acb5b27
--- /dev/null
+++ b/src/main/java/net/javase/onenet/model/RegistDeviceIdentityModel.java
@@ -0,0 +1,39 @@
+package net.javase.onenet.model;
+
+import lombok.Builder;
+import lombok.Getter;
+import lombok.Setter;
+import net.javase.onenet.annotation.ApiParam;
+import net.javase.onenet.model.base.BaseModel;
+
+import java.util.List;
+
+/**
+ * RegistDeviceIdentityModel
+ *
+ * @author Frank
+ */
+@Getter
+@Setter
+@Builder
+public class RegistDeviceIdentityModel extends BaseModel {
+
+ /**
+ * 产品名称
+ */
+ @ApiParam(name = "product_id")
+ private String productId;
+
+ /**
+ * 设备信息集合, 一次最多创建1000个设备。
+ * 每个集合元素是设备名称,例如["device01", "device02"],每个元素的设备名称只能是1-32位英文、数字、特殊字符 -_
+ */
+ private List devices;
+
+ /**
+ * 是否开启自动更新,0:关闭,1:开启
+ */
+ @ApiParam(name = "auto_mode")
+ private String autoMode;
+
+}
diff --git a/src/main/java/net/javase/onenet/model/VoiceNotifyModel.java b/src/main/java/net/javase/onenet/model/VoiceNotifyModel.java
new file mode 100644
index 0000000..13b0c3f
--- /dev/null
+++ b/src/main/java/net/javase/onenet/model/VoiceNotifyModel.java
@@ -0,0 +1,107 @@
+package net.javase.onenet.model;
+
+import lombok.Builder;
+import lombok.Getter;
+import lombok.Setter;
+import net.javase.onenet.annotation.ApiParam;
+import net.javase.onenet.model.base.BaseModel;
+
+import java.util.List;
+
+/**
+ * VoiceNotifyModel
+ *
+ * @author Frank
+ */
+@Getter
+@Setter
+@Builder
+public class VoiceNotifyModel extends BaseModel {
+
+ /**
+ * 外呼被叫号码MSISDN
+ * 举例8618625150488
+ */
+ @ApiParam(name = "participant_address")
+ private String participantAddress;
+
+ /**
+ * 号显号码(业务号码)
+ * 由OneNET平台提供
+ */
+ private String display;
+
+ /**
+ * 呼叫操作指示,参考CallActionType定义
+ * 仅支持Play和PlayAndCollect
+ */
+ private List actions;
+
+ /**
+ * 用户指定的通知地址(请求方式为POST)
+ * 如无此字段,则根据OneNET平台配置为准
+ */
+ @ApiParam(name = "notify_url")
+ private String notifyUrl;
+
+
+ /**
+ * CallActionType 呼叫操作类型
+ *
+ * @author Frank
+ */
+ @Getter
+ @Setter
+ @Builder
+ public static class CallActionType {
+ /**
+ * 操作类型
+ * Play:放音
+ * PlayAndCollect:放音及收号
+ */
+ private String operation;
+
+ /**
+ * tts模板编号
+ * 用户向OneNET提交的通知模板,需审核通过后才能使用
+ */
+ private String tts_template;
+
+ /**
+ * 模板中需要填充的参数参数内容为UTF-8编码,JSON Object的格式为{"var1":"aa","var2":"aa"},其中var1,var2为模板变量名称,var的个数可变
+ */
+ private String param_value;
+
+ /**
+ * 收号长度当operation=PlayAndCollect时有效,如果replayAfterCollection=false或未配置,系统会将用户输入的号码通过呼叫状态通知API发送给第三方;如果replayAfterCollection=true,则不会将收号结果上报给第三方
+ * 取值范围
+ * 1~32:收号,取值表示收号位长,最大支持32位
+ */
+ private String collect_length;
+
+ /**
+ * 重新播放标识
+ * 当operation=PlayAndCollect时有效,此字段用于设置是否在收号后重新播放指定的放音
+ * true:播放
+ * false:不播放
+ * 默认值:false
+ */
+ private String replay_after_collection;
+
+ /**
+ * 当replayAfterCollection=true时此参数有效
+ * 此字段用于设置触发重新放音的收号内容,只有实际收号内容与该参数值一致时,才重新放音
+ * 例如:该参数设置为1,当用户根据收号语音提示按1,两者一致,则重复放音默认值为1
+ */
+ private String collect_content_trigger_replaying;
+
+ /**
+ * 重复放音次数
+ * 当操作类型为Play时,此字段有效
+ * 默认为1次
+ */
+ private String relay_time;
+
+ }
+}
+
diff --git a/src/main/java/net/javase/onenet/utils/RequestUtil.java b/src/main/java/net/javase/onenet/utils/RequestUtil.java
index b701b54..4e7359d 100644
--- a/src/main/java/net/javase/onenet/utils/RequestUtil.java
+++ b/src/main/java/net/javase/onenet/utils/RequestUtil.java
@@ -9,6 +9,7 @@ import net.javase.onenet.api.ApiRequest;
import net.javase.onenet.api.ApiResponse;
import net.javase.onenet.exception.ApiException;
+import java.io.File;
import java.nio.charset.StandardCharsets;
/**
@@ -78,4 +79,47 @@ public class RequestUtil {
throw new ApiException("请求异常", ex);
}
}
+
+ /**
+ * 文件下载
+ *
+ * @param req {@link ApiRequest}
+ * @param accessKey accessKey
+ * @param target {@link File}
+ */
+ public static void download(ApiRequest req, String accessKey, File target) {
+ Method method = req.getMethod();
+ String url = req.getDomain().getDomain() + req.url();
+ if (req.getQuery() != null && req.getQuery().size() > 0) {
+ String query = URLUtil.buildQuery(req.getQuery(), StandardCharsets.UTF_8);
+ url += "?" + query;
+ }
+ HttpRequest request = HttpRequest.of(url).method(method);
+ if (req.getContentType() != null) {
+ request.contentType(req.getContentType().toString());
+ }
+ if (req.getBody() != null && req.getBody().size() > 0) {
+ request.body(JSONObject.toJSONString(req.getBody()));
+ }
+
+ String expirationTime = String.valueOf((System.currentTimeMillis() / 1000) + 600);
+ String token = SignUtil.assembleToken(req.getVersion(),
+ req.getRes(), expirationTime, req.getSignMethod(), accessKey);
+ request.header("authorization", token);
+ download(request, target);
+ }
+
+ /**
+ * 文件下载
+ *
+ * @param request {@link HttpRequest}
+ * @param target {@link File}
+ */
+ public static void download(HttpRequest request, File target) {
+ try (HttpResponse response = request.execute()) {
+ response.writeBody(target);
+ } catch (Exception ex) {
+ throw new ApiException("文件下载异常", ex);
+ }
+ }
}