50 lines
1.7 KiB
Java
50 lines
1.7 KiB
Java
package com.onekeycall.videotablet.controller;
|
|
|
|
import com.onekeycall.videotablet.entity.DeviceInfo;
|
|
import com.onekeycall.videotablet.result.Result;
|
|
import com.onekeycall.videotablet.service.DeviceSnService;
|
|
import com.onekeycall.videotablet.service.UserService;
|
|
import com.onekeycall.videotablet.tencent.trtc.TLSSigAPIv2;
|
|
import com.onekeycall.videotablet.utils.JwtUtil;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import java.time.Instant;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
|
|
@RestController
|
|
@RequestMapping("/public")
|
|
public class TencentTrtcController {
|
|
@Autowired
|
|
private JwtUtil jwtUtil;
|
|
@Autowired
|
|
private UserService userService;
|
|
@Autowired
|
|
private DeviceSnService deviceSnService;
|
|
|
|
|
|
@GetMapping("/get_trtc_sig")
|
|
public Result getTrtcSig(
|
|
@RequestHeader("Authorization") String authHeader, @RequestHeader("Device-ID") String deviceId,
|
|
@RequestParam(value = "user_id") String userId
|
|
) {
|
|
if (!authHeader.startsWith("Bearer ")) {
|
|
return Result.error().message("Invalid Authorization header");
|
|
}
|
|
String token = authHeader.substring(7); // 去掉 "Bearer " 前缀
|
|
|
|
if (!jwtUtil.validateAccessToken(userId, token, deviceId)) {
|
|
return Result.error().message("Invalid token");
|
|
}
|
|
|
|
TLSSigAPIv2 tlsSigAPIv2 = new TLSSigAPIv2(1600100994, "ccc0d591fe50bd9c05df7e3182256eb43fd83d1127ae7dc01a3d256dd80f3ae2");
|
|
String sig = tlsSigAPIv2.genUserSig(userId);
|
|
Map<String, Object> map = new HashMap<>();
|
|
map.put("sig", sig);
|
|
map.put("expire", Instant.now().getEpochSecond() + TLSSigAPIv2.EXPIRETIME);
|
|
return Result.ok().data(map);
|
|
}
|
|
}
|
|
|