diff --git a/src/main/java/com/onekeycall/videotablet/config/PushIdConfig.java b/src/main/java/com/onekeycall/videotablet/config/PushIdConfig.java index e5d87a3..c6ef19e 100644 --- a/src/main/java/com/onekeycall/videotablet/config/PushIdConfig.java +++ b/src/main/java/com/onekeycall/videotablet/config/PushIdConfig.java @@ -12,4 +12,10 @@ public class PushIdConfig { public static final String CLEAR_APP = "12"; /*卸载应用*/ public static final String UNINSTALL_APP = "13"; + + public static final String CONTACT_CALL = "14"; + public static final String CONTACT_AUDIO = "15"; + public static final String CONTACT_VIDEO = "16"; + public static final String CONTACT_DELETE = "17"; + } diff --git a/src/main/java/com/onekeycall/videotablet/controller/pub/ManageSnController.java b/src/main/java/com/onekeycall/videotablet/controller/pub/ManageSnController.java index 91d1320..de55955 100644 --- a/src/main/java/com/onekeycall/videotablet/controller/pub/ManageSnController.java +++ b/src/main/java/com/onekeycall/videotablet/controller/pub/ManageSnController.java @@ -21,6 +21,7 @@ import java.io.File; import java.io.IOException; import java.util.Date; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.Map; @RestController @@ -104,4 +105,67 @@ public class ManageSnController { return Result.ok().data(map); } + + /** + * 获取平板sn绑定状态 + * 标准的通过平板获取接口,需要 Device-Token Device-ID Device-Sig + * + * @param deviceToken + * @param deviceId + * @param deviceSig + * @param sn + * @return + */ + // TODO: 2025/8/22 Device_Token在docker无法被接收到,使用Device-Token代替 + @GetMapping("/get_bind_statu") + public Result getBindStatus( +// @RequestHeader("Device-Token") String deviceToken, + @RequestHeader("Device-ID") String deviceId, +// @RequestHeader("Device-Sig") String deviceSig, + @RequestParam(value = "sn") String sn, + @RequestParam(value = "code1") String sigCode, + @RequestParam(value = "code2") String sha256 + ) { + if (TextUtils.isEmpty(sigCode) || TextUtils.isEmpty(sha256)) { + return Result.error().message("sigCode or sha256 is empty"); + } + + if (!"tongtongstudio".equals(sigCode)) { + return Result.error().message("sigCode not match"); + } + + if (!"5304915c4bb7baca28776231993996fde1baffcbbe6500fb0fc7f2d3a2888cb7".equalsIgnoreCase(sha256)) { + return Result.error().message("sha256 not match"); + } + +// 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"); + } + + Map map = new LinkedHashMap<>(); + map.put("device_token", deviceInfo.getToken()); + map.put("device_sig", deviceInfo.getBindSig()); + map.put("bind_status", 1); + map.put("device_alias", deviceInfo.getDeviceAlias()); + map.put("tablet_avatar", deviceInfo.getTabletAvatar()); + map.put("bind_phone", deviceInfo.getBindPhone()); + map.put("user_id", deviceInfo.getUserId()); + map.put("add_time", deviceInfo.getAddTime()); + map.put("bind_time", deviceInfo.getBindTime()); + + return Result.ok().data(map).message("sn bind"); + } } diff --git a/src/main/java/com/onekeycall/videotablet/controller/sn/BindSnController.java b/src/main/java/com/onekeycall/videotablet/controller/sn/BindSnController.java index 4a1dbda..0a15035 100644 --- a/src/main/java/com/onekeycall/videotablet/controller/sn/BindSnController.java +++ b/src/main/java/com/onekeycall/videotablet/controller/sn/BindSnController.java @@ -97,49 +97,4 @@ public class BindSnController { return Result.ok().data(map).message("bind success"); } - /** - * 获取平板sn绑定状态 - * 标准的通过平板获取接口,需要 Device-Token Device-ID Device-Sig - * @param deviceToken - * @param deviceId - * @param deviceSig - * @param sn - * @return - */ - // TODO: 2025/8/22 Device_Token在docker无法被接收到,使用Device-Token代替 - @GetMapping("/get_bind_statu") - public Result getBindStatus( -// @RequestHeader("Device-Token") String deviceToken, @RequestHeader("Device-ID") String deviceId, -// @RequestHeader("Device-Sig") String deviceSig, - @RequestParam(value = "sn") String sn) { - -// 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"); - } - - Map map = new LinkedHashMap<>(); - map.put("bind_status", 1); - map.put("device_alias", deviceInfo.getDeviceAlias()); - map.put("tablet_avatar", deviceInfo.getTabletAvatar()); - map.put("bind_phone", deviceInfo.getBindPhone()); - map.put("user_id", deviceInfo.getUserId()); - map.put("add_time", deviceInfo.getAddTime()); - map.put("bind_time", deviceInfo.getBindTime()); - - return Result.ok().data(map).message("sn bind"); - } - } diff --git a/src/main/java/com/onekeycall/videotablet/controller/user/ContactController.java b/src/main/java/com/onekeycall/videotablet/controller/user/ContactController.java index 909cb5a..c20a61c 100644 --- a/src/main/java/com/onekeycall/videotablet/controller/user/ContactController.java +++ b/src/main/java/com/onekeycall/videotablet/controller/user/ContactController.java @@ -102,4 +102,55 @@ public class ContactController { } return Result.ok().data(contacts); } + + @PostMapping("/control_contact") + public Result controlContact( + @RequestParam(value = "user_id") String userId, + @RequestParam(value = "sn") String sn, + @RequestParam(value = "contact_id") String contactId, + @RequestParam(value = "action") String action + ) throws ExecutionException, InterruptedException { + + User user = userService.getUserByUserId(userId); + if (user == null) { + return Result.error().message("user not found"); + } + DeviceInfo deviceInfo = deviceSnService.findBySn(sn); + if (deviceInfo == null) { + return Result.error().message("device not found"); + } + + if (!deviceInfo.getUserId().equals(userId)) { + return Result.error().message("device not belong to user"); + } + + List contacts = contactService.findAllBySn(sn); + if (contacts == null || contacts.isEmpty()) { + return Result.notFound().message("contacts not found"); + } + + Contact contact = contactService.findById(contactId); + if (contact == null) { + return Result.error().message("contact not found"); + } + + switch (action) { + case "call": + DevicePushUtils.aliyunAsyncPush(PushIdConfig.CONTACT_CALL, sn, GsonUtils.toJSONString(contact)); + break; + case "audio": + DevicePushUtils.aliyunAsyncPush(PushIdConfig.CONTACT_AUDIO, sn, GsonUtils.toJSONString(contact)); + break; + case "video": + DevicePushUtils.aliyunAsyncPush(PushIdConfig.CONTACT_VIDEO, sn, GsonUtils.toJSONString(contact)); + break; + case "delete": + DevicePushUtils.aliyunAsyncPush(PushIdConfig.CONTACT_DELETE, sn, GsonUtils.toJSONString(contact)); + break; + default: + return Result.error().message("action not found"); + } + + return Result.ok(); + } } diff --git a/src/main/java/com/onekeycall/videotablet/service/ContactService.java b/src/main/java/com/onekeycall/videotablet/service/ContactService.java index 0eff61c..5ff4c23 100644 --- a/src/main/java/com/onekeycall/videotablet/service/ContactService.java +++ b/src/main/java/com/onekeycall/videotablet/service/ContactService.java @@ -45,6 +45,10 @@ public class ContactService { return contactRepository.findAllBySn(sn); } + public Contact findById(String id) { + return contactRepository.findById(Long.valueOf(id)).orElse(null); + } + public void save(Contact contact) { contactRepository.save(contact); }