init
This commit is contained in:
8
.idea/.gitignore
generated
vendored
Normal file
8
.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
# 默认忽略的文件
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# 基于编辑器的 HTTP 客户端请求
|
||||||
|
/httpRequests/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
||||||
9
.idea/flash.iml
generated
Normal file
9
.idea/flash.iml
generated
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="WEB_MODULE" version="4">
|
||||||
|
<component name="Go" enabled="true" />
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$" />
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/flash.iml" filepath="$PROJECT_DIR$/.idea/flash.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
12
config.json
Normal file
12
config.json
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"tokens": [
|
||||||
|
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJjdXN0b21QYXJhbWV0ZXIiOiJxd2VyMTIzNCIsImV4cCI6MTcyMjgzMDE0NSwidXNlcklkIjo4MDU4NDJ9.n3cXJCJNqEpHWoamv3nG-8rrnRPkD44TOqZamzEDFgU",
|
||||||
|
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJjdXN0b21QYXJhbWV0ZXIiOiJxd2VyMTIzNCIsImV4cCI6MTcyMjgyOTkzOSwidXNlcklkIjoxMDU1NzgwfQ.CpMhGx0uWDOJe2xCeqQ_zDyxkelGTsIoUQs3J0aH0aw",
|
||||||
|
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJjdXN0b21QYXJhbWV0ZXIiOiJxd2VyMTIzNCIsImV4cCI6MTcyMjgyOTc3MiwidXNlcklkIjo3OTg2NTJ9.9aTj_LiugdKptbErvGoeLYBvg8x9HZLl6fUWPrKFJ6o",
|
||||||
|
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJjdXN0b21QYXJhbWV0ZXIiOiJxd2VyMTIzNCIsImV4cCI6MTcyMzQzNDg3MywidXNlcklkIjozNTk4NDl9.5J0mQzAXIDW6uWQ9gUdbEN26y9Tx9WpU30pAZrwrqqk"
|
||||||
|
],
|
||||||
|
"activityId": 748226,
|
||||||
|
"totalCost": 23.5,
|
||||||
|
"groupId": 1251763
|
||||||
|
}
|
||||||
|
|
||||||
62
core/crontab.go
Normal file
62
core/crontab.go
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
package core
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/robfig/cron"
|
||||||
|
)
|
||||||
|
|
||||||
|
var CronInfo CronServiceInfo
|
||||||
|
|
||||||
|
type CronServiceInfo struct {
|
||||||
|
Cron []string
|
||||||
|
Func []func()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *CronServiceInfo) Register(cron string, f func()) {
|
||||||
|
c.Cron = append(c.Cron, cron)
|
||||||
|
c.Func = append(c.Func, f)
|
||||||
|
}
|
||||||
|
|
||||||
|
func CronRun() {
|
||||||
|
c := cron.New()
|
||||||
|
for k, v := range CronInfo.Cron {
|
||||||
|
err := c.AddFunc(v, wrap(CronInfo.Func[k]))
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("定时任务添加失败")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
c.Start()
|
||||||
|
}
|
||||||
|
|
||||||
|
func wrap(f func()) func() {
|
||||||
|
return func() {
|
||||||
|
//defer CronRecovery(runtime.FuncForPC(reflect.ValueOf(f).Pointer()).Name())
|
||||||
|
f()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func CronRegister(rule string, f func()) {
|
||||||
|
CronInfo.Register(rule, f)
|
||||||
|
}
|
||||||
|
|
||||||
|
//func CronRecovery(name string){
|
||||||
|
// if err := recover(); err != nil {
|
||||||
|
// var code int
|
||||||
|
// var msg interface{}
|
||||||
|
// if h, ok := err.(*Exception); ok {
|
||||||
|
// code = h.Code
|
||||||
|
// msg = h.Msg
|
||||||
|
// } else if _, ok = err.(error); ok {
|
||||||
|
// msg = "未知错误"
|
||||||
|
// code = UNKNOW_ERROR
|
||||||
|
// } else {
|
||||||
|
// msg = "服务器错误"
|
||||||
|
// code = SERVER_ERROR
|
||||||
|
// }
|
||||||
|
// Log.WithFields(map[string]interface{}{
|
||||||
|
// "code":code,
|
||||||
|
// "model":"task",
|
||||||
|
// "func":name,
|
||||||
|
// }).Error(msg)
|
||||||
|
// }
|
||||||
|
//}
|
||||||
85
core/http.go
Normal file
85
core/http.go
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
package core
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"compress/gzip"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
var ApiUrl = "https://www.shuote.top:8082/flash/activity/applyActivity"
|
||||||
|
var Headers = map[string]string{
|
||||||
|
"Host": "www.shuote.top:8082",
|
||||||
|
"Connection": "keep-alive",
|
||||||
|
"Request-Channel": "MP-WEIXIN",
|
||||||
|
"X-Access-Token": "",
|
||||||
|
"Accept-Encoding": "gzip,compress,br,deflate",
|
||||||
|
"User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 17_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/8.0.49(0x18003137) NetType/WIFI Language/zh_CN",
|
||||||
|
"Referer": "https://servicewechat.com/wxbb50595cab69d719/403/page-frame.html",
|
||||||
|
}
|
||||||
|
|
||||||
|
// PostStruct 结构
|
||||||
|
type PostStruct struct {
|
||||||
|
PayAmount float64 `json:"payAmount"`
|
||||||
|
ActivityID int `json:"activityId"`
|
||||||
|
MaleCount int `json:"maleCount"`
|
||||||
|
FemaleCount int `json:"femaleCount"`
|
||||||
|
PayType int `json:"payType"`
|
||||||
|
GroupID int `json:"groupId"`
|
||||||
|
XbSex any `json:"xbSex"`
|
||||||
|
CardType int `json:"cardType"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func ApiRequest(url string, customHeaders map[string]string, postData *PostStruct) (string, error) {
|
||||||
|
if url == "" {
|
||||||
|
return "", fmt.Errorf("URL is empty")
|
||||||
|
}
|
||||||
|
jsonData, err := json.Marshal(postData)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
client := &http.Client{
|
||||||
|
Timeout: 30 * time.Second,
|
||||||
|
}
|
||||||
|
req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
// 设置默认请求头
|
||||||
|
req.Header.Set("Content-Type", "application/json")
|
||||||
|
req.Header.Set("Content-Length", fmt.Sprintf("%d", len(jsonData)))
|
||||||
|
|
||||||
|
// 如果有自定义请求头,则设置请求头
|
||||||
|
for key, value := range customHeaders {
|
||||||
|
req.Header.Set(key, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置Accept-Encoding以接收压缩响应
|
||||||
|
req.Header.Set("Accept-Encoding", "gzip")
|
||||||
|
|
||||||
|
resp, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
var reader io.ReadCloser
|
||||||
|
switch resp.Header.Get("Content-Encoding") {
|
||||||
|
case "gzip":
|
||||||
|
reader, err = gzip.NewReader(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
defer reader.Close()
|
||||||
|
default:
|
||||||
|
reader = resp.Body
|
||||||
|
}
|
||||||
|
responseBytes, err := io.ReadAll(reader)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return string(responseBytes), nil
|
||||||
|
}
|
||||||
13
core/json.go
Normal file
13
core/json.go
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
package core
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
)
|
||||||
|
|
||||||
|
func JsonToString(postData interface{}) string {
|
||||||
|
jsons, errs := json.Marshal(postData) //转换成JSON返回的是byte[]
|
||||||
|
if errs != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return string(jsons)
|
||||||
|
}
|
||||||
5
go.mod
Normal file
5
go.mod
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
module flash
|
||||||
|
|
||||||
|
go 1.22
|
||||||
|
|
||||||
|
require github.com/robfig/cron v1.2.0
|
||||||
2
go.sum
Normal file
2
go.sum
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
github.com/robfig/cron v1.2.0 h1:ZjScXvvxeQ63Dbyxy76Fj3AT3Ut0aKsyd2/tl3DTMuQ=
|
||||||
|
github.com/robfig/cron v1.2.0/go.mod h1:JGuDeoQd7Z6yL4zQhZ3OPEVHB7fL6Ka6skscFHfmt2k=
|
||||||
72
main.go
Normal file
72
main.go
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
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 {}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user