初次提交

This commit is contained in:
sunxiaolong
2023-12-10 22:39:16 +08:00
commit b36783ac34
7 changed files with 248 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/.idea

8
go.mod Normal file
View File

@@ -0,0 +1,8 @@
module kami_scripts
go 1.20
require (
github.com/matoous/go-nanoid/v2 v2.0.0 // indirect
github.com/rs/xid v1.5.0 // indirect
)

12
go.sum Normal file
View File

@@ -0,0 +1,12 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/matoous/go-nanoid v1.5.0 h1:VRorl6uCngneC4oUQqOYtO3S0H5QKFtKuKycFG3euek=
github.com/matoous/go-nanoid v1.5.0/go.mod h1:zyD2a71IubI24efhpvkJz+ZwfwagzgSO6UNiFsZKN7U=
github.com/matoous/go-nanoid/v2 v2.0.0 h1:d19kur2QuLeHmJBkvYkFdhFBzLoo1XVm2GgTpL+9Tj0=
github.com/matoous/go-nanoid/v2 v2.0.0/go.mod h1:FtS4aGPVfEkxKxhdWPAspZpZSh1cOjtM7Ej/So3hR0g=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rs/xid v1.5.0 h1:mKX4bl4iPYJtEIxp6CYiUuLQ/8DYMoz0PUdtGgMFRVc=
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

110
main.go Normal file
View File

@@ -0,0 +1,110 @@
package main
import (
"crypto/md5"
"encoding/hex"
"encoding/json"
"fmt"
gonanoid "github.com/matoous/go-nanoid/v2"
"io"
"kami_scripts/models"
"math"
"math/rand"
"net/http"
"sort"
"strconv"
"sync"
"time"
)
// SortMap 对map的key值进行排序
func SortMap(m map[string]string) []string {
var arr []string
for k := range m {
arr = append(arr, k)
}
sort.Strings(arr)
return arr
}
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
params["orderPrice"] = data.OrderPrice
params["payWayCode"] = data.PayWayCode
params["osType"] = data.OsType
params["notifyUrl"] = data.NotifyUrl
params["payKey"] = data.AppKey
params["timestamp"] = data.TimeStamp
strArr := SortMap(params)
signStr := ""
for i := 0; i < len(strArr); i++ {
k := strArr[i]
if len(params[k]) == 0 {
signStr += k
} else {
signStr += k + params[k]
}
}
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) {
defer func() {
time.Sleep(time.Second * 2)
<-stop
group.Done()
if err := recover(); err != nil {
fmt.Println(err)
}
}()
fmt.Println("正在发送请求次数", count)
id, _ := gonanoid.New()
client := http.Client{}
formData := models.Data{
ExValue: models.ExValue{
Data: "333333333333333",
FaceType: "100",
CardNo: "1233333333",
RecoveryType: "8",
},
OrderNo: id,
OrderPeriod: strconv.Itoa(rand.Intn(24)),
OrderPrice: "100",
PayWayCode: "CARD_DH",
OsType: "1",
NotifyUrl: "https://baidu.com",
AppKey: "kkkkc9kit6bimggos5kk0c90",
TimeStamp: strconv.FormatInt(time.Now().Unix(), 10),
Sign: "",
}
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))
}
func main() {
group := sync.WaitGroup{}
stop := make(chan int, 50)
for i := 1; i < int(math.Pow10(5)); i++ {
group.Add(1)
stop <- 1
go randomRequest(i, stop, &group)
}
group.Wait()
}

46
models/model.go Normal file
View File

@@ -0,0 +1,46 @@
package models
import (
"encoding/json"
"net/url"
)
type Data struct {
ExValue ExValue `json:"exValue"`
OrderNo string `json:"orderNo"`
OrderPeriod string `json:"orderPeriod"`
OrderPrice string `json:"orderPrice"`
PayWayCode string `json:"payWayCode"`
OsType string `json:"osType"`
NotifyUrl string `json:"notifyUrl"`
AppKey string `json:"payKey"`
TimeStamp string `json:"timestamp"`
Sign string `json:"sign"`
}
func (d *Data) Url() url.Values {
return url.Values{
"exValue": {d.ExValue.Json()},
"orderNo": {d.OrderNo},
"orderPeriod": {d.OrderPeriod},
"orderPrice": {d.OrderPrice},
"payWayCode": {d.PayWayCode},
"osType": {d.OsType},
"notifyUrl": {d.NotifyUrl},
"payKey": {d.AppKey},
"timestamp": {d.TimeStamp},
"sign": {d.Sign},
}
}
type ExValue struct {
Data string `json:"data"`
CardNo string `json:"cardNo"`
FaceType string `json:"faceType"`
RecoveryType string `json:"recoveryType"`
}
func (v *ExValue) Json() string {
data, _ := json.Marshal(v)
return string(data)
}

39
models/order.go Normal file
View File

@@ -0,0 +1,39 @@
package models
import (
"encoding/hex"
"encoding/json"
"kami_scripts/utils"
"time"
)
type OrderParams struct {
PayKey string `json:"payKey"` // 支付明文秘钥
GeneratedTime time.Time `json:"generatedTime"` // 过期时间
Duration int `json:"duration"` // 存续时间(小时)
}
func (p *OrderParams) Encrypt() string {
prepareData := p.String()
if prepareData == "" {
return prepareData
}
// 加密密码数据
key := "thisis32bitlongpassphraseimusing"
iv := "1234567890123456"
result, _ := utils.AesCBCEncrypt([]byte(prepareData), []byte(key), []byte(iv))
return hex.EncodeToString(result)
}
func (p *OrderParams) String() string {
r, err := json.Marshal(p)
if err != nil {
return ""
}
return string(r)
}

32
utils/enctrypt.go Normal file
View File

@@ -0,0 +1,32 @@
package utils
import (
"bytes"
"crypto/aes"
"crypto/cipher"
)
// AesCBCEncrypt AES/CBC/PKCS7Padding 加密
func AesCBCEncrypt(plaintext []byte, key []byte, iv []byte) ([]byte, error) {
// AES
block, err := aes.NewCipher(key)
if err != nil {
panic(err)
}
// PKCS7 填充
plaintext = paddingPKCS7(plaintext, aes.BlockSize)
// CBC 加密
mode := cipher.NewCBCEncrypter(block, iv)
mode.CryptBlocks(plaintext, plaintext)
return plaintext, nil
}
// PKCS7 填充
func paddingPKCS7(plaintext []byte, blockSize int) []byte {
paddingSize := blockSize - len(plaintext)%blockSize
paddingText := bytes.Repeat([]byte{byte(paddingSize)}, paddingSize)
return append(plaintext, paddingText...)
}