From 0c140fa4c180f59ce98bf642f29d1b1345557a85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Mon, 16 Nov 2020 11:45:06 +0800 Subject: [PATCH] tuiguangm --- business/jxstore/cms/user2.go | 2 +- business/jxutils/jxutils.go | 19 ++++++++----------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/business/jxstore/cms/user2.go b/business/jxstore/cms/user2.go index c1c5ee147..f27f016c9 100644 --- a/business/jxstore/cms/user2.go +++ b/business/jxstore/cms/user2.go @@ -227,7 +227,7 @@ func CreateUser(user *model.User, creatorName string) (err error) { user.Status = model.UserStatusNormal // user.DividePercentage = 1 //推广码 - user.PopCode = jxutils.GenValidateCode(6) + user.PopCode = jxutils.GenRandomString(6) return dao.CreateEntity(nil, user) } diff --git a/business/jxutils/jxutils.go b/business/jxutils/jxutils.go index a5d5d3d83..b163934a9 100644 --- a/business/jxutils/jxutils.go +++ b/business/jxutils/jxutils.go @@ -894,16 +894,13 @@ func polarTriangleArea(tan1, lng1, tan2, lng2 float64) (s float64) { return 2 * math.Atan2(t*math.Sin(deltaLng), 1+t*math.Cos(deltaLng)) } -func GenValidateCode(width int) string { - numeric := [36]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, - 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', - 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'} - r := len(numeric) - rand.Seed(time.Now().UnixNano()) - - var sb strings.Builder - for i := 0; i < width; i++ { - fmt.Fprintf(&sb, "%d", numeric[rand.Intn(r)]) +func GenRandomString(l int) string { + str := "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" + bytes := []byte(str) + result := []byte{} + r := rand.New(rand.NewSource(time.Now().UnixNano())) + for i := 0; i < l; i++ { + result = append(result, bytes[r.Intn(len(bytes))]) } - return sb.String() + return string(result) }