Browse Source

no message

xingzai 11 months ago
parent
commit
d8681e8bf5
4 changed files with 122 additions and 0 deletions
  1. 1 0
      models/user.go
  2. 22 0
      models/user_admin_share.go
  3. 92 0
      services/aes.go
  4. 7 0
      services/user_admin_share.go

+ 1 - 0
models/user.go

@@ -154,6 +154,7 @@ type UserDetailResp struct {
 	IsAuthor             bool     `description:"是否开通了研选专栏"`
 	SpecialColumnId      int      // 专栏栏目ID
 	IsImproveInformation bool     `description:"作者信息是否完善"`
+	InviteShareCode      string   `description:"销售账号邀请码"`
 }
 
 type CheckStatusResp struct {

+ 22 - 0
models/user_admin_share.go

@@ -0,0 +1,22 @@
+package models
+
+import "time"
+
+type CygxUserAdminShare struct {
+	UserAdminShareID int       `orm:"column(user_admin_share_id);pk";comment:"主键ID"`
+	Action           string    `comment:"动作内容"`
+	UserId           int       `comment:"用户ID"`
+	Mobile           string    `comment:"手机号"`
+	Email            string    `comment:"邮箱"`
+	CompanyId        int       `comment:"公司ID"`
+	CompanyName      string    `comment:"公司名称"`
+	RealName         string    `comment:"用户实际名称"`
+	SellerName       string    `comment:"所属销售名称"`
+	SellerId         int       `comment:"所属销售 ID"`
+	Source           string    `comment:"来源(article, activity, login)"`
+	SourceId         int       `comment:"来源 ID"`
+	SourceTitle      string    `comment:"来源名称,活动或者报告标题"`
+	RegisterPlatform int       `comment:"注册平台(1: 小程序, 2: 网页)"`
+	CreateTime       time.Time `comment:"创建时间"`
+	ModifyTime       time.Time `comment:"修改时间"`
+}

+ 92 - 0
services/aes.go

@@ -0,0 +1,92 @@
+package services
+
+import (
+	"crypto/aes"
+	"crypto/cipher"
+	"crypto/rand"
+	"encoding/base64"
+	"fmt"
+	"io"
+	"strconv"
+)
+
+var aseKey = []byte("kmk6ln3n4mibig8p") // 加密密钥(必须是16、24或32字节)
+
+func init() {
+	// 原始数据
+	originalData := 123
+
+	// 加密数据
+	encryptedData, err := encrypt(originalData, aseKey)
+	if err != nil {
+		fmt.Println("加密时出错:", err)
+		return
+	}
+	fmt.Println("加密后的数据:", encryptedData)
+
+	// 解密数据
+	decryptedData, err := decrypt(encryptedData, aseKey)
+	if err != nil {
+		fmt.Println("解密时出错:", err)
+		return
+	}
+	fmt.Println("解密后的数据:", decryptedData)
+}
+
+func encrypt(data int, key []byte) (string, error) {
+	// 将数据转换为字节数组
+	dataBytes := []byte(fmt.Sprintf("%d", data))
+
+	// 创建一个新的 AES 块
+	block, err := aes.NewCipher(key)
+	if err != nil {
+		return "", err
+	}
+
+	// 创建一个加密流
+	ciphertext := make([]byte, aes.BlockSize+len(dataBytes))
+	iv := ciphertext[:aes.BlockSize]
+	if _, err := io.ReadFull(rand.Reader, iv); err != nil {
+		return "", err
+	}
+
+	// 使用密钥加密数据
+	stream := cipher.NewCFBEncrypter(block, iv)
+	stream.XORKeyStream(ciphertext[aes.BlockSize:], dataBytes)
+
+	// 返回加密后的数据(使用base64编码以便于传输)
+	return base64.StdEncoding.EncodeToString(ciphertext), nil
+}
+
+func decrypt(data string, key []byte) (int, error) {
+	// 解码base64数据
+	ciphertext, err := base64.StdEncoding.DecodeString(data)
+	if err != nil {
+		return 0, err
+	}
+
+	// 创建一个新的 AES 块
+	block, err := aes.NewCipher(key)
+	if err != nil {
+		return 0, err
+	}
+
+	// 解密流
+	if len(ciphertext) < aes.BlockSize {
+		return 0, fmt.Errorf("加密数据长度不够")
+	}
+	iv := ciphertext[:aes.BlockSize]
+	ciphertext = ciphertext[aes.BlockSize:]
+
+	// 解密数据
+	stream := cipher.NewCFBDecrypter(block, iv)
+	stream.XORKeyStream(ciphertext, ciphertext)
+
+	// 将解密的数据转换为int
+	decryptedData, err := strconv.Atoi(string(ciphertext))
+	if err != nil {
+		return 0, err
+	}
+
+	return decryptedData, nil
+}

+ 7 - 0
services/user_admin_share.go

@@ -0,0 +1,7 @@
+package services
+
+
+InviteShareCode
+func ()  {
+
+}