package license import ( "net/http" "github.com/gin-gonic/gin" ) // Verify 客户端 License 验证 // Logan.Li func (ctrl *LicenseController) Verify(c *gin.Context) { var req 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"` } if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"code": 400, "message": "参数错误: " + err.Error()}) return } resp, _ := ctrl.svc.Verify(req) c.JSON(http.StatusOK, resp) } // ActivateDevice 客户端激活(机器绑定) // Logan.Li func (ctrl *LicenseController) ActivateDevice(c *gin.Context) { var req 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"` } if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"code": 400, "message": "参数错误: " + err.Error()}) return } data, err := ctrl.svc.Activate(req, c.ClientIP()) if err != nil { c.JSON(http.StatusOK, gin.H{"code": 1, "message": err.Error()}) return } c.JSON(http.StatusOK, gin.H{"code": 0, "message": "激活成功", "data": data}) } // Deactivate 客户端停用 // Logan.Li func (ctrl *LicenseController) Deactivate(c *gin.Context) { var req struct { LicenseKey string `json:"license_key" binding:"required"` DeviceID string `json:"device_id" binding:"required"` } if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"code": 400, "message": "参数错误"}) return } if err := ctrl.svc.Deactivate(req); err != nil { c.JSON(http.StatusOK, gin.H{"code": 1, "message": err.Error()}) return } c.JSON(http.StatusOK, gin.H{"code": 0, "message": "停用成功"}) } // Heartbeat 客户端心跳 // Logan.Li func (ctrl *LicenseController) Heartbeat(c *gin.Context) { var req struct { LicenseKey string `json:"license_key" binding:"required"` DeviceID string `json:"device_id" binding:"required"` } if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"code": 400, "message": "参数错误"}) return } data, err := ctrl.svc.Heartbeat(req) if err != nil { c.JSON(http.StatusOK, gin.H{"code": 1, "message": err.Error()}) return } c.JSON(http.StatusOK, gin.H{"code": 0, "message": "心跳成功", "data": data}) }