🎨 一堆杂七杂八的优化
This commit is contained in:
@@ -1,18 +1,34 @@
|
||||
package test
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"fmt"
|
||||
"git.echol.cn/loser/lckt/utils/sms"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
const charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
||||
|
||||
func TestRain(t *testing.T) {
|
||||
rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
verifyCode := fmt.Sprintf("%06v", rand.Int31n(1000000))
|
||||
fmt.Println(verifyCode)
|
||||
num := GenerateOrderNum()
|
||||
fmt.Println("生成的订单号:", num)
|
||||
}
|
||||
|
||||
func GenerateOrderNum() string {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
// 拼接用户ID和随机数
|
||||
data := fmt.Sprintf("%d%d", 6, rand.Intn(1000000))
|
||||
hash := md5.Sum([]byte(data))
|
||||
code := ""
|
||||
for i := 0; i < 12; i++ {
|
||||
// 取哈希的前6位,每位映射到字符集
|
||||
code += string(charset[int(hash[i])%len(charset)])
|
||||
}
|
||||
return code
|
||||
}
|
||||
|
||||
func TestPwd(t *testing.T) {
|
||||
@@ -28,14 +44,30 @@ func TestPwd(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCode(t *testing.T) {
|
||||
// 测试验证码生成
|
||||
rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
verifyCode := fmt.Sprintf("%06v", rand.Int31n(1000000))
|
||||
// 测试验证码生成
|
||||
sendCode(verifyCode)
|
||||
}
|
||||
|
||||
test := sms.SendSMSTest("17754945397", verifyCode)
|
||||
if test {
|
||||
fmt.Println("短信发送成功")
|
||||
func sendCode(code string) {
|
||||
// 内容 通过urlEncode编码
|
||||
content := "【海口龙华铁坚成电子商务商行】您的验证码是" + code + "。如非本人操作,请忽略本短信"
|
||||
// urlencode编码内容
|
||||
content = url.QueryEscape(content)
|
||||
|
||||
api := "https://api.smsbao.com/sms?u=lchz5599&p=7ea114c87a224cd38a0d616b9be3faed&g=海口龙华铁坚成电子商务商行&m=17754945397&c=" + content
|
||||
|
||||
// 发送GET请求
|
||||
resp, err := http.Get(api)
|
||||
if err != nil {
|
||||
fmt.Println("请求失败:", err)
|
||||
return
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode == http.StatusOK {
|
||||
fmt.Println("请求成功,短信发送成功")
|
||||
} else {
|
||||
fmt.Println("短信发送失败")
|
||||
fmt.Println("请求失败,状态码:", resp.StatusCode)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user