// 许可证类型 export type LicenseType = 'FREE' | 'STANDARD' | 'PRO'; // 许可证配置 export interface LicenseConfig { type: LicenseType; limits: { maxUsers: number; // -1 表示无限 maxMaterials: number; // -1 表示无限 }; features: { customTemplates: boolean; systemSettings: boolean; departmentIsolation: boolean; apiAccess: boolean; intranetPenetration: boolean; }; expiresAt: string | null; // ISO 日期字符串,null 表示永久 } // 签名后的许可证 export interface SignedLicense { data: LicenseConfig & { issuedAt: string }; signature: string; issuedAt: string; } // 硬件指纹 export interface HardwareFingerprint { machineId: string; hostname: string; macAddress: string; cpuId?: string; instanceId: string; } // 激活请求 export interface ActivateRequest { licenseKey: string; fingerprint: HardwareFingerprint; timestamp: number; } // 激活响应 export interface ActivateResponse { success: boolean; license?: SignedLicense; error?: string; } // 验证请求 export interface VerifyRequest { instanceId: string; fingerprint: HardwareFingerprint; timestamp: number; } // 验证响应 export interface VerifyResponse { valid: boolean; license?: SignedLicense; error?: string; } // 心跳请求 export interface HeartbeatRequest { instanceId: string; fingerprint: HardwareFingerprint; usage: { userCount: number; materialCount: number; }; timestamp: number; } // 心跳响应 export interface HeartbeatResponse { acknowledged: boolean; license?: SignedLicense; } // 本地存储的许可证数据 export interface LocalLicenseData { instanceId: string; licenseKey: string; licenseData: string; // 加密存储的签名许可证 lastVerified: string; // ISO 日期字符串 cachedConfig: LicenseConfig; } // 功能键 export type FeatureKey = keyof LicenseConfig['features']; // 各版本的默认配置 export const LICENSE_CONFIGS: Record> = { FREE: { type: 'FREE', limits: { maxUsers: 10, maxMaterials: 100, }, features: { customTemplates: false, systemSettings: false, departmentIsolation: false, apiAccess: false, intranetPenetration: false, }, }, STANDARD: { type: 'STANDARD', limits: { maxUsers: -1, maxMaterials: -1, }, features: { customTemplates: true, systemSettings: true, departmentIsolation: true, apiAccess: true, intranetPenetration: false, }, }, PRO: { type: 'PRO', limits: { maxUsers: -1, maxMaterials: -1, }, features: { customTemplates: true, systemSettings: true, departmentIsolation: true, apiAccess: true, intranetPenetration: true, }, }, }; /** * 根据许可证类型生成配置 */ export function generateLicenseConfig( type: LicenseType, expiresAt?: Date | null ): LicenseConfig { const baseConfig = LICENSE_CONFIGS[type]; return { ...baseConfig, expiresAt: expiresAt ? expiresAt.toISOString() : null, }; }