feat: 添加 GET /api/v1/time 基准时间接口

- 返回服务端 Unix 时间戳(秒)
- 客户端签名前调用此接口获取 timestamp
- 避免跨服务器时钟偏差导致 PSK 签名过期
This commit is contained in:
mediabot-pt
2026-06-29 17:07:29 +08:00
parent bb96062b7c
commit 4ba9ade790

View File

@@ -0,0 +1,25 @@
package com.par.api.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
/**
* 基准时间接口
* 客户端签名前获取服务端时间戳,避免时钟偏差导致签名失效
*/
@RestController
@RequestMapping("/api/v1")
public class TimeController {
/**
* 返回服务端当前 Unix 时间戳(秒)
*/
@GetMapping("/time")
public Map<String, Object> serverTime() {
long now = System.currentTimeMillis() / 1000;
return Map.of("timestamp", now, "unit", "seconds");
}
}