Files
lckt-server/test/rain_test.go

105 lines
2.7 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package test
import (
"crypto/md5"
"fmt"
"git.echol.cn/loser/lckt/core"
"git.echol.cn/loser/lckt/global"
"git.echol.cn/loser/lckt/initialize"
"git.echol.cn/loser/lckt/task"
"go.uber.org/zap"
"golang.org/x/crypto/bcrypt"
"math/rand"
"net/http"
"net/url"
"testing"
"time"
)
const charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
func TestRain(t *testing.T) {
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) {
password, _ := bcrypt.GenerateFromPassword([]byte("loser7659"), bcrypt.DefaultCost)
fmt.Println(string(password))
err := bcrypt.CompareHashAndPassword(password, []byte("122456"))
if err != nil {
fmt.Println("密码错误")
} else {
fmt.Println("密码正确")
}
}
func TestCode(t *testing.T) {
rand.New(rand.NewSource(time.Now().UnixNano()))
verifyCode := fmt.Sprintf("%06v", rand.Int31n(1000000))
// 测试验证码生成
sendCode(verifyCode)
}
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("请求失败,状态码:", resp.StatusCode)
}
}
func TestTime(t *testing.T) {
// 默认未过期,获取过期时间+30天
// 将 existingTeacherVip.ExpireAt转为time.Time类型
parse, err := time.Parse("2006-01-02", "2025-09-10")
if err != nil {
global.GVA_LOG.Error("转换过期时间出错", zap.Error(err))
return
}
after := time.Now().After(parse)
fmt.Println(after)
}
func TestTask(t *testing.T) {
global.GVA_VP = core.Viper() // 初始化Viper
global.GVA_LOG = core.Zap() // 初始化zap日志库
zap.ReplaceGlobals(global.GVA_LOG)
global.GVA_DB = initialize.Gorm() // gorm连接数据库
initialize.DBList()
err := task.CheckVip(global.GVA_DB)
if err != nil {
fmt.Println("清理表失败", err.Error())
} else {
fmt.Println("清理表成功")
}
}