- 添加了 gjson 库用于解析 JSON 数据 - 修改循环语法从传统的 for i := 0; i < n; i++ 到 range 语法 - 实现了 CheckHasVideo 函数来检查用户是否有视频作品 - 根据用户是否有视频动态选择 HasVideoToken 或 NoVideoToken - 添加了新的 HTTP 请求头配置用于 API 调用 - 更新了依赖包并添加了相关间接依赖
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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=
|
||||
|
||||
+54
-3
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user