chore: 并入 iotlcm-app 历史到 app/(原提交 f40bda9)
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package allocaterequest
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
)
|
||||
|
||||
var validID = regexp.MustCompile(`^[A-Za-z0-9_-]{16,96}$`)
|
||||
|
||||
func Key(tenant string, user int64, requestID string) (string, error) {
|
||||
requestID = strings.TrimSpace(requestID)
|
||||
if tenant == "" || user <= 0 || !validID.MatchString(requestID) {
|
||||
return "", gerror.New("划拨请求标识无效")
|
||||
}
|
||||
value, err := json.Marshal([]any{tenant, user, "allocate", requestID})
|
||||
if err != nil {
|
||||
return "", gerror.Wrap(err, "生成划拨请求标识失败")
|
||||
}
|
||||
digest := sha256.Sum256(value)
|
||||
return hex.EncodeToString(digest[:]), nil
|
||||
}
|
||||
|
||||
func Fingerprint(cards []string, source, target int64, mode int, remark string) string {
|
||||
sorted := append([]string(nil), cards...)
|
||||
sort.Strings(sorted)
|
||||
value, _ := json.Marshal([]any{sorted, source, target, mode, strings.TrimSpace(remark)})
|
||||
digest := sha256.Sum256(value)
|
||||
return hex.EncodeToString(digest[:])
|
||||
}
|
||||
Reference in New Issue
Block a user