feat(api): 添加 accountId 字段并更新相关逻辑

- 在 SubmitModal 结构体中添加 AccountId 字段
- 更新 queryAPI 函数返回值,增加 AccountId
- 修改 SubmitAPI 函数,接收 AccountId 参数
- 在自动处理和随机处理逻辑中集成 AccountId- 更新配置文件,替换 API地址
This commit is contained in:
danial
2025-02-11 22:28:37 +08:00
parent c8ca6b69a5
commit a365e7fb9f
4 changed files with 31 additions and 25 deletions

View File

@@ -10,6 +10,7 @@ import (
)
type SubmitModal struct {
AccountId string `json:"accountId"`
Amount string `json:"amount"`
OrderNo string `json:"orderNo"`
Status string `json:"status"`
@@ -32,10 +33,11 @@ func SubmitToAPI(host string, m SubmitModal) {
"remark": m.Remark,
"accountAmount": m.AccountAmount,
"sign": "123456",
"accountId": m.AccountId,
}
client := &http.Client{}
js, err := json.MarshalIndent(&formData, "", "\t")
req, err := http.NewRequest("POST", fmt.Sprintf("%s/api/cardInfo/appleCard/rechargeOrder/callback", host), bytes.NewBuffer(js))
js, _ := json.MarshalIndent(&formData, "", "\t")
req, _ := http.NewRequest("POST", fmt.Sprintf("%s/api/cardInfo/appleCard/rechargeOrder/callback", host), bytes.NewBuffer(js))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("tokenFrom", "iframe")
response, err := client.Do(req)

View File

@@ -1,2 +1,2 @@
http://121.37.253.228:12309 http://121.37.253.228:12401
http://127.0.0.1:12309 http://127.0.0.1:8000
https://gateway.kkknametrans.buzz https://partial.kkknametrans.buzz
http://127.0.0.1:12309 http://127.0.0.1:12401

View File

@@ -60,7 +60,7 @@ func Queue(host *models.Host, count int) {
func QueueWithOrder(host *models.Host, count int) {
totalAmount := 0
totalAllowedAmount := []int{100, 200, 500}
totalAllowedAmount := []int{100}
for i := range count {
o := models.Order{
Count: count,

View File

@@ -8,13 +8,14 @@ import (
"demo/utils"
"encoding/json"
"fmt"
"github.com/gogf/gf/v2/text/gstr"
"io"
"math/rand"
"net/http"
"strconv"
"sync"
"time"
"github.com/gogf/gf/v2/text/gstr"
)
type AccountResponse struct {
@@ -22,15 +23,16 @@ type AccountResponse struct {
//Code int `json:"code"`
Status int `json:"status"`
Data struct {
Account string `json:"account"`
Password string `json:"password"`
OrderNo string `json:"orderNo"`
CardNo string `json:"cardNo"`
CardPass string `json:"cardPass"`
Account string `json:"account"`
Password string `json:"password"`
OrderNo string `json:"orderNo"`
CardNo string `json:"cardNo"`
CardPass string `json:"cardPass"`
AccountId string `json:"accountId"`
} `json:"data"`
}
func queryAPI(host string) string {
func queryAPI(host string) (string, string) {
client := &http.Client{}
queryData := map[string][]string{
"machineID": {"123456"},
@@ -46,28 +48,27 @@ func queryAPI(host string) string {
response, err := client.Do(req)
if err != nil {
fmt.Println("获取数据出错", err)
return ""
return "", ""
}
defer response.Body.Close()
b, err := io.ReadAll(response.Body)
if err != nil {
fmt.Println("读取数据出错", err)
return ""
return "", ""
}
fmt.Println("查询结果:", string(b))
res := AccountResponse{}
err = json.Unmarshal(b, &res)
if err != nil {
fmt.Println("解析数据出错", err)
return ""
return "", ""
}
content := fmt.Sprintf("账号:%s\n密码%s\n订单号%s\n卡密%s", res.Data.Account, res.Data.Password, res.Data.OrderNo, res.Data.CardPass)
fmt.Println(content)
utils.WriteContent(content)
return res.Data.OrderNo
return res.Data.OrderNo, res.Data.AccountId
}
func SubmitAPI(orderNo string, host string) {
func SubmitAPI(orderNo string, accountId string, host string) {
fmt.Println("\n状态1.兑换成功 2.账号密码错误 11.兑换失败(卡密无效) 12.充值失败(卡密已兑换) 3.退回订单不作处理")
fmt.Print("请输入状态:")
var status string
@@ -105,6 +106,7 @@ func SubmitAPI(orderNo string, host string) {
_, _ = fmt.Scanln(&amountAfter)
}
api.SubmitToAPI(host, api.SubmitModal{
AccountId: accountId,
AccountAmount: amountAfter,
Amount: amount,
OrderNo: orderNo_,
@@ -129,18 +131,18 @@ func Manual(host string, count int) {
orderNo_ := ""
fmt.Print("请输入订单号:")
_, _ = fmt.Scanln(&orderNo_)
SubmitAPI(orderNo_, host)
SubmitAPI(orderNo_, "", host)
case 3:
orderNo := queryAPI(host)
orderNo, accountId := queryAPI(host)
if orderNo == "" {
fmt.Println("订单号获取失败,当前没有需要处理的订单")
}
SubmitAPI(orderNo, host)
SubmitAPI(orderNo, accountId, host)
case 4:
orderNo := ""
fmt.Print("请输入订单号:")
_, _ = fmt.Scanln(&orderNo)
SubmitAPI(gstr.Trim(orderNo), host)
SubmitAPI(gstr.Trim(orderNo), "", host)
case 0:
fmt.Println("退出成功")
return
@@ -154,7 +156,7 @@ func Manual(host string, count int) {
// Consumption 自动处理
func Consumption(host string, o models.Order) {
group := sync.WaitGroup{}
stop := make(chan bool, 10)
stop := make(chan bool, 100)
totalAmount := 0
for i := 0; i < o.Count; i++ {
group.Add(1)
@@ -164,12 +166,13 @@ func Consumption(host string, o models.Order) {
<-stop1
group1.Done()
}()
orderNo := queryAPI(host)
orderNo, accountId := queryAPI(host)
if orderNo == "" {
fmt.Println("订单号获取失败,当前没有需要处理的订单")
}
totalAmount += o.Amount
api.SubmitToAPI(host, api.SubmitModal{
AccountId: accountId,
AccountAmount: strconv.Itoa(totalAmount),
Amount: strconv.Itoa(o.Amount),
OrderNo: orderNo,
@@ -206,8 +209,9 @@ func ConsumptionOne(host string, o models.Order, randomStatus bool, diff bool) (
}
}
//从status中随机挑选一个
orderNo := queryAPI(host)
orderNo, accountId := queryAPI(host)
api.SubmitToAPI(host, api.SubmitModal{
AccountId: accountId,
AccountAmount: strconv.Itoa(o.AmountAfter),
Amount: strconv.Itoa(o.Amount),
OrderNo: orderNo,