mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-22 23:23:55 +08:00
update:ota接口验证通过 (#675)
This commit is contained in:
+1
-1
@@ -18,4 +18,4 @@ xiaozhi-esp32-server
|
||||
|
||||
# manager-web 、manager-api接口协议
|
||||
|
||||
https://2662r3426b.vicp.fun/xiaozhi-esp32-api/api/v1/doc.html
|
||||
https://2662r3426b.vicp.fun/xiaozhi/v1/doc.html
|
||||
|
||||
@@ -92,5 +92,5 @@ nohup java -jar xiaozhi-esp32-api.jar --spring.profiles.activate=dev
|
||||
|
||||
|
||||
# 接口文档
|
||||
启动后打开:http://localhost:8002/xiaozhi-esp32-api/doc.html
|
||||
启动后打开:http://localhost:8002/xiaozhi/doc.html
|
||||
|
||||
|
||||
@@ -8,6 +8,6 @@ public class AdminApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(AdminApplication.class, args);
|
||||
System.out.println("http://localhost:8002/xiaozhi-esp32-api/api/v1/doc.html");
|
||||
System.out.println("http://localhost:8002/xiaozhi/doc.html");
|
||||
}
|
||||
}
|
||||
+1
-8
@@ -19,7 +19,6 @@ import xiaozhi.common.redis.RedisKeys;
|
||||
import xiaozhi.common.redis.RedisUtils;
|
||||
import xiaozhi.common.user.UserDetail;
|
||||
import xiaozhi.common.utils.Result;
|
||||
import xiaozhi.modules.device.dto.DeviceBindDTO;
|
||||
import xiaozhi.modules.device.dto.DeviceRegisterDTO;
|
||||
import xiaozhi.modules.device.dto.DeviceUnBindDTO;
|
||||
import xiaozhi.modules.device.entity.DeviceEntity;
|
||||
@@ -39,13 +38,7 @@ public class DeviceController {
|
||||
@Operation(summary = "绑定设备")
|
||||
@RequiresPermissions("sys:role:normal")
|
||||
public Result<Void> bindDevice(@PathVariable String agentId, @PathVariable String deviceCode) {
|
||||
String macAddress = (String) redisUtils.get(RedisKeys.getDeviceCaptchaKey(deviceCode));
|
||||
if (StringUtils.isBlank(macAddress)) {
|
||||
return new Result<Void>().error(ErrorCode.DEVICE_CAPTCHA_ERROR);
|
||||
}
|
||||
Long user = SecurityUser.getUser().getId();
|
||||
DeviceBindDTO deviceBindDTO = new DeviceBindDTO(macAddress, user, agentId);
|
||||
deviceService.bindDevice(deviceBindDTO);
|
||||
deviceService.deviceActivation(agentId, deviceCode);
|
||||
return new Result<>();
|
||||
}
|
||||
|
||||
|
||||
+1
-10
@@ -5,12 +5,10 @@ import java.nio.charset.StandardCharsets;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
@@ -22,7 +20,6 @@ import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
import xiaozhi.common.utils.Result;
|
||||
import xiaozhi.modules.device.dto.DeviceReportReqDTO;
|
||||
import xiaozhi.modules.device.dto.DeviceReportRespDTO;
|
||||
import xiaozhi.modules.device.service.DeviceService;
|
||||
@@ -31,7 +28,7 @@ import xiaozhi.modules.device.utils.NetworkUtil;
|
||||
@Tag(name = "设备管理", description = "OTA 相关接口")
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/ota")
|
||||
@RequestMapping("/ota/")
|
||||
public class OTAController {
|
||||
private final DeviceService deviceService;
|
||||
|
||||
@@ -55,12 +52,6 @@ public class OTAController {
|
||||
return createResponse(deviceService.checkDeviceActive(macAddress, deviceId, clientId, deviceReportReqDTO));
|
||||
}
|
||||
|
||||
@Operation(summary = "设备激活")
|
||||
@GetMapping("/activation")
|
||||
public Result<Boolean> deviceActivation(@RequestParam String code) {
|
||||
return new Result<Boolean>().ok(deviceService.deviceActivation(code));
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
private ResponseEntity<String> createResponse(DeviceReportRespDTO deviceReportRespDTO) {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
@@ -9,7 +9,7 @@ import lombok.Setter;
|
||||
@Schema(description = "设备OTA检测版本返回体,包含激活码要求")
|
||||
public class DeviceReportRespDTO {
|
||||
@Schema(description = "服务器时间")
|
||||
private ServerTime serverTime;
|
||||
private ServerTime server_time;
|
||||
|
||||
@Schema(description = "激活码")
|
||||
private Activation activation;
|
||||
@@ -56,6 +56,6 @@ public class DeviceReportRespDTO {
|
||||
private String timeZone;
|
||||
|
||||
@Schema(description = "时区偏移量,单位为分钟")
|
||||
private Integer timezoneOffset;
|
||||
private Integer timezone_offset;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package xiaozhi.modules.device.service;
|
||||
import java.util.List;
|
||||
|
||||
import xiaozhi.common.page.PageData;
|
||||
import xiaozhi.modules.device.dto.DeviceBindDTO;
|
||||
import xiaozhi.modules.device.dto.DevicePageUserDTO;
|
||||
import xiaozhi.modules.device.dto.DeviceReportReqDTO;
|
||||
import xiaozhi.modules.device.dto.DeviceReportRespDTO;
|
||||
@@ -23,11 +22,6 @@ public interface DeviceService {
|
||||
DeviceReportRespDTO checkDeviceActive(String macAddress, String deviceId, String clientId,
|
||||
DeviceReportReqDTO deviceReport);
|
||||
|
||||
/**
|
||||
* 绑定设备
|
||||
*/
|
||||
DeviceEntity bindDevice(DeviceBindDTO deviceHeader);
|
||||
|
||||
/**
|
||||
* 获取用户指定智能体的设备列表,
|
||||
*/
|
||||
@@ -41,7 +35,7 @@ public interface DeviceService {
|
||||
/**
|
||||
* 设备激活
|
||||
*/
|
||||
Boolean deviceActivation(String activationCode);
|
||||
Boolean deviceActivation(String agentId, String activationCode);
|
||||
|
||||
/**
|
||||
* 删除此用户的所有设备
|
||||
|
||||
+5
-18
@@ -27,7 +27,6 @@ import xiaozhi.common.user.UserDetail;
|
||||
import xiaozhi.common.utils.ConvertUtils;
|
||||
import xiaozhi.common.utils.DateUtils;
|
||||
import xiaozhi.modules.device.dao.DeviceDao;
|
||||
import xiaozhi.modules.device.dto.DeviceBindDTO;
|
||||
import xiaozhi.modules.device.dto.DevicePageUserDTO;
|
||||
import xiaozhi.modules.device.dto.DeviceReportReqDTO;
|
||||
import xiaozhi.modules.device.dto.DeviceReportRespDTO;
|
||||
@@ -66,7 +65,7 @@ public class DeviceServiceImpl extends BaseServiceImpl<DeviceDao, DeviceEntity>
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean deviceActivation(String activationCode) {
|
||||
public Boolean deviceActivation(String agentId, String activationCode) {
|
||||
if (StringUtils.isBlank(activationCode)) {
|
||||
throw new RenException("激活码不能为空");
|
||||
}
|
||||
@@ -103,6 +102,7 @@ public class DeviceServiceImpl extends BaseServiceImpl<DeviceDao, DeviceEntity>
|
||||
DeviceEntity deviceEntity = new DeviceEntity();
|
||||
deviceEntity.setId(deviceId);
|
||||
deviceEntity.setBoard(board);
|
||||
deviceEntity.setAgentId(agentId);
|
||||
deviceEntity.setAppVersion(appVersion);
|
||||
deviceEntity.setMacAddress(macAddress);
|
||||
deviceEntity.setUserId(user.getId());
|
||||
@@ -123,13 +123,13 @@ public class DeviceServiceImpl extends BaseServiceImpl<DeviceDao, DeviceEntity>
|
||||
public DeviceReportRespDTO checkDeviceActive(String macAddress, String deviceId, String clientId,
|
||||
DeviceReportReqDTO deviceReport) {
|
||||
DeviceReportRespDTO response = new DeviceReportRespDTO();
|
||||
response.setServerTime(buildServerTime());
|
||||
response.setServer_time(buildServerTime());
|
||||
// todo: 此处是固件信息,目前是针对固件上传上来的版本号再返回回去
|
||||
// 在未来开发了固件更新功能,需要更换此处代码,
|
||||
// 或写定时任务定期请求虾哥的OTA,获取最新的版本讯息保存到服务内
|
||||
DeviceReportRespDTO.Firmware firmware = new DeviceReportRespDTO.Firmware();
|
||||
firmware.setVersion(deviceReport.getApplication().getVersion());
|
||||
firmware.setUrl("http://localhost:8002/xiaozhi-esp32-api/api/v1/ota/download");
|
||||
firmware.setUrl("http://localhost:8002/xiaozhi/ota/download");
|
||||
response.setFirmware(firmware);
|
||||
|
||||
DeviceEntity deviceById = getDeviceById(deviceId);
|
||||
@@ -178,19 +178,6 @@ public class DeviceServiceImpl extends BaseServiceImpl<DeviceDao, DeviceEntity>
|
||||
return response;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeviceEntity bindDevice(DeviceBindDTO dto) {
|
||||
// 查看是否已经被绑定
|
||||
DeviceEntity deviceEntity = baseDao
|
||||
.selectOne(new LambdaQueryWrapper<DeviceEntity>().eq(DeviceEntity::getMacAddress, dto.getMacAddress()));
|
||||
if (deviceEntity != null) {
|
||||
throw new RenException("设备已绑定");
|
||||
}
|
||||
deviceEntity = ConvertUtils.sourceToTarget(dto, DeviceEntity.class);
|
||||
baseDao.insert(deviceEntity);
|
||||
return deviceEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DeviceEntity> getUserDevices(Long userId, String agentId) {
|
||||
QueryWrapper<DeviceEntity> wrapper = new QueryWrapper<>();
|
||||
@@ -251,7 +238,7 @@ public class DeviceServiceImpl extends BaseServiceImpl<DeviceDao, DeviceEntity>
|
||||
TimeZone tz = TimeZone.getDefault();
|
||||
serverTime.setTimestamp(Instant.now().toEpochMilli());
|
||||
serverTime.setTimeZone(tz.getID());
|
||||
serverTime.setTimezoneOffset(tz.getOffset(System.currentTimeMillis()) / (60 * 1000));
|
||||
serverTime.setTimezone_offset(tz.getOffset(System.currentTimeMillis()) / (60 * 1000));
|
||||
return serverTime;
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ server:
|
||||
min-spare: 30
|
||||
port: 8002
|
||||
servlet:
|
||||
context-path: /xiaozhi-esp32-api/api/v1
|
||||
context-path: /xiaozhi
|
||||
session:
|
||||
cookie:
|
||||
http-only: true
|
||||
@@ -26,6 +26,8 @@ spring:
|
||||
enabled: true
|
||||
main:
|
||||
allow-bean-definition-overriding: true
|
||||
liquibase:
|
||||
enabled: false
|
||||
|
||||
knife4j:
|
||||
enable: true
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# 暂时使用群主的接口
|
||||
VUE_APP_API_BASE_URL=https://2662r3426b.vicp.fun/xiaozhi-esp32-api
|
||||
# VUE_APP_API_BASE_URL=https://2662r3426b.vicp.fun/xiaozhi
|
||||
# 如果本地开发,请使用以下接口
|
||||
# VUE_APP_API_BASE_URL=http://localhost:8002/xiaozhi-esp32-api
|
||||
VUE_APP_API_BASE_URL=http://localhost:8002/xiaozhi
|
||||
@@ -1 +1 @@
|
||||
VUE_APP_API_BASE_URL=/xiaozhi-esp32-api
|
||||
VUE_APP_API_BASE_URL=/xiaozhi
|
||||
@@ -12,7 +12,7 @@ export default {
|
||||
}).toString();
|
||||
|
||||
RequestService.sendRequest()
|
||||
.url(`${getServiceUrl()}/api/v1/admin/users?${queryParams}`)
|
||||
.url(`${getServiceUrl()}/admin/users?${queryParams}`)
|
||||
.method('GET')
|
||||
.success((res) => {
|
||||
RequestService.clearRequestTime()
|
||||
@@ -28,7 +28,7 @@ export default {
|
||||
// 删除用户
|
||||
deleteUser(id, callback) {
|
||||
RequestService.sendRequest()
|
||||
.url(`${getServiceUrl()}/api/v1/admin/users/${id}`)
|
||||
.url(`${getServiceUrl()}/admin/users/${id}`)
|
||||
.method('DELETE')
|
||||
.success((res) => {
|
||||
RequestService.clearRequestTime()
|
||||
@@ -44,7 +44,7 @@ export default {
|
||||
// 重置用户密码
|
||||
resetUserPassword(id, callback) {
|
||||
RequestService.sendRequest()
|
||||
.url(`${getServiceUrl()}/api/v1/admin/users/${id}`)
|
||||
.url(`${getServiceUrl()}/admin/users/${id}`)
|
||||
.method('PUT')
|
||||
.success((res) => {
|
||||
RequestService.clearRequestTime()
|
||||
|
||||
@@ -6,7 +6,7 @@ export default {
|
||||
// 获取智能体列表
|
||||
getAgentList(callback) {
|
||||
RequestService.sendRequest()
|
||||
.url(`${getServiceUrl()}/api/v1/agent/list`)
|
||||
.url(`${getServiceUrl()}/agent/list`)
|
||||
.method('GET')
|
||||
.success((res) => {
|
||||
RequestService.clearRequestTime();
|
||||
@@ -21,7 +21,7 @@ export default {
|
||||
// 添加智能体
|
||||
addAgent(agentName, callback) {
|
||||
RequestService.sendRequest()
|
||||
.url(`${getServiceUrl()}/api/v1/agent`)
|
||||
.url(`${getServiceUrl()}/agent`)
|
||||
.method('POST')
|
||||
.data({ agentName: agentName })
|
||||
.success((res) => {
|
||||
@@ -37,7 +37,7 @@ export default {
|
||||
// 删除智能体
|
||||
deleteAgent(agentId, callback) {
|
||||
RequestService.sendRequest()
|
||||
.url(`${getServiceUrl()}/api/v1/agent/${agentId}`)
|
||||
.url(`${getServiceUrl()}/agent/${agentId}`)
|
||||
.method('DELETE')
|
||||
.success((res) => {
|
||||
RequestService.clearRequestTime();
|
||||
@@ -52,7 +52,7 @@ export default {
|
||||
// 获取智能体配置
|
||||
getDeviceConfig(deviceId, callback) {
|
||||
RequestService.sendRequest()
|
||||
.url(`${getServiceUrl()}/api/v1/agent/${deviceId}`)
|
||||
.url(`${getServiceUrl()}/agent/${deviceId}`)
|
||||
.method('GET')
|
||||
.success((res) => {
|
||||
RequestService.clearRequestTime();
|
||||
@@ -68,7 +68,7 @@ export default {
|
||||
// 配置智能体
|
||||
updateAgentConfig(agentId, configData, callback) {
|
||||
RequestService.sendRequest()
|
||||
.url(`${getServiceUrl()}/api/v1/agent/${agentId}`)
|
||||
.url(`${getServiceUrl()}/agent/${agentId}`)
|
||||
.method('PUT')
|
||||
.data(configData)
|
||||
.success((res) => {
|
||||
@@ -84,7 +84,7 @@ export default {
|
||||
// 新增方法:获取智能体模板
|
||||
getAgentTemplate(callback) { // 移除templateName参数
|
||||
RequestService.sendRequest()
|
||||
.url(`${getServiceUrl()}/api/v1/agent/template`)
|
||||
.url(`${getServiceUrl()}/agent/template`)
|
||||
.method('GET')
|
||||
.success((res) => {
|
||||
RequestService.clearRequestTime();
|
||||
|
||||
@@ -5,7 +5,7 @@ export default {
|
||||
// 已绑设备
|
||||
getAgentBindDevices(agentId, callback) {
|
||||
RequestService.sendRequest()
|
||||
.url(`${getServiceUrl()}/api/v1/device/bind/${agentId}`)
|
||||
.url(`${getServiceUrl()}/device/bind/${agentId}`)
|
||||
.method('GET')
|
||||
.success((res) => {
|
||||
RequestService.clearRequestTime();
|
||||
@@ -21,7 +21,7 @@ export default {
|
||||
// 解绑设备
|
||||
unbindDevice(device_id, callback) {
|
||||
RequestService.sendRequest()
|
||||
.url(`${getServiceUrl()}/api/v1/device/unbind`)
|
||||
.url(`${getServiceUrl()}/device/unbind`)
|
||||
.method('POST')
|
||||
.data({ deviceId: device_id })
|
||||
.success((res) => {
|
||||
@@ -38,7 +38,7 @@ export default {
|
||||
// 绑定设备
|
||||
bindDevice(agentId, deviceCode, callback) {
|
||||
RequestService.sendRequest()
|
||||
.url(`${getServiceUrl()}/api/v1/device/bind/${agentId}/${deviceCode}`)
|
||||
.url(`${getServiceUrl()}/device/bind/${agentId}/${deviceCode}`)
|
||||
.method('POST')
|
||||
.success((res) => {
|
||||
RequestService.clearRequestTime();
|
||||
|
||||
@@ -13,7 +13,7 @@ export default {
|
||||
}).toString();
|
||||
|
||||
RequestService.sendRequest()
|
||||
.url(`${getServiceUrl()}/api/v1/models/models/list?${queryParams}`)
|
||||
.url(`${getServiceUrl()}/models/models/list?${queryParams}`)
|
||||
.method('GET')
|
||||
.success((res) => {
|
||||
RequestService.clearRequestTime()
|
||||
@@ -29,7 +29,7 @@ export default {
|
||||
// 获取模型供应器列表
|
||||
getModelProviders(modelType, callback) {
|
||||
RequestService.sendRequest()
|
||||
.url(`${getServiceUrl()}/api/v1/models/${modelType}/provideTypes`)
|
||||
.url(`${getServiceUrl()}/models/${modelType}/provideTypes`)
|
||||
.method('GET')
|
||||
.success((res) => {
|
||||
RequestService.clearRequestTime()
|
||||
@@ -59,7 +59,7 @@ export default {
|
||||
};
|
||||
|
||||
RequestService.sendRequest()
|
||||
.url(`${getServiceUrl()}/api/v1/models/models/${modelType}/${provideCode}`)
|
||||
.url(`${getServiceUrl()}/models/models/${modelType}/${provideCode}`)
|
||||
.method('POST')
|
||||
.data(postData)
|
||||
.success((res) => {
|
||||
@@ -77,7 +77,7 @@ export default {
|
||||
// 删除模型配置
|
||||
deleteModel(id, callback) {
|
||||
RequestService.sendRequest()
|
||||
.url(`${getServiceUrl()}/api/v1/models/models/${id}`)
|
||||
.url(`${getServiceUrl()}/models/models/${id}`)
|
||||
.method('DELETE')
|
||||
.success((res) => {
|
||||
RequestService.clearRequestTime()
|
||||
|
||||
@@ -6,7 +6,7 @@ export default {
|
||||
// 登录
|
||||
login(loginForm, callback) {
|
||||
RequestService.sendRequest()
|
||||
.url(`${getServiceUrl()}/api/v1/user/login`)
|
||||
.url(`${getServiceUrl()}/user/login`)
|
||||
.method('POST')
|
||||
.data(loginForm)
|
||||
.success((res) => {
|
||||
@@ -22,7 +22,7 @@ export default {
|
||||
// 获取验证码
|
||||
getCaptcha(uuid, callback) {
|
||||
RequestService.sendRequest()
|
||||
.url(`${getServiceUrl()}/api/v1/user/captcha?uuid=${uuid}`)
|
||||
.url(`${getServiceUrl()}/user/captcha?uuid=${uuid}`)
|
||||
.method('GET')
|
||||
.type('blob')
|
||||
.header({
|
||||
@@ -41,7 +41,7 @@ export default {
|
||||
// 注册账号
|
||||
register(registerForm, callback) {
|
||||
RequestService.sendRequest()
|
||||
.url(`${getServiceUrl()}/api/v1/user/register`)
|
||||
.url(`${getServiceUrl()}/user/register`)
|
||||
.method('POST')
|
||||
.data(registerForm)
|
||||
.success((res) => {
|
||||
@@ -54,7 +54,7 @@ export default {
|
||||
// 保存设备配置
|
||||
saveDeviceConfig(device_id, configData, callback) {
|
||||
RequestService.sendRequest()
|
||||
.url(`${getServiceUrl()}/api/v1/user/configDevice/${device_id}`)
|
||||
.url(`${getServiceUrl()}/user/configDevice/${device_id}`)
|
||||
.method('PUT')
|
||||
.data(configData)
|
||||
.success((res) => {
|
||||
@@ -71,7 +71,7 @@ export default {
|
||||
// 用户信息获取
|
||||
getUserInfo(callback) {
|
||||
RequestService.sendRequest()
|
||||
.url(`${getServiceUrl()}/api/v1/user/info`)
|
||||
.url(`${getServiceUrl()}/user/info`)
|
||||
.method('GET')
|
||||
.success((res) => {
|
||||
RequestService.clearRequestTime()
|
||||
@@ -87,7 +87,7 @@ export default {
|
||||
// 修改用户密码
|
||||
changePassword(oldPassword, newPassword, successCallback, errorCallback) {
|
||||
RequestService.sendRequest()
|
||||
.url(`${getServiceUrl()}/api/v1/user/change-password`)
|
||||
.url(`${getServiceUrl()}/user/change-password`)
|
||||
.method('PUT')
|
||||
.data({
|
||||
password: oldPassword,
|
||||
|
||||
Reference in New Issue
Block a user