act_rank_data.go 10.9 KB
Newer Older
hujiebin's avatar
hujiebin committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
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)
}