优化平板信息获取,优化推送复用及增加用户推送

This commit is contained in:
2025-08-22 18:04:35 +08:00
parent 6b5eeee6ee
commit 1038c1b0d4
6 changed files with 207 additions and 49 deletions

View File

@@ -1,31 +1,21 @@
package com.onekeycall.videotablet.controller;
import com.google.gson.JsonObject;
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.DevicePushUtils;
import com.onekeycall.videotablet.utils.TextUtils;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.JwtException;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import io.jsonwebtoken.security.Keys;
import jakarta.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.RandomStringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.security.oauth2.common.exceptions.InvalidTokenException;
import org.springframework.web.bind.annotation.*;
import javax.crypto.SecretKey;
import java.util.*;
import java.util.concurrent.TimeUnit;
@@ -82,11 +72,15 @@ public class BindSnController {
return Result.error().message("sn already bind");
}
try {
String verifyKey = RandomStringUtils.randomAlphanumeric(32);
// PushUtils.aliyunAsyncPush(verifyKey, userPhone, sn);
PushUtils.tpnsPush(verifyKey, userPhone, sn);
JsonObject params = new JsonObject();
params.addProperty("verify_key", verifyKey);
params.addProperty("phone", userPhone);
params.addProperty("expire_time", System.currentTimeMillis() + 60 * 1000);
// PushUtils.aliyunAsyncPush("1", params.toString(), sn);
DevicePushUtils.tpnsPush("1", params.toString(), sn);
redisTemplate.opsForValue().set(sn, verifyKey, 1, TimeUnit.MINUTES);
return Result.ok().message("send message success");
} catch (Exception e) {
@@ -147,7 +141,7 @@ public class BindSnController {
oldDeviceInfo.setToken(deviceToken);
oldDeviceInfo.setSn(sn);
deviceSnService.save(oldDeviceInfo);
Map<String, Object> map = new HashMap<>();
Map<String, Object> map = new LinkedHashMap<>();
map.put("phone", phone);
map.put("device_token", deviceToken);
map.put("device_sig", deviceSig);
@@ -170,16 +164,32 @@ public class BindSnController {
@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");
}
return Result.ok().message("sn bind");
Map<String, Object> map = new LinkedHashMap<>();
map.put("bind_status", 1);
map.put("device_alias", deviceInfo.getDeviceAlias());
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

@@ -1,14 +1,7 @@
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.*;

View File

@@ -1,15 +1,12 @@
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.CXAESUtil;
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.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;