增加添加和绑定sn,增加阿里云推送
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
package com.onekeycall.videotablet.controller;
|
||||
|
||||
import com.onekeycall.videotablet.entity.DeviceInfo;
|
||||
import com.onekeycall.videotablet.entity.User;
|
||||
import com.onekeycall.videotablet.result.Result;
|
||||
import com.onekeycall.videotablet.service.DeviceSnService;
|
||||
import com.onekeycall.videotablet.service.UserService;
|
||||
import com.onekeycall.videotablet.utils.JwtUtil;
|
||||
import com.onekeycall.videotablet.utils.PushUtils;
|
||||
import com.onekeycall.videotablet.utils.TextUtils;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/public")
|
||||
public class ManageSnController {
|
||||
|
||||
@Autowired
|
||||
private JwtUtil jwtUtil;
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
@Autowired
|
||||
private DeviceSnService deviceSnService;
|
||||
|
||||
@PostMapping("/add_sn")
|
||||
public Result addSn(
|
||||
@RequestHeader("Authorization") String authHeader, @RequestHeader("Device-ID") String deviceId,
|
||||
@RequestParam(value = "user_id") String userId, @RequestParam(value = "sn") String sn) {
|
||||
// 1. 校验 Authorization 头
|
||||
if (!authHeader.startsWith("Bearer ")) {
|
||||
return Result.error().message("Invalid Authorization header");
|
||||
}
|
||||
String token = authHeader.substring(7); // 去掉 "Bearer " 前缀
|
||||
|
||||
// 2. 校验 Token
|
||||
if (!jwtUtil.validateAccessToken(userId, token, deviceId)) {
|
||||
return Result.error().message("Invalid token");
|
||||
}
|
||||
|
||||
// 3. 校验 sn 是否存在
|
||||
DeviceInfo oldDeviceInfo = deviceSnService.findBySn(sn);
|
||||
if (oldDeviceInfo != null) {
|
||||
return Result.error().message("sn already exists");
|
||||
}
|
||||
|
||||
// 4. 新增 sn
|
||||
DeviceInfo deviceInfo = new DeviceInfo();
|
||||
deviceInfo.setSn(sn);
|
||||
deviceInfo.setAddTime(new Date());
|
||||
deviceSnService.save(deviceInfo);
|
||||
|
||||
return Result.ok();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user