mirror of
https://git.oceanpay.cc/danial/kami_script.git
synced 2025-12-18 20:56:47 +00:00
chore(deps): 升级Go版本及第三方依赖库
- 将Go版本从1.20升级到1.23.0 - 添加resty客户端库github.com/go-resty/resty/v2 v2.17.0 - 升级go-nanoid库版本到v2.1.0 - 添加golang.org/x/net v0.43.0为间接依赖 - 升级testify测试库到v1.9.0 - 升级yaml.v3到v3.0.1版本 feat(main): 使用resty替代http客户端并提高请求并发 - 用resty库替代原始http.Client实现POST请求 - 修改支付网关和通知URL为测试环境地址 - 将并发请求数从10提升到100以增加负载 - 修正请求参数ProductCode为“玖隆” - 调整请求发送及结果打印逻辑以兼容resty响应结构
This commit is contained in:
108
CLAUDE.md
Normal file
108
CLAUDE.md
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
# CLAUDE.md
|
||||||
|
|
||||||
|
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
||||||
|
|
||||||
|
## Project Overview
|
||||||
|
|
||||||
|
This is a Go-based load testing script (卡密并发脚本) designed for stress testing payment gateways. The script generates concurrent requests with random card numbers and credentials to test system performance under load.
|
||||||
|
|
||||||
|
## Architecture
|
||||||
|
|
||||||
|
### Core Components
|
||||||
|
|
||||||
|
- **main.go**: Entry point containing the main concurrency logic and request generation
|
||||||
|
- **models/**: Data structures for API requests
|
||||||
|
- `model.go`: Core request data structures (`Data`, `ExValue`) with URL encoding
|
||||||
|
- `order.go`: Order parameter encryption (`OrderParams`)
|
||||||
|
- `account.go`: Account-related models
|
||||||
|
- **utils/**: Utility functions
|
||||||
|
- `enctrypt.go`: AES-CBC encryption with PKCS7 padding for sensitive data
|
||||||
|
|
||||||
|
### Key Functions
|
||||||
|
|
||||||
|
- **randomRequest()** (main.go:76): Generates individual HTTP requests with random card data
|
||||||
|
- **genSign()** (main.go:47): Creates MD5 signature for API authentication using sorted parameter concatenation
|
||||||
|
- **GenRandomCardNo()** (main.go:31): Generates random 16-digit card numbers starting with "250306"
|
||||||
|
- **GenRandomCardPass()** (main.go:39): Generates random 16-digit card passwords starting with "350610"
|
||||||
|
|
||||||
|
### Request Flow
|
||||||
|
|
||||||
|
1. Generate unique order ID using nanoid
|
||||||
|
2. Create random card number and password
|
||||||
|
3. Build request parameters with hardcoded credentials
|
||||||
|
4. Generate MD5 signature using parameter sorting and app secret
|
||||||
|
5. Send POST request to external gateway
|
||||||
|
6. Process and display response
|
||||||
|
|
||||||
|
## Development Commands
|
||||||
|
|
||||||
|
### Build and Run
|
||||||
|
```bash
|
||||||
|
# Build the application
|
||||||
|
go build -o kami_script
|
||||||
|
|
||||||
|
# Run directly
|
||||||
|
go run main.go
|
||||||
|
|
||||||
|
# Run with specific parameters if modified
|
||||||
|
go run main.go -concurrency=50 -requests=1000
|
||||||
|
```
|
||||||
|
|
||||||
|
### Testing
|
||||||
|
```bash
|
||||||
|
# Run tests (if any exist)
|
||||||
|
go test ./...
|
||||||
|
|
||||||
|
# Run with verbose output
|
||||||
|
go test -v ./...
|
||||||
|
|
||||||
|
# Check code coverage
|
||||||
|
go test -cover ./...
|
||||||
|
```
|
||||||
|
|
||||||
|
### Dependency Management
|
||||||
|
```bash
|
||||||
|
# Download dependencies
|
||||||
|
go mod download
|
||||||
|
|
||||||
|
# Tidy up go.mod
|
||||||
|
go mod tidy
|
||||||
|
|
||||||
|
# Verify dependencies
|
||||||
|
go mod verify
|
||||||
|
```
|
||||||
|
|
||||||
|
### Code Quality
|
||||||
|
```bash
|
||||||
|
# Format code
|
||||||
|
go fmt ./...
|
||||||
|
|
||||||
|
# Lint code
|
||||||
|
go vet ./...
|
||||||
|
|
||||||
|
# Check for issues
|
||||||
|
golint ./...
|
||||||
|
```
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
### Hardcoded Values
|
||||||
|
- App Secret: `"ssssc9kit6bimggos5kk0c9g"` (main.go:48)
|
||||||
|
- Pay Key: `"kkkkc9kit6bimggos5kk0c90"` (main.go:98)
|
||||||
|
- Gateway URL: `"https://gateway.oceanpay.cc/gateway/scan"` (main.go:104)
|
||||||
|
- Notify URL: `"https://shop.oceanpay.cc/shop/notify"` (main.go:97)
|
||||||
|
- AES Encryption Key: `"thisis32bitlongpassphraseimusing"` (models/order.go:24)
|
||||||
|
- AES IV: `"1234567890123456"` (models/order.go:26)
|
||||||
|
|
||||||
|
### Concurrency Settings
|
||||||
|
- Default buffer channel size: 50 (main.go:112)
|
||||||
|
- Default request count: 10^1 = 10 (main.go:113)
|
||||||
|
|
||||||
|
## Important Notes
|
||||||
|
|
||||||
|
- This script is designed for load testing purposes only
|
||||||
|
- Contains hardcoded credentials and encryption keys
|
||||||
|
- Uses goroutines with sync.WaitGroup for concurrent request handling
|
||||||
|
- Implements panic recovery in goroutines to prevent crashes
|
||||||
|
- All requests generate random card data for testing uniqueness
|
||||||
|
- Signature generation follows specific parameter sorting algorithm for API compatibility
|
||||||
9
go.mod
9
go.mod
@@ -1,5 +1,10 @@
|
|||||||
module kami_scripts
|
module kami_scripts
|
||||||
|
|
||||||
go 1.20
|
go 1.23.0
|
||||||
|
|
||||||
require github.com/matoous/go-nanoid/v2 v2.0.0
|
require (
|
||||||
|
github.com/go-resty/resty/v2 v2.17.0
|
||||||
|
github.com/matoous/go-nanoid/v2 v2.1.0
|
||||||
|
)
|
||||||
|
|
||||||
|
require golang.org/x/net v0.43.0 // indirect
|
||||||
|
|||||||
25
go.sum
25
go.sum
@@ -1,13 +1,16 @@
|
|||||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/matoous/go-nanoid v1.5.0/go.mod h1:zyD2a71IubI24efhpvkJz+ZwfwagzgSO6UNiFsZKN7U=
|
github.com/go-resty/resty/v2 v2.17.0 h1:pW9DeXcaL4Rrym4EZ8v7L19zZiIlWPg5YXAcVmt+gN0=
|
||||||
github.com/matoous/go-nanoid/v2 v2.0.0 h1:d19kur2QuLeHmJBkvYkFdhFBzLoo1XVm2GgTpL+9Tj0=
|
github.com/go-resty/resty/v2 v2.17.0/go.mod h1:kCKZ3wWmwJaNc7S29BRtUhJwy7iqmn+2mLtQrOyQlVA=
|
||||||
github.com/matoous/go-nanoid/v2 v2.0.0/go.mod h1:FtS4aGPVfEkxKxhdWPAspZpZSh1cOjtM7Ej/So3hR0g=
|
github.com/matoous/go-nanoid/v2 v2.1.0 h1:P64+dmq21hhWdtvZfEAofnvJULaRR1Yib0+PnU669bE=
|
||||||
|
github.com/matoous/go-nanoid/v2 v2.1.0/go.mod h1:KlbGNQ+FhrUNIHUxZdL63t7tl4LaPkZNpUULS8H4uVM=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||||
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
|
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
golang.org/x/net v0.43.0 h1:lat02VYK2j4aLzMzecihNvTlJNQUq316m2Mr9rnM6YE=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
golang.org/x/net v0.43.0/go.mod h1:vhO1fvI4dGsIjh73sWfUVjj3N7CA9WkKJNQm2svM6Jg=
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
golang.org/x/time v0.12.0 h1:ScB/8o8olJvc+CQPWrK3fPZNfh7qgwCrY0zJmoEQLSE=
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
golang.org/x/time v0.12.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
|||||||
16
main.go
16
main.go
@@ -5,16 +5,15 @@ import (
|
|||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"kami_scripts/models"
|
"kami_scripts/models"
|
||||||
"math"
|
"math"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net/http"
|
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/go-resty/resty/v2"
|
||||||
gonanoid "github.com/matoous/go-nanoid/v2"
|
gonanoid "github.com/matoous/go-nanoid/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -92,25 +91,24 @@ func randomRequest(count int, stop chan int, group *sync.WaitGroup) {
|
|||||||
OrderNo: id,
|
OrderNo: id,
|
||||||
OrderPeriod: strconv.Itoa(rand.Intn(24)),
|
OrderPeriod: strconv.Itoa(rand.Intn(24)),
|
||||||
OrderPrice: "10",
|
OrderPrice: "10",
|
||||||
ProductCode: "fdsu",
|
ProductCode: "玖隆",
|
||||||
Ip: "127.0.0.1",
|
Ip: "127.0.0.1",
|
||||||
NotifyUrl: "https://shop.oceanpay.cc/shop/notify",
|
NotifyUrl: "http://kami_shop:12305/shop/notify",
|
||||||
PayKey: "kkkkc9kit6bimggos5kk0c90",
|
PayKey: "kkkkc9kit6bimggos5kk0c90",
|
||||||
TimeStamp: strconv.FormatInt(time.Now().Unix(), 10),
|
TimeStamp: strconv.FormatInt(time.Now().Unix(), 10),
|
||||||
Sign: "",
|
Sign: "",
|
||||||
}
|
}
|
||||||
formData.Sign = genSign(formData)
|
formData.Sign = genSign(formData)
|
||||||
client := http.Client{}
|
client := resty.New()
|
||||||
res, _ := client.PostForm("https://gateway.oceanpay.cc/gateway/scan", formData.Url())
|
resp, _ := client.R().SetFormDataFromValues(formData.Url()).Post("http://49.233.216.171:12309/gateway/scan")
|
||||||
result, _ := io.ReadAll(res.Body)
|
fmt.Println(string(resp.Body()))
|
||||||
fmt.Println(string(result))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
group := sync.WaitGroup{}
|
group := sync.WaitGroup{}
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
stop := make(chan int, 50)
|
stop := make(chan int, 50)
|
||||||
for i := 0; i < int(math.Pow10(1)); i++ {
|
for i := 0; 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)
|
||||||
|
|||||||
Reference in New Issue
Block a user