refactorL 适配新api

This commit is contained in:
sunxiaolong
2024-07-06 19:46:48 +08:00
parent 148d67cf63
commit c800439fa7
3 changed files with 23 additions and 23 deletions

1
.gitignore vendored
View File

@@ -1 +1,2 @@
/.idea
main.exe

41
main.go
View File

@@ -5,7 +5,6 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
gonanoid "github.com/matoous/go-nanoid/v2"
"io"
"kami_scripts/models"
"math"
@@ -15,6 +14,8 @@ import (
"strconv"
"sync"
"time"
gonanoid "github.com/matoous/go-nanoid/v2"
)
// SortMap 对map的key值进行排序
@@ -28,29 +29,27 @@ func SortMap(m map[string]string) []string {
}
func GenRandomCardNo() string {
cardNo := "GCA"
//GCA3238734750243
for i := 0; i < 13; i++ {
cardNo += strconv.Itoa(rand.Intn(10))
}
return cardNo
return ""
// cardNo := "X"
// for i := 0; i < 15; i++ {
// cardNo += strconv.Itoa(rand.Intn(10))
// }
// return cardNo
}
func GenRandomCardPass() string {
cardPass := ""
for i := 0; i < 16; i++ {
cardPass += string(rune(rand.Intn(26) + 65))
cardPass := "X"
for i := 0; i < 15; i++ {
cardPass += strconv.Itoa(rand.Intn(10))
}
return cardPass
// return cardPass
}
func genSign(data models.Data) string {
appSecret := "ssssc9kit6bimggos5kk0c9g"
params := map[string]string{}
exValue, _ := json.Marshal(data.ExValue)
params["exValue"] = string(exValue)
params["orderNo"] = data.OrderNo
params["orderPeriod"] = data.OrderPeriod
@@ -58,8 +57,8 @@ func genSign(data models.Data) string {
params["notifyUrl"] = data.NotifyUrl
params["timestamp"] = data.TimeStamp
params["payKey"] = data.PayKey
params["ip"] = data.Ip
params["productCode"] = data.ProductCode
strArr := SortMap(params)
signStr := ""
for i := 0; i < len(strArr); i++ {
@@ -71,13 +70,12 @@ func genSign(data models.Data) string {
}
}
signStr += appSecret
h := md5.New()
h.Write([]byte(signStr))
return hex.EncodeToString(h.Sum(nil))
}
func randomRequest(count int, stop chan int, group *sync.WaitGroup) {
func randomRequest(count int, stop chan int, group *sync.WaitGroup, client *http.Client) {
defer func() {
time.Sleep(time.Second * 2)
<-stop
@@ -88,8 +86,6 @@ func randomRequest(count int, stop chan int, group *sync.WaitGroup) {
}()
fmt.Println("正在发送请求次数", count)
id, _ := gonanoid.New()
client := http.Client{}
formData := models.Data{
ExValue: models.ExValue{
Data: GenRandomCardPass(),
@@ -101,6 +97,7 @@ func randomRequest(count int, stop chan int, group *sync.WaitGroup) {
OrderPeriod: strconv.Itoa(rand.Intn(24)),
OrderPrice: "100",
ProductCode: "8546",
Ip: "127.0.0.1",
NotifyUrl: "https://baidu.com",
PayKey: "kkkkc9kit6bimggos5kk0c90",
TimeStamp: strconv.FormatInt(time.Now().Unix(), 10),
@@ -108,7 +105,6 @@ func randomRequest(count int, stop chan int, group *sync.WaitGroup) {
}
formData.Sign = genSign(formData)
res, _ := client.PostForm("http://121.37.253.228:12309/gateway/scan", formData.Url())
result, _ := io.ReadAll(res.Body)
fmt.Println(string(result))
}
@@ -121,11 +117,12 @@ func randomRequest(count int, stop chan int, group *sync.WaitGroup) {
func main() {
group := sync.WaitGroup{}
startTime := time.Now()
stop := make(chan int, 100)
for i := 1; i < int(math.Pow10(3)); i++ {
stop := make(chan int, 10)
client := http.Client{}
for i := 1; i < int(math.Pow10(2)); i++ {
group.Add(1)
stop <- 1
go randomRequest(i, stop, &group)
go randomRequest(i, stop, &group, &client)
}
group.Wait()
fmt.Println("总耗时", time.Since(startTime).Seconds())

View File

@@ -15,6 +15,7 @@ type Data struct {
PayKey string `json:"PayKey"`
TimeStamp string `json:"timestamp"`
Sign string `json:"sign"`
Ip string `json:"ip"`
}
func (d *Data) Url() url.Values {
@@ -27,6 +28,7 @@ func (d *Data) Url() url.Values {
"productCode": {d.ProductCode},
"payKey": {d.PayKey},
"timestamp": {d.TimeStamp},
"ip": {d.Ip},
"sign": {d.Sign},
}
}