2026-05-15 21:00:24 +08:00
|
|
|
package com.xuqm.license.controller;
|
|
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.annotation.JsonAlias;
|
|
|
|
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
2026-05-15 21:29:48 +08:00
|
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
2026-05-15 21:00:24 +08:00
|
|
|
import com.xuqm.common.model.ApiResponse;
|
|
|
|
|
import com.xuqm.license.service.DeviceService;
|
|
|
|
|
import jakarta.validation.Valid;
|
|
|
|
|
import jakarta.validation.constraints.NotBlank;
|
|
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("/api/license")
|
|
|
|
|
public class LicensePublicController {
|
|
|
|
|
|
|
|
|
|
private final DeviceService deviceService;
|
|
|
|
|
|
|
|
|
|
public LicensePublicController(DeviceService deviceService) {
|
|
|
|
|
this.deviceService = deviceService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PostMapping("/register")
|
|
|
|
|
public ResponseEntity<ApiResponse<Map<String, Object>>> register(@Valid @RequestBody RegisterRequest req) {
|
|
|
|
|
DeviceService.RegisterResult result = deviceService.register(
|
2026-05-15 21:42:10 +08:00
|
|
|
req.appKey(),
|
2026-05-15 21:00:24 +08:00
|
|
|
req.deviceId(),
|
|
|
|
|
req.deviceName(),
|
|
|
|
|
req.deviceModel(),
|
|
|
|
|
req.deviceVendor(),
|
2026-05-15 21:29:48 +08:00
|
|
|
req.osVersion(),
|
|
|
|
|
req.userInfo());
|
2026-05-15 21:00:24 +08:00
|
|
|
Map<String, Object> data = new java.util.LinkedHashMap<>();
|
|
|
|
|
data.put("success", result.success());
|
|
|
|
|
data.put("token", result.token());
|
|
|
|
|
if (result.message() != null) {
|
|
|
|
|
data.put("message", result.message());
|
|
|
|
|
}
|
|
|
|
|
return ResponseEntity.ok(ApiResponse.success(data));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PostMapping("/verify")
|
|
|
|
|
public ResponseEntity<ApiResponse<Map<String, Object>>> verify(@Valid @RequestBody VerifyRequest req) {
|
2026-05-15 21:42:10 +08:00
|
|
|
DeviceService.VerifyResult result = deviceService.verify(req.appKey(), req.deviceId(), req.token(), req.userInfo());
|
2026-05-15 21:00:24 +08:00
|
|
|
Map<String, Object> data = new java.util.LinkedHashMap<>();
|
|
|
|
|
data.put("valid", result.valid());
|
|
|
|
|
if (result.error() != null) {
|
|
|
|
|
data.put("error", result.error());
|
|
|
|
|
}
|
|
|
|
|
return ResponseEntity.ok(ApiResponse.success(data));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public record RegisterRequest(
|
2026-05-15 21:42:10 +08:00
|
|
|
@NotBlank String appKey,
|
2026-05-15 21:00:24 +08:00
|
|
|
@NotBlank @JsonProperty("deviceId") @JsonAlias("device_id") String deviceId,
|
|
|
|
|
@JsonProperty("deviceName") @JsonAlias("device_name") String deviceName,
|
|
|
|
|
@JsonProperty("deviceModel") @JsonAlias("device_model") String deviceModel,
|
|
|
|
|
@JsonProperty("deviceVendor") @JsonAlias("device_vendor") String deviceVendor,
|
2026-05-15 21:29:48 +08:00
|
|
|
@JsonProperty("osVersion") @JsonAlias("os_version") String osVersion,
|
|
|
|
|
@JsonProperty("userInfo") @JsonAlias("user_info") JsonNode userInfo
|
2026-05-15 21:00:24 +08:00
|
|
|
) {}
|
|
|
|
|
|
|
|
|
|
public record VerifyRequest(
|
2026-05-15 21:42:10 +08:00
|
|
|
@NotBlank String appKey,
|
2026-05-15 21:00:24 +08:00
|
|
|
@NotBlank @JsonProperty("deviceId") @JsonAlias("device_id") String deviceId,
|
2026-05-15 21:29:48 +08:00
|
|
|
@NotBlank String token,
|
|
|
|
|
@JsonProperty("userInfo") @JsonAlias("user_info") JsonNode userInfo
|
2026-05-15 21:00:24 +08:00
|
|
|
) {}
|
|
|
|
|
}
|