package main import ( "encoding/json" "fmt" "github.com/spf13/cast" "github.com/tealeg/xlsx" "io/ioutil" "net/http" "time" ) type ActRankData struct { Code int `json:"code,omitempty"` Message string `json:"message,omitempty"` MessageData any `json:"messageData,omitempty"` OperationMessage string `json:"operationMessage,omitempty"` Data struct { Top3 []struct { ID int `json:"id,omitempty"` CreatedTime time.Time `json:"createdTime,omitempty"` UpdatedTime time.Time `json:"updatedTime,omitempty"` ExternalID string `json:"externalId,omitempty"` Avatar string `json:"avatar,omitempty"` DefaultAvatar bool `json:"defaultAvatar,omitempty"` Nick string `json:"nick,omitempty"` Sex int `json:"sex,omitempty"` Birthday int `json:"birthday,omitempty"` Country string `json:"country,omitempty"` CountryIcon string `json:"countryIcon,omitempty"` Language string `json:"language,omitempty"` Description string `json:"description,omitempty"` Code string `json:"code,omitempty"` OriginCode string `json:"originCode,omitempty"` IsPush int `json:"isPush,omitempty"` IsShowAge int `json:"isShowAge,omitempty"` Status int `json:"status,omitempty"` DeviceType string `json:"deviceType,omitempty"` LogoutTime int `json:"logoutTime,omitempty"` MaskNick string `json:"maskNick,omitempty"` MaskAvatar string `json:"maskAvatar,omitempty"` CountryID bool `json:"countryId,omitempty"` IsRealCertification int `json:"isRealCertification,omitempty"` Rank int `json:"Rank,omitempty"` Score int `json:"Score,omitempty"` User2 struct { ID int `json:"id,omitempty"` CreatedTime time.Time `json:"createdTime,omitempty"` UpdatedTime time.Time `json:"updatedTime,omitempty"` ExternalID string `json:"externalId,omitempty"` Avatar string `json:"avatar,omitempty"` DefaultAvatar bool `json:"defaultAvatar,omitempty"` Nick string `json:"nick,omitempty"` Sex int `json:"sex,omitempty"` Birthday int `json:"birthday,omitempty"` Country string `json:"country,omitempty"` CountryIcon string `json:"countryIcon,omitempty"` Language string `json:"language,omitempty"` Description string `json:"description,omitempty"` Code string `json:"code,omitempty"` OriginCode string `json:"originCode,omitempty"` IsPush int `json:"isPush,omitempty"` IsShowAge int `json:"isShowAge,omitempty"` Status int `json:"status,omitempty"` DeviceType string `json:"deviceType,omitempty"` LogoutTime int `json:"logoutTime,omitempty"` MaskNick string `json:"maskNick,omitempty"` MaskAvatar string `json:"maskAvatar,omitempty"` CountryID bool `json:"countryId,omitempty"` IsRealCertification int `json:"isRealCertification,omitempty"` } `json:"User2,omitempty"` Supporter any `json:"supporter,omitempty"` Family any `json:"Family,omitempty"` TodayScore int `json:"TodayScore,omitempty"` Today string `json:"Today,omitempty"` } `json:"top3,omitempty"` List []struct { ID int `json:"id,omitempty"` CreatedTime time.Time `json:"createdTime,omitempty"` UpdatedTime time.Time `json:"updatedTime,omitempty"` ExternalID string `json:"externalId,omitempty"` Avatar string `json:"avatar,omitempty"` DefaultAvatar bool `json:"defaultAvatar,omitempty"` Nick string `json:"nick,omitempty"` Sex int `json:"sex,omitempty"` Birthday int `json:"birthday,omitempty"` Country string `json:"country,omitempty"` CountryIcon string `json:"countryIcon,omitempty"` Language string `json:"language,omitempty"` Description string `json:"description,omitempty"` Code string `json:"code,omitempty"` OriginCode string `json:"originCode,omitempty"` IsPush int `json:"isPush,omitempty"` IsShowAge int `json:"isShowAge,omitempty"` Status int `json:"status,omitempty"` DeviceType string `json:"deviceType,omitempty"` LogoutTime int `json:"logoutTime,omitempty"` MaskNick string `json:"maskNick,omitempty"` MaskAvatar string `json:"maskAvatar,omitempty"` CountryID bool `json:"countryId,omitempty"` IsRealCertification int `json:"isRealCertification,omitempty"` Rank int `json:"Rank,omitempty"` Score int `json:"Score,omitempty"` User2 struct { ID int `json:"id,omitempty"` CreatedTime time.Time `json:"createdTime,omitempty"` UpdatedTime time.Time `json:"updatedTime,omitempty"` ExternalID string `json:"externalId,omitempty"` Avatar string `json:"avatar,omitempty"` DefaultAvatar bool `json:"defaultAvatar,omitempty"` Nick string `json:"nick,omitempty"` Sex int `json:"sex,omitempty"` Birthday int `json:"birthday,omitempty"` Country string `json:"country,omitempty"` CountryIcon string `json:"countryIcon,omitempty"` Language string `json:"language,omitempty"` Description string `json:"description,omitempty"` Code string `json:"code,omitempty"` OriginCode string `json:"originCode,omitempty"` IsPush int `json:"isPush,omitempty"` IsShowAge int `json:"isShowAge,omitempty"` Status int `json:"status,omitempty"` DeviceType string `json:"deviceType,omitempty"` LogoutTime int `json:"logoutTime,omitempty"` MaskNick string `json:"maskNick,omitempty"` MaskAvatar string `json:"maskAvatar,omitempty"` CountryID bool `json:"countryId,omitempty"` IsRealCertification int `json:"isRealCertification,omitempty"` } `json:"User2,omitempty"` Supporter any `json:"supporter,omitempty"` Family any `json:"Family,omitempty"` TodayScore int `json:"TodayScore,omitempty"` Today string `json:"Today,omitempty"` } `json:"List,omitempty"` OrdinaryTop5 any `json:"OrdinaryTop5,omitempty"` Mine struct { ID int `json:"id,omitempty"` CreatedTime time.Time `json:"createdTime,omitempty"` UpdatedTime time.Time `json:"updatedTime,omitempty"` ExternalID string `json:"externalId,omitempty"` Avatar string `json:"avatar,omitempty"` DefaultAvatar bool `json:"defaultAvatar,omitempty"` Nick string `json:"nick,omitempty"` Sex int `json:"sex,omitempty"` Birthday int `json:"birthday,omitempty"` Country string `json:"country,omitempty"` CountryIcon string `json:"countryIcon,omitempty"` Language string `json:"language,omitempty"` Description string `json:"description,omitempty"` Code string `json:"code,omitempty"` OriginCode string `json:"originCode,omitempty"` IsPush int `json:"isPush,omitempty"` IsShowAge int `json:"isShowAge,omitempty"` Status int `json:"status,omitempty"` DeviceType string `json:"deviceType,omitempty"` LogoutTime int `json:"logoutTime,omitempty"` MaskNick string `json:"maskNick,omitempty"` MaskAvatar string `json:"maskAvatar,omitempty"` CountryID bool `json:"countryId,omitempty"` IsRealCertification int `json:"isRealCertification,omitempty"` Rank int `json:"Rank,omitempty"` Score int `json:"Score,omitempty"` User2 any `json:"User2,omitempty"` Supporter any `json:"supporter,omitempty"` Family any `json:"Family,omitempty"` TodayScore int `json:"TodayScore,omitempty"` Today string `json:"Today,omitempty"` } `json:"Mine,omitempty"` TeamList any `json:"TeamList,omitempty"` Team any `json:"Team,omitempty"` MyTeam any `json:"MyTeam,omitempty"` } `json:"data,omitempty"` Edata any `json:"edata,omitempty"` } func main() { url := "https://api.hiloconn.com/v1/h5/activity/ranking?activityId=1028&rankType=4&nonce=0.9194299152147352" method := "GET" client := &http.Client{} req, err := http.NewRequest(method, url, nil) if err != nil { fmt.Println(err) return } req.Header.Add("token", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVc2VySWQiOjE3NjMyMTEsIkV4dGVybmFsSWQiOiJkYTllMTJhM2I0ZGU0YWE5Yjc2MjBlNDllYzUyMTliYyIsImV4cCI6MTcyNDU3ODA5MiwiaXNzIjoiaGlsb0FwaSJ9.zzqt1wz20MurMPYL5vvusKB8Fue3QtcHePEP5yQ18-I") req.Header.Add("nonce", "hilo") res, err := client.Do(req) if err != nil { fmt.Println(err) return } defer res.Body.Close() body, err := ioutil.ReadAll(res.Body) if err != nil { fmt.Println(err) return } rsp := new(ActRankData) if err := json.Unmarshal(body, rsp); err != nil { panic(err) } excelFileName := fmt.Sprintf("./1028-活动榜单.xlsx") xlFile := xlsx.NewFile() sheet, err := xlFile.AddSheet("data") if err != nil { panic(err) } row := sheet.AddRow() c1, c2, c3, c4 := row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell() c1.Value, c2.Value, c3.Value, c4.Value = "排名", "User1", "User2", "分数" for _, d := range rsp.Data.Top3 { row := sheet.AddRow() c1, c2, c3, c4 := row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell() c1.Value, c2.Value, c3.Value, c4.Value = cast.ToString(d.Rank), cast.ToString(d.Code), cast.ToString(d.User2.Code), cast.ToString(d.Score) } for _, d := range rsp.Data.List { row := sheet.AddRow() c1, c2, c3, c4 := row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell() c1.Value, c2.Value, c3.Value, c4.Value = cast.ToString(d.Rank), cast.ToString(d.Code), cast.ToString(d.User2.Code), cast.ToString(d.Score) } _ = xlFile.Save(excelFileName) }