修改了分享嘛

This commit is contained in:
wucongxing8150 2024-12-10 14:50:55 +08:00
parent 14f4314982
commit 38ce98fada
2 changed files with 11 additions and 1 deletions

View File

@ -205,7 +205,7 @@ func (r *QuestionQaService) AddQuestionQa(req requests.AddQuestionQa) (bool, err
// 生成分享链接
questionQaData := make(map[string]interface{})
questionQaData["qa_share_id"] = utils.HashString(fmt.Sprintf("%d", questionQa.QaId))
questionQaData["qa_share_id"] = utils.GenerateUniqueCode()
err = questionQaDao.EditQuestionQaById(tx, questionQa.QaId, questionQaData)
if err != nil {
tx.Rollback()

View File

@ -7,7 +7,10 @@ import (
"crypto/sha256"
"encoding/base64"
"encoding/hex"
"fmt"
"io"
mathRand "math/rand"
"time"
)
// Encrypt 加密函数
@ -88,3 +91,10 @@ func hashKey(key string) []byte {
hash := sha256.Sum256([]byte(key))
return hash[:]
}
// GenerateUniqueCode 生成6位数唯一码
func GenerateUniqueCode() string {
mathRand.Seed(time.Now().UnixNano())
code := fmt.Sprintf("%06d", mathRand.Intn(999999))
return code
}