73 lines
1.4 KiB
Go
73 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"flash/core"
|
|
"fmt"
|
|
"math/rand"
|
|
"os"
|
|
"sync"
|
|
"time"
|
|
)
|
|
|
|
// Conf 配置文件
|
|
type Conf struct {
|
|
Tokens []string `json:"tokens"`
|
|
ActivityId int `json:"activityId"`
|
|
TotalCost float64 `json:"totalCost"`
|
|
GroupId int `json:"groupId"`
|
|
}
|
|
|
|
var conf Conf
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
//var queue = make(chan *app.PushData)
|
|
//var resultCh = make(chan *app.Result)
|
|
|
|
func Task() {
|
|
for _, token := range conf.Tokens {
|
|
wg.Add(1)
|
|
go func(token string) {
|
|
defer wg.Done()
|
|
delay := time.Duration(rand.Intn(2)+5) * time.Second // 随机延迟2到3秒
|
|
time.Sleep(delay)
|
|
postData := &core.PostStruct{
|
|
PayAmount: conf.TotalCost,
|
|
ActivityID: conf.ActivityId,
|
|
MaleCount: 0,
|
|
FemaleCount: 0,
|
|
PayType: 3,
|
|
GroupID: conf.GroupId,
|
|
XbSex: nil,
|
|
CardType: 0,
|
|
}
|
|
core.Headers["X-Access-Token"] = token
|
|
fmt.Println(core.JsonToString(postData), token)
|
|
s, e := core.ApiRequest(core.ApiUrl, core.Headers, postData)
|
|
fmt.Println(s, e)
|
|
}(token)
|
|
}
|
|
wg.Wait()
|
|
}
|
|
func main() {
|
|
|
|
p := "config.json"
|
|
f, err := os.ReadFile(p)
|
|
if err != nil {
|
|
fmt.Printf("载入配置文件出错, 错误: %v", err)
|
|
os.Exit(-1)
|
|
}
|
|
err = json.Unmarshal(f, &conf)
|
|
if nil != err {
|
|
fmt.Printf("解析配置文件内容出错, 错误: %v", err)
|
|
os.Exit(-1)
|
|
}
|
|
rand.New(rand.NewSource(time.Now().UnixNano()))
|
|
Task()
|
|
//core.CronRegister("0 12 * * * ?", Task)
|
|
core.CronRun()
|
|
select {}
|
|
|
|
}
|