增加联系人操作,优化无状态获取绑定的信息

This commit is contained in:
2025-09-29 10:36:37 +08:00
parent 6a55ac47e3
commit 8c8af32a93
5 changed files with 125 additions and 45 deletions

View File

@@ -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";
}

View File

@@ -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<String, Object> 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");
}
}

View File

@@ -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<String, Object> 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");
}
}

View File

@@ -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<Contact> 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();
}
}

View File

@@ -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);
}