From 707fb3f7c2fec51a3059e9431031b28c9bcb7a8a Mon Sep 17 00:00:00 2001 From: Mrs4s <1844812067@qq.com> Date: Wed, 19 Aug 2020 01:56:44 +0800 Subject: [PATCH] add: GetGroupHonorInfo() --- client/client.go | 17 +++++++++++++++++ client/decoders.go | 2 +- client/entities.go | 6 +++--- client/honor.go | 39 +++++++++++++++++++++++++++++++++++++++ utils/http.go | 5 ++++- 5 files changed, 64 insertions(+), 5 deletions(-) create mode 100644 client/honor.go diff --git a/client/client.go b/client/client.go index 84c9b96e..3a6dddf6 100644 --- a/client/client.go +++ b/client/client.go @@ -4,6 +4,7 @@ import ( "bytes" "crypto/md5" "encoding/hex" + "encoding/json" "errors" "fmt" "io" @@ -11,6 +12,7 @@ import ( "math" "math/rand" "net" + "strings" "sync" "sync/atomic" "time" @@ -173,6 +175,21 @@ func (c *QQClient) Login() (*LoginResponse, error) { return &l, nil } +func (c *QQClient) GetGroupHonorInfo(groupCode int64, honorType HonorType) (*GroupHonorInfo, error) { + b, err := utils.HttpGetBytes(fmt.Sprintf("https://qun.qq.com/interactive/honorlist?gc=%d&type=%d", groupCode, honorType), c.getCookiesWithDomain("qun.qq.com")) + if err != nil { + return nil, err + } + rsp := string(b) + data := strings.Split(strings.Split(rsp, `window.__INITIAL_STATE__=`)[1], "")[0] + ret := GroupHonorInfo{} + err = json.Unmarshal([]byte(data), &ret) + if err != nil { + return nil, err + } + return &ret, nil +} + // SubmitCaptcha send captcha to server func (c *QQClient) SubmitCaptcha(result string, sign []byte) (*LoginResponse, error) { seq, packet := c.buildCaptchaPacket(result, sign) diff --git a/client/decoders.go b/client/decoders.go index e02c22ea..0c4ce623 100644 --- a/client/decoders.go +++ b/client/decoders.go @@ -777,7 +777,7 @@ func decodeMultiApplyDownResponse(c *QQClient, _ uint16, payload []byte) (interf } rsp := body.MultimsgApplydownRsp[0] i := binary.UInt32ToIPV4Address(uint32(rsp.Uint32DownIp[0])) - b, err := utils.HttpGetBytes(fmt.Sprintf("http://%s:%d%s", i, body.MultimsgApplydownRsp[0].Uint32DownPort[0], string(rsp.ThumbDownPara))) + b, err := utils.HttpGetBytes(fmt.Sprintf("http://%s:%d%s", i, body.MultimsgApplydownRsp[0].Uint32DownPort[0], string(rsp.ThumbDownPara)), "") if err != nil { return nil, err } diff --git a/client/entities.go b/client/entities.go index d330de2b..b2f4a37b 100644 --- a/client/entities.go +++ b/client/entities.go @@ -191,9 +191,9 @@ type ( const ( NeedCaptcha LoginError = 1 - OtherLoginError = 3 - UnsafeDeviceError = 4 - UnknownLoginError = -1 + OtherLoginError LoginError = 3 + UnsafeDeviceError LoginError = 4 + UnknownLoginError LoginError = -1 Owner MemberPermission = iota Administrator diff --git a/client/honor.go b/client/honor.go new file mode 100644 index 00000000..9081693c --- /dev/null +++ b/client/honor.go @@ -0,0 +1,39 @@ +package client + +type ( + HonorType int + + GroupHonorInfo struct { + GroupCode string `json:"gc"` + Uin string `json:"uin"` + Type HonorType `json:"type"` + TalkativeList []HonorMemberInfo `json:"talkativeList"` + CurrentTalkative CurrentTalkative `json:"currentTalkative"` + ActorList []HonorMemberInfo `json:"actorList"` + LegendList []HonorMemberInfo `json:"legendList"` + StrongNewbieList []HonorMemberInfo `json:"strongnewbieList"` + EmotionList []HonorMemberInfo `json:"emotionList"` + } + + HonorMemberInfo struct { + Uin int64 `json:"uin"` + Avatar string `json:"avatar"` + Name string `json:"name"` + Desc string `json:"desc"` + } + + CurrentTalkative struct { + Uin int64 `json:"uin"` + DayCount int32 `json:"day_count"` + Avatar string `json:"avatar"` + Name string `json:"nick"` + } +) + +const ( + Talkative HonorType = 1 //龙王 + Performer HonorType = 2 //群聊之火 + Legend HonorType = 3 //群聊炙焰 + StrongNewbie HonorType = 5 //冒尖小春笋 + Emotion HonorType = 6 //快乐源泉 +) diff --git a/utils/http.go b/utils/http.go index d2d10562..436c92bf 100644 --- a/utils/http.go +++ b/utils/http.go @@ -8,13 +8,16 @@ import ( "strings" ) -func HttpGetBytes(url string) ([]byte, error) { +func HttpGetBytes(url, cookie string) ([]byte, error) { req, err := http.NewRequest("GET", url, nil) if err != nil { return nil, err } req.Header["User-Agent"] = []string{"QQ/8.2.0.1296 CFNetwork/1126"} req.Header["Net-Type"] = []string{"Wifi"} + if cookie != "" { + req.Header["Cookie"] = []string{cookie} + } resp, err := http.DefaultClient.Do(req) if err != nil { return nil, err