diff --git a/go.mod b/go.mod index a022e1e..7252779 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,7 @@ go 1.26 require ( github.com/fsnotify/fsnotify v1.9.0 github.com/spf13/viper v1.21.0 + github.com/tidwall/gjson v1.14.2 github.com/wailsapp/wails/v2 v2.12.0 golang.org/x/sync v0.20.0 ) @@ -37,6 +38,8 @@ require ( github.com/spf13/cast v1.10.0 // indirect github.com/spf13/pflag v1.0.10 // indirect github.com/subosito/gotenv v1.6.0 // indirect + github.com/tidwall/match v1.1.1 // indirect + github.com/tidwall/pretty v1.2.0 // indirect github.com/tkrajina/go-reflector v0.5.8 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/fasttemplate v1.2.2 // indirect diff --git a/go.sum b/go.sum index e157038..167bed7 100644 --- a/go.sum +++ b/go.sum @@ -81,6 +81,12 @@ github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= +github.com/tidwall/gjson v1.14.2 h1:6BBkirS0rAHjumnjHF6qgy5d2YAJ1TLIaFE2lzfOLqo= +github.com/tidwall/gjson v1.14.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= +github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= +github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= +github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs= +github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= github.com/tkrajina/go-reflector v0.5.8 h1:yPADHrwmUbMq4RGEyaOUpz2H90sRsETNVpjzo3DLVQQ= github.com/tkrajina/go-reflector v0.5.8/go.mod h1:ECbqLgccecY5kPmPmXg1MrHW585yMcDkVl6IvJe64T4= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= diff --git a/internal/api/api.go b/internal/api/api.go index 38baf9a..7ab9eeb 100644 --- a/internal/api/api.go +++ b/internal/api/api.go @@ -7,8 +7,11 @@ import ( "io" "net/http" "net/url" + "strings" "sync" "time" + + "github.com/tidwall/gjson" ) var httpClient = &http.Client{ @@ -31,9 +34,9 @@ func init() { func InitConn() { wg := &sync.WaitGroup{} - for i := 0; i < 10; i++ { + for range 10 { wg.Go(func() { - for i := 0; i < 50; i++ { + for range 50 { resp, err := httpClient.Get(config.APPConfig.Url + "/api/test") if err != nil { fmt.Println(err) @@ -56,8 +59,19 @@ func UploadDataToServer(ctx context.Context, data string) error { <-limit }() + //根据账号是否有视频判断要存储的token params := url.Values{} - params.Set("token", config.APPConfig.Token) + secUserId := strings.Split(data, "----")[1] + hasVideo, err := CheckHasVideo(secUserId) + if err != nil { + return err + } + if hasVideo { + params.Set("token", config.APPConfig.HasVideoToken) + } else { + params.Set("token", config.APPConfig.NoVideoToken) + } + params.Set("data", data) //http://127.0.0.1:8080/api/data?token=123456&data=123456 @@ -82,3 +96,40 @@ func UploadDataToServer(ctx context.Context, data string) error { return err } + +func CheckHasVideo(secUserId string) (bool, error) { + client := &http.Client{} + req, err := http.NewRequest( + "GET", + "https://imdesktop.douyin.com/aweme/v1/web/user/profile/other/?sec_user_id="+secUserId, + nil, + ) + + if err != nil { + fmt.Println(err) + return false, err + } + req.Header.Add("User-Agent", "Apifox/1.0.0 (https://apifox.com)") + req.Header.Add("Accept", "*/*") + req.Header.Add("Host", "imdesktop.douyin.com") + req.Header.Add("Connection", "keep-alive") + + res, err := client.Do(req) + if err != nil { + fmt.Println(err) + return false, err + } + defer res.Body.Close() + + body, err := io.ReadAll(res.Body) + if err != nil { + fmt.Println(err) + return false, err + } + + if gjson.Get(string(body), "user.aweme_count").Int() > 0 { + return true, nil + } + + return false, nil +}