animeic il y a 1 an
Parent
commit
6afb364794
1 fichiers modifiés avec 36 ajouts et 0 suppressions
  1. 36 0
      boxcost/api/mac-cpu.go

+ 36 - 0
boxcost/api/mac-cpu.go

@@ -2,6 +2,8 @@ package api
 
 import (
 	"box-cost/conf"
+	"box-cost/db/repo"
+	"box-cost/log"
 	"crypto/hmac"
 	"crypto/sha256"
 	"fmt"
@@ -10,6 +12,7 @@ import (
 
 	"github.com/gin-gonic/gin"
 	"github.com/shirou/gopsutil/net"
+	"go.mongodb.org/mongo-driver/bson/primitive"
 )
 
 func Mac(r *GinRouter) {
@@ -65,6 +68,39 @@ func GetCode(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 	// fmt.Println(len("86068c837d554c8aba4f997b51be6bc209b68cdad7c5a4a0adccbfc289adf4a2"))
 	// fmt.Println(len("63e208dc7452ab74932b9e37"))
 	// fmt.Println(len(UtilMd5(mac)))
+	appName := c.Query("appName")
+	appVersion := c.Query("appVersion")
+	// create_time := c.Query("createTime")
+
+	// deviceId设置唯一key
+	type RegCode struct {
+		Id         primitive.ObjectID `bson:"_id,omitempty" json:"_id"`
+		AppName    string             `bson:"appName,omitempty" json:"appName"`
+		AppVersion string             `bson:"appVersion,omitempty" json:"appVersion"`
+		DeviceId   string             `bson:"deviceId,omitempty" json:"deviceId"`
+		Key        string             `bson:"key,omitempty" json:"key"`
+		Code       string             `bson:"code,omitempty" json:"code"`
+		CreateTime time.Time          `bson:"createTime,omitempty" json:"createTime"`
+		UpdateTIme time.Time          `bson:"updateTIme,omitempty" json:"updateTIme"`
+		ExpireTime time.Time          `bson:"expireTime,omitempty" json:"expireTime"`
+		Status     int                `bson:"status,omitempty" json:"status"`
+	}
+	_, err := repo.RepoAddDoc(apictx.CreateRepoCtx(), "reg-code", &RegCode{
+
+		AppName:    appName,
+		AppVersion: appVersion,
+		DeviceId:   deviceId,
+		Key:        SECRET_KEY,
+		Code:       fmt.Sprintf("%x", signature),
+		CreateTime: time.Now(),
+		UpdateTIme: time.Now(),
+		ExpireTime: time.Now().AddDate(0, 0, 3),
+		Status:     1,
+	})
+	if err != nil {
+		log.Error(err)
+		return nil, err
+	}
 
 	// 输出签名结果
 	c.String(http.StatusOK, fmt.Sprintf("%x", signature))