mirror of
https://git.oceanpay.cc/danial/kami_script.git
synced 2025-12-18 22:06:37 +00:00
refactorL 适配新api
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1 +1,2 @@
|
|||||||
/.idea
|
/.idea
|
||||||
|
main.exe
|
||||||
41
main.go
41
main.go
@@ -5,7 +5,6 @@ import (
|
|||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
gonanoid "github.com/matoous/go-nanoid/v2"
|
|
||||||
"io"
|
"io"
|
||||||
"kami_scripts/models"
|
"kami_scripts/models"
|
||||||
"math"
|
"math"
|
||||||
@@ -15,6 +14,8 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
gonanoid "github.com/matoous/go-nanoid/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SortMap 对map的key值进行排序
|
// SortMap 对map的key值进行排序
|
||||||
@@ -28,29 +29,27 @@ func SortMap(m map[string]string) []string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GenRandomCardNo() string {
|
func GenRandomCardNo() string {
|
||||||
cardNo := "GCA"
|
return ""
|
||||||
//GCA3238734750243
|
// cardNo := "X"
|
||||||
for i := 0; i < 13; i++ {
|
// for i := 0; i < 15; i++ {
|
||||||
cardNo += strconv.Itoa(rand.Intn(10))
|
// cardNo += strconv.Itoa(rand.Intn(10))
|
||||||
}
|
// }
|
||||||
return cardNo
|
// return cardNo
|
||||||
}
|
}
|
||||||
|
|
||||||
func GenRandomCardPass() string {
|
func GenRandomCardPass() string {
|
||||||
cardPass := ""
|
cardPass := "X"
|
||||||
for i := 0; i < 16; i++ {
|
for i := 0; i < 15; i++ {
|
||||||
cardPass += string(rune(rand.Intn(26) + 65))
|
cardPass += strconv.Itoa(rand.Intn(10))
|
||||||
}
|
}
|
||||||
return cardPass
|
return cardPass
|
||||||
|
// return cardPass
|
||||||
}
|
}
|
||||||
|
|
||||||
func genSign(data models.Data) string {
|
func genSign(data models.Data) string {
|
||||||
appSecret := "ssssc9kit6bimggos5kk0c9g"
|
appSecret := "ssssc9kit6bimggos5kk0c9g"
|
||||||
|
|
||||||
params := map[string]string{}
|
params := map[string]string{}
|
||||||
|
|
||||||
exValue, _ := json.Marshal(data.ExValue)
|
exValue, _ := json.Marshal(data.ExValue)
|
||||||
|
|
||||||
params["exValue"] = string(exValue)
|
params["exValue"] = string(exValue)
|
||||||
params["orderNo"] = data.OrderNo
|
params["orderNo"] = data.OrderNo
|
||||||
params["orderPeriod"] = data.OrderPeriod
|
params["orderPeriod"] = data.OrderPeriod
|
||||||
@@ -58,8 +57,8 @@ func genSign(data models.Data) string {
|
|||||||
params["notifyUrl"] = data.NotifyUrl
|
params["notifyUrl"] = data.NotifyUrl
|
||||||
params["timestamp"] = data.TimeStamp
|
params["timestamp"] = data.TimeStamp
|
||||||
params["payKey"] = data.PayKey
|
params["payKey"] = data.PayKey
|
||||||
|
params["ip"] = data.Ip
|
||||||
params["productCode"] = data.ProductCode
|
params["productCode"] = data.ProductCode
|
||||||
|
|
||||||
strArr := SortMap(params)
|
strArr := SortMap(params)
|
||||||
signStr := ""
|
signStr := ""
|
||||||
for i := 0; i < len(strArr); i++ {
|
for i := 0; i < len(strArr); i++ {
|
||||||
@@ -71,13 +70,12 @@ func genSign(data models.Data) string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
signStr += appSecret
|
signStr += appSecret
|
||||||
|
|
||||||
h := md5.New()
|
h := md5.New()
|
||||||
h.Write([]byte(signStr))
|
h.Write([]byte(signStr))
|
||||||
return hex.EncodeToString(h.Sum(nil))
|
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() {
|
defer func() {
|
||||||
time.Sleep(time.Second * 2)
|
time.Sleep(time.Second * 2)
|
||||||
<-stop
|
<-stop
|
||||||
@@ -88,8 +86,6 @@ func randomRequest(count int, stop chan int, group *sync.WaitGroup) {
|
|||||||
}()
|
}()
|
||||||
fmt.Println("正在发送请求次数", count)
|
fmt.Println("正在发送请求次数", count)
|
||||||
id, _ := gonanoid.New()
|
id, _ := gonanoid.New()
|
||||||
|
|
||||||
client := http.Client{}
|
|
||||||
formData := models.Data{
|
formData := models.Data{
|
||||||
ExValue: models.ExValue{
|
ExValue: models.ExValue{
|
||||||
Data: GenRandomCardPass(),
|
Data: GenRandomCardPass(),
|
||||||
@@ -101,6 +97,7 @@ func randomRequest(count int, stop chan int, group *sync.WaitGroup) {
|
|||||||
OrderPeriod: strconv.Itoa(rand.Intn(24)),
|
OrderPeriod: strconv.Itoa(rand.Intn(24)),
|
||||||
OrderPrice: "100",
|
OrderPrice: "100",
|
||||||
ProductCode: "8546",
|
ProductCode: "8546",
|
||||||
|
Ip: "127.0.0.1",
|
||||||
NotifyUrl: "https://baidu.com",
|
NotifyUrl: "https://baidu.com",
|
||||||
PayKey: "kkkkc9kit6bimggos5kk0c90",
|
PayKey: "kkkkc9kit6bimggos5kk0c90",
|
||||||
TimeStamp: strconv.FormatInt(time.Now().Unix(), 10),
|
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)
|
formData.Sign = genSign(formData)
|
||||||
res, _ := client.PostForm("http://121.37.253.228:12309/gateway/scan", formData.Url())
|
res, _ := client.PostForm("http://121.37.253.228:12309/gateway/scan", formData.Url())
|
||||||
|
|
||||||
result, _ := io.ReadAll(res.Body)
|
result, _ := io.ReadAll(res.Body)
|
||||||
fmt.Println(string(result))
|
fmt.Println(string(result))
|
||||||
}
|
}
|
||||||
@@ -121,11 +117,12 @@ func randomRequest(count int, stop chan int, group *sync.WaitGroup) {
|
|||||||
func main() {
|
func main() {
|
||||||
group := sync.WaitGroup{}
|
group := sync.WaitGroup{}
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
stop := make(chan int, 100)
|
stop := make(chan int, 10)
|
||||||
for i := 1; i < int(math.Pow10(3)); i++ {
|
client := http.Client{}
|
||||||
|
for i := 1; i < int(math.Pow10(2)); i++ {
|
||||||
group.Add(1)
|
group.Add(1)
|
||||||
stop <- 1
|
stop <- 1
|
||||||
go randomRequest(i, stop, &group)
|
go randomRequest(i, stop, &group, &client)
|
||||||
}
|
}
|
||||||
group.Wait()
|
group.Wait()
|
||||||
fmt.Println("总耗时", time.Since(startTime).Seconds())
|
fmt.Println("总耗时", time.Since(startTime).Seconds())
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ type Data struct {
|
|||||||
PayKey string `json:"PayKey"`
|
PayKey string `json:"PayKey"`
|
||||||
TimeStamp string `json:"timestamp"`
|
TimeStamp string `json:"timestamp"`
|
||||||
Sign string `json:"sign"`
|
Sign string `json:"sign"`
|
||||||
|
Ip string `json:"ip"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Data) Url() url.Values {
|
func (d *Data) Url() url.Values {
|
||||||
@@ -27,6 +28,7 @@ func (d *Data) Url() url.Values {
|
|||||||
"productCode": {d.ProductCode},
|
"productCode": {d.ProductCode},
|
||||||
"payKey": {d.PayKey},
|
"payKey": {d.PayKey},
|
||||||
"timestamp": {d.TimeStamp},
|
"timestamp": {d.TimeStamp},
|
||||||
|
"ip": {d.Ip},
|
||||||
"sign": {d.Sign},
|
"sign": {d.Sign},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user