feat: 提交正确程序

This commit is contained in:
孙晓龙
2024-07-09 14:32:27 +08:00
parent c44e8dd6b6
commit 06e67e9b7d
5 changed files with 50 additions and 28 deletions

View File

@@ -1,2 +1,2 @@
http://121.37.253.228:12401
http://121.37.253.228:12309 http://121.37.253.228:12401
http://127.0.0.1:8000

View File

@@ -58,10 +58,11 @@ func Queue(host *models.Host, count int) {
func QueueWithOrder(host *models.Host, count int) {
totalAmount := 0
totalAllowedAmount := []int{68, 100, 200, 500}
for i := range count {
o := models.Order{
Count: count,
Amount: rand.Intn(100) + 100,
Amount: totalAllowedAmount[rand.Intn(len(totalAllowedAmount))],
}
totalAmount += o.Amount
o.AmountAfter = totalAmount

View File

@@ -10,12 +10,12 @@ type Data struct {
OrderNo string `json:"orderNo"`
OrderPeriod string `json:"orderPeriod"`
OrderPrice string `json:"orderPrice"`
PayWayCode string `json:"payWayCode"`
OsType string `json:"osType"`
ProductCode string `json:"productCode"`
NotifyUrl string `json:"notifyUrl"`
AppKey string `json:"payKey"`
PayKey string `json:"PayKey"`
TimeStamp string `json:"timestamp"`
Sign string `json:"sign"`
Ip string `json:"ip"`
}
func (d *Data) Url() url.Values {
@@ -24,11 +24,11 @@ func (d *Data) Url() url.Values {
"orderNo": {d.OrderNo},
"orderPeriod": {d.OrderPeriod},
"orderPrice": {d.OrderPrice},
"payWayCode": {d.PayWayCode},
"osType": {d.OsType},
"notifyUrl": {d.NotifyUrl},
"payKey": {d.AppKey},
"productCode": {d.ProductCode},
"payKey": {d.PayKey},
"timestamp": {d.TimeStamp},
"ip": {d.Ip},
"sign": {d.Sign},
}
}

View File

@@ -2,6 +2,7 @@ package queue
import (
"bytes"
"context"
"demo/api"
"demo/models"
"demo/utils"
@@ -12,6 +13,7 @@ import (
"net/http"
"strconv"
"sync"
"time"
"github.com/gogf/gf/v2/text/gstr"
)
@@ -31,14 +33,16 @@ type AccountResponse struct {
func queryAPI(host string) string {
client := &http.Client{}
queryData := map[string][]string{
"machineID": {"123456"},
}
js, err := json.MarshalIndent(&queryData, "", "\t")
js, _ := json.MarshalIndent(&queryData, "", "\t")
req, _ := http.NewRequest("POST", fmt.Sprintf("%s/api/cardInfo/appleCard/rechargeOrder/handler", host), bytes.NewBuffer(js))
req.Header.Set("tokenFrom", "iframe")
req.Header.Set("accept", "*/*")
ctx, cancel := context.WithTimeout(req.Context(), time.Second*5)
defer cancel()
req = req.WithContext(ctx)
req.Header.Set("content-type", "application/json")
response, err := client.Do(req)
if err != nil {
@@ -69,7 +73,6 @@ func SubmitAPI(orderNo string, host string) {
fmt.Print("请输入状态:")
var status string
_, _ = fmt.Scanln(&status)
var orderNo_ string
if orderNo == "" {
fmt.Print("请输入订单号:")
@@ -157,7 +160,7 @@ func Consumption(host string, o models.Order) {
for i := 0; i < o.Count; i++ {
group.Add(1)
stop <- true
func(stop1 chan bool, group1 *sync.WaitGroup) {
go func(stop1 chan bool, group1 *sync.WaitGroup) {
defer func() {
<-stop1
group1.Done()

View File

@@ -17,6 +17,7 @@ import (
gonanoid "github.com/matoous/go-nanoid/v2"
)
// SortMap 对map的key值进行排序
// SortMap 对map的key值进行排序
func SortMap(m map[string]string) []string {
var arr []string
@@ -27,6 +28,24 @@ func SortMap(m map[string]string) []string {
return arr
}
func GenRandomCardNo() string {
return ""
// cardNo := "X"
// for i := 0; i < 15; i++ {
// cardNo += strconv.Itoa(rand.Intn(10))
// }
// return cardNo
}
func GenRandomCardPass() string {
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{}
@@ -35,12 +54,11 @@ func genSign(data models.Data) string {
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
params["payKey"] = data.PayKey
params["ip"] = data.Ip
params["productCode"] = data.ProductCode
strArr := SortMap(params)
signStr := ""
for i := 0; i < len(strArr); i++ {
@@ -52,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(host string, order models.Order, stop chan int, group *sync.WaitGroup) {
func randomRequest(host string, o models.Order, stop chan int, group *sync.WaitGroup) {
defer func() {
<-stop
group.Done()
@@ -66,23 +83,23 @@ func randomRequest(host string, order models.Order, stop chan int, group *sync.W
fmt.Println(err)
}
}()
fmt.Println("正在发送请求次数", order.Count)
id, _ := gonanoid.New()
client := http.Client{}
fmt.Println("正在发送请求次数", o.Count)
id, _ := gonanoid.New()
formData := models.Data{
ExValue: models.ExValue{
Data: "333333333333333",
Data: GenRandomCardPass(),
FaceType: "100",
CardNo: "1233333333",
CardNo: GenRandomCardNo(),
RecoveryType: "8",
},
OrderNo: id,
OrderPeriod: strconv.Itoa(rand.Intn(24)),
OrderPrice: strconv.Itoa(order.Amount),
PayWayCode: "CARD_DH",
OsType: "1",
ProductCode: "8546",
OrderPrice: strconv.Itoa(o.Amount),
Ip: "127.0.0.1",
NotifyUrl: "https://baidu.com",
AppKey: "kkkkc9kit6bimggos5kk0c90",
PayKey: "kkkkc9kit6bimggos5kk0c90",
TimeStamp: strconv.FormatInt(time.Now().Unix(), 10),
Sign: "",
}
@@ -106,8 +123,9 @@ func Production(host string, o models.Order) {
func ProductionOne(host string, o models.Order) {
group := sync.WaitGroup{}
stop := make(chan int, 50)
stop := make(chan int, 10)
group.Add(1)
randomRequest(host, o, stop, &group)
stop <- 1
go randomRequest(host, o, stop, &group)
group.Wait()
}