Files
opsx-licence/backend/internal/dto/license.go
T

154 lines
6.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package dto
// LicenseCreate 创建 License 请求 // Logan.Li
type LicenseCreate struct {
CustomerID uint `json:"customer_id" binding:"required"`
ProductID uint `json:"product_id" binding:"required"`
Duration int `json:"duration"` // 30/90/180/365/…/0(永久);0 合法,勿用 binding:required
MaxActivations int `json:"max_activations"`
IsTrial bool `json:"is_trial"`
TrialDays int `json:"trial_days"`
Notes string `json:"notes"`
Count int `json:"count"` // 批量生成数量
}
// LicenseRenew 续期请求 // Logan.Li
type LicenseRenew struct {
Duration int `json:"duration" binding:"required"`
}
// LicenseBatchDeleteRequest 批量删除请求 // Logan.Li
type LicenseBatchDeleteRequest struct {
IDs []uint `json:"ids" binding:"required,min=1"`
}
// LicenseBatchDeleteResponse 批量删除响应 // Logan.Li
type LicenseBatchDeleteResponse struct {
Deleted int `json:"deleted"`
Skipped int `json:"skipped"`
Failed int `json:"failed"`
SkippedIDs []uint `json:"skipped_ids,omitempty"`
}
// LicenseResponse License 响应 // Logan.Li
type LicenseResponse struct {
ID uint `json:"id"`
LicenseKey string `json:"license_key"`
LicenseKeyShort string `json:"license_key_short"` // 列表展示用短码,避免 LICOFF 撑爆表格 // Logan.Li
Channel string `json:"channel"` // online | offline
IsOffline bool `json:"is_offline"`
DeviceID string `json:"device_id,omitempty"` // 离线证绑定设备
CustomerID uint `json:"customer_id"`
CustomerName string `json:"customer_name"`
CustomerEmail string `json:"customer_email,omitempty"`
ProductID uint `json:"product_id"`
ProductName string `json:"product_name"`
Status string `json:"status"`
StartDate string `json:"start_date"`
EndDate string `json:"end_date"`
Duration int `json:"duration"`
MaxActivations int `json:"max_activations"`
CurrentActivations int `json:"current_activations"`
IsTrial bool `json:"is_trial"`
DaysLeft int `json:"days_left"`
Notes string `json:"notes"`
CreatedAt string `json:"created_at"`
DistinctIPs int `json:"distinct_ips"` // 激活记录中的不重复 IP 数(疑似共享信号)
NewDevices7d int `json:"new_devices_7d"` // 近 7 天新增设备数(换座频次信号)
AbuseSuspected bool `json:"abuse_suspected"` // 疑似共享/滥用标记
}
// ============ 客户端授权契约(无需认证) ============
// LicenseVerifyRequest 验证请求(客户端调用) // Logan.Li
type LicenseVerifyRequest struct {
LicenseKey string `json:"license_key" binding:"required"`
DeviceID string `json:"device_id"`
DeviceName string `json:"device_name"`
DeviceInfo string `json:"device_info"`
ProductID uint `json:"product_id"`
}
// LicenseVerifyResponse 验证响应 // Logan.Li
type LicenseVerifyResponse struct {
Valid bool `json:"valid"`
LicenseKey string `json:"license_key,omitempty"`
ProductID uint `json:"product_id,omitempty"`
ProductName string `json:"product_name,omitempty"`
ProductCode string `json:"product_code,omitempty"`
Features []string `json:"features,omitempty"`
Status string `json:"status,omitempty"`
ExpiresAt string `json:"expires_at,omitempty"`
DaysLeft int `json:"days_left,omitempty"`
MaxDevices int `json:"max_devices,omitempty"`
PlanType string `json:"plan_type,omitempty"`
Message string `json:"message,omitempty"`
InGrace bool `json:"in_grace,omitempty"` // 宽限期内(仅商业过期,吊销/暂停无宽限)
GraceDaysLeft int `json:"grace_days_left,omitempty"` // 宽限剩余天数
ExpiresAtUnix int64 `json:"expires_at_unix,omitempty"` // 到期时间 unix 秒(签名字段,客户端直接回用免时区换算)
ServerTime int64 `json:"server_time,omitempty"` // 服务端时间(unix 秒),客户端据此防时钟回拨
Sig string `json:"sig,omitempty"` // Ed25519 签名(hex),客户端用内嵌公钥验签防假服务器
}
// LicenseActivateRequest 激活请求(客户端调用) // Logan.Li
type LicenseActivateRequest struct {
LicenseKey string `json:"license_key" binding:"required"`
DeviceID string `json:"device_id" binding:"required"`
DeviceName string `json:"device_name"`
DeviceInfo string `json:"device_info"`
}
// LicenseDeactivateRequest 停用请求(客户端调用) // Logan.Li
type LicenseDeactivateRequest struct {
LicenseKey string `json:"license_key" binding:"required"`
DeviceID string `json:"device_id" binding:"required"`
ActivationToken string `json:"activation_token"` // 本机激活时下发的令牌;解绑他机需联系管理员
}
// LicenseHeartbeatRequest 心跳请求(客户端调用) // Logan.Li
type LicenseHeartbeatRequest struct {
LicenseKey string `json:"license_key" binding:"required"`
DeviceID string `json:"device_id" binding:"required"`
}
// ActivationResponse 激活记录响应 // Logan.Li
type ActivationResponse struct {
ID uint `json:"id"`
LicenseID uint `json:"license_id"`
DeviceID string `json:"device_id"`
DeviceName string `json:"device_name"`
DeviceInfo string `json:"device_info"`
IP string `json:"ip"`
Status string `json:"status"`
IsOnline bool `json:"is_online"`
ActivatedAt string `json:"activated_at"`
LastSeenAt string `json:"last_seen_at"`
}
// OfflineLicenseCreate 管理端签发离线许可证请求 // Logan.Li
type OfflineLicenseCreate struct {
DeviceID string `json:"device_id" binding:"required"`
Email string `json:"email"`
CustomerID uint `json:"customer_id"`
CustomerName string `json:"customer_name"`
ProductCode string `json:"product_code"`
PlanType string `json:"plan_type"` // trial | yearly(禁止 perpetual)
DurationDays int `json:"duration_days"` // 1–365,默认 365;trial 上限 180
Notes string `json:"notes"`
}
// OfflineLicenseResponse 离线许可证签发结果 // Logan.Li
type OfflineLicenseResponse struct {
Serial string `json:"serial"`
DeviceID string `json:"device_id"`
Email string `json:"email,omitempty"`
PlanType string `json:"plan_type"`
ProductCode string `json:"product_code"`
IssuedAt string `json:"issued_at"`
ExpiresAt string `json:"expires_at"`
Duration int `json:"duration_days"`
MaxDevices int `json:"max_devices"`
LicenseID uint `json:"license_id"`
PublicKey string `json:"public_key_hex"`
}