From 7199921255a84bcac7d9fbecdf03299dcee9660f Mon Sep 17 00:00:00 2001 From: tongtongstudio Date: Sun, 31 Aug 2025 13:16:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=98=AF=E5=90=A6=E6=9C=89?= =?UTF-8?q?=E5=AF=86=E7=A0=81=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/DevicesController.java | 38 ++++++++++++++++++- .../controller/UserController.java | 2 + .../videotablet/service/UserService.java | 3 -- .../onekeycall/videotablet/utils/JwtUtil.java | 5 ++- 4 files changed, 43 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/onekeycall/videotablet/controller/DevicesController.java b/src/main/java/com/onekeycall/videotablet/controller/DevicesController.java index 48bb4b5..5db5b3e 100644 --- a/src/main/java/com/onekeycall/videotablet/controller/DevicesController.java +++ b/src/main/java/com/onekeycall/videotablet/controller/DevicesController.java @@ -67,7 +67,7 @@ public class DevicesController { } @PostMapping("/update_location") - public Result getBindStatus( + public Result updateLocation( @RequestHeader("Device-Token") String deviceToken, @RequestHeader("Device-ID") String deviceId, @RequestHeader("Device-Sig") String deviceSig, @Valid @RequestBody DeviceLocation deviceLocation @@ -133,4 +133,40 @@ public class DevicesController { return Result.ok().data("contacts", contacts); } + @PostMapping("/upload_install_apk") + public Result uploadInstallApk( + @RequestHeader("Device-Token") String deviceToken, @RequestHeader("Device-ID") String deviceId, + @RequestHeader("Device-Sig") String deviceSig, + @Valid @RequestBody DeviceLocation deviceLocation + ) { + String sn = deviceLocation.getSn(); + + if (!jwtUtil.validateDeviceToken(deviceToken, deviceId, sn)) { + return Result.error().message("Invalid token"); + } + + DeviceInfo deviceInfo = deviceSnService.findBySn(sn); + if (deviceInfo == null) { + return Result.notFound().message("sn not found"); + } + + if (!deviceInfo.getBindSig().equals(deviceSig)) { + return Result.error().message("device sig not match"); + } + + if (TextUtils.isEmpty(deviceInfo.getBindPhone())) { + return Result.error().message("sn not bind"); + } + if (deviceLocationService.isExist(sn)) { + DeviceLocation deviceLocationDB = deviceLocationService.getDeviceLocation(sn); + deviceLocation.setId(deviceLocationDB.getId()); + deviceLocation.setUpdateTime(new Date(System.currentTimeMillis())); + deviceLocationService.save(deviceLocation); + } else { + deviceLocation.setUpdateTime(new Date(System.currentTimeMillis())); + deviceLocation.setCreateTime(new Date(System.currentTimeMillis())); + deviceLocationService.save(deviceLocation); + } + return Result.ok(); + } } diff --git a/src/main/java/com/onekeycall/videotablet/controller/UserController.java b/src/main/java/com/onekeycall/videotablet/controller/UserController.java index 76e0dac..ca6b63c 100644 --- a/src/main/java/com/onekeycall/videotablet/controller/UserController.java +++ b/src/main/java/com/onekeycall/videotablet/controller/UserController.java @@ -10,6 +10,7 @@ import com.onekeycall.videotablet.service.DeviceLocationService; import com.onekeycall.videotablet.service.DeviceSnService; import com.onekeycall.videotablet.service.UserService; import com.onekeycall.videotablet.utils.JwtUtil; +import com.onekeycall.videotablet.utils.TextUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -96,6 +97,7 @@ public class UserController { userInfo.put("phone", user.getPhone()); userInfo.put("nickname", user.getNickname()); userInfo.put("avatar", user.getAvatar()); + userInfo.put("set_password", !TextUtils.isEmpty(user.getPassword())); return Result.ok().data("user_info", userInfo); } diff --git a/src/main/java/com/onekeycall/videotablet/service/UserService.java b/src/main/java/com/onekeycall/videotablet/service/UserService.java index 3036c12..1c48ba0 100644 --- a/src/main/java/com/onekeycall/videotablet/service/UserService.java +++ b/src/main/java/com/onekeycall/videotablet/service/UserService.java @@ -127,9 +127,6 @@ public class UserService implements UserDetailsService { // } public boolean saveUser(User user) { - if (userRepository.existsByUserId(user.getUserId())) { - return false; - } userRepository.save(user); return true; } diff --git a/src/main/java/com/onekeycall/videotablet/utils/JwtUtil.java b/src/main/java/com/onekeycall/videotablet/utils/JwtUtil.java index ddbb55b..a82644d 100644 --- a/src/main/java/com/onekeycall/videotablet/utils/JwtUtil.java +++ b/src/main/java/com/onekeycall/videotablet/utils/JwtUtil.java @@ -86,7 +86,10 @@ public class JwtUtil { .build() .parseSignedClaims(token) .getPayload(); - } catch (JwtException | IllegalArgumentException e) { + } catch (JwtException e) { + logger.error("parseToken Token已过期: {}", e.getMessage()); + throw new InvalidTokenException("Token解析失败: " + e.getMessage()); + } catch (IllegalArgumentException e) { logger.error("parseToken Token解析失败: {}", e.getMessage()); throw new InvalidTokenException("Token解析失败: " + e.getMessage()); }