mirror of
https://github.com/Mrs4s/MiraiGo.git
synced 2025-05-04 19:17:38 +08:00
feat: support get group announcement (#258)
* feat: support get group announcement * refactor: avoid importing new dependent package * refactor: prettify
This commit is contained in:
parent
f5950d72fa
commit
8fa49fedb9
@ -165,6 +165,32 @@ func (c *QQClient) GetTts(text string) ([]byte, error) {
|
|||||||
|
|
||||||
/* -------- GroupNotice -------- */
|
/* -------- GroupNotice -------- */
|
||||||
|
|
||||||
|
type groupNoticeRsp struct {
|
||||||
|
Feeds []*struct {
|
||||||
|
SenderId uint32 `json:"u"`
|
||||||
|
PublishTime uint64 `json:"pubt"`
|
||||||
|
Message struct {
|
||||||
|
Text string `json:"text"`
|
||||||
|
Images []noticeImage `json:"pics"`
|
||||||
|
} `json:"msg"`
|
||||||
|
} `json:"feeds"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type GroupNoticeMessage struct {
|
||||||
|
SenderId uint32 `json:"sender_id"`
|
||||||
|
PublishTime uint64 `json:"publish_time"`
|
||||||
|
Message struct {
|
||||||
|
Text string `json:"text"`
|
||||||
|
Images []GroupNoticeImage `json:"images"`
|
||||||
|
} `json:"message"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type GroupNoticeImage struct {
|
||||||
|
Height string `json:"height"`
|
||||||
|
Width string `json:"width"`
|
||||||
|
ID string `json:"id"`
|
||||||
|
}
|
||||||
|
|
||||||
type noticePicUpResponse struct {
|
type noticePicUpResponse struct {
|
||||||
ErrorCode int `json:"ec"`
|
ErrorCode int `json:"ec"`
|
||||||
ErrorMessage string `json:"em"`
|
ErrorMessage string `json:"em"`
|
||||||
@ -177,6 +203,66 @@ type noticeImage struct {
|
|||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *QQClient) GetGroupNotice(groupCode int64) (l []*GroupNoticeMessage, err error) {
|
||||||
|
|
||||||
|
v := url.Values{}
|
||||||
|
v.Set("bkn", strconv.Itoa(c.getCSRFToken()))
|
||||||
|
v.Set("qid", strconv.FormatInt(groupCode, 10))
|
||||||
|
v.Set("ft", "23")
|
||||||
|
v.Set("ni", "1")
|
||||||
|
v.Set("n", "1")
|
||||||
|
v.Set("i", "1")
|
||||||
|
v.Set("log_read", "1")
|
||||||
|
v.Set("platform", "1")
|
||||||
|
v.Set("s", "-1")
|
||||||
|
v.Set("n", "20")
|
||||||
|
|
||||||
|
req, _ := http.NewRequest(http.MethodGet, "https://web.qun.qq.com/cgi-bin/announce/get_t_list?"+v.Encode(), nil)
|
||||||
|
req.Header.Set("Cookie", c.getCookies())
|
||||||
|
rsp, err := utils.Client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer rsp.Body.Close()
|
||||||
|
|
||||||
|
r := groupNoticeRsp{}
|
||||||
|
err = json.NewDecoder(rsp.Body).Decode(&r)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.parseGroupNoticeJson(&r), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *QQClient) parseGroupNoticeJson(s *groupNoticeRsp) []*GroupNoticeMessage {
|
||||||
|
o := make([]*GroupNoticeMessage, 0, len(s.Feeds))
|
||||||
|
for _, v := range s.Feeds {
|
||||||
|
|
||||||
|
ims := make([]GroupNoticeImage, 0, len(v.Message.Images))
|
||||||
|
for i := 0; i < len(v.Message.Images); i++ {
|
||||||
|
ims = append(ims, GroupNoticeImage{
|
||||||
|
Height: v.Message.Images[i].Height,
|
||||||
|
Width: v.Message.Images[i].Width,
|
||||||
|
ID: v.Message.Images[i].ID,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
o = append(o, &GroupNoticeMessage{
|
||||||
|
SenderId: v.SenderId,
|
||||||
|
PublishTime: v.PublishTime,
|
||||||
|
Message: struct {
|
||||||
|
Text string `json:"text"`
|
||||||
|
Images []GroupNoticeImage `json:"images"`
|
||||||
|
}{
|
||||||
|
Text: v.Message.Text,
|
||||||
|
Images: ims,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
func (c *QQClient) uploadGroupNoticePic(img []byte) (*noticeImage, error) {
|
func (c *QQClient) uploadGroupNoticePic(img []byte) (*noticeImage, error) {
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
w := multipart.NewWriter(buf)
|
w := multipart.NewWriter(buf)
|
||||||
|
@ -8,7 +8,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
var client = &http.Client{
|
var Client = &http.Client{
|
||||||
Transport: &http.Transport{
|
Transport: &http.Transport{
|
||||||
ForceAttemptHTTP2: true,
|
ForceAttemptHTTP2: true,
|
||||||
MaxConnsPerHost: 0,
|
MaxConnsPerHost: 0,
|
||||||
@ -34,7 +34,7 @@ func HttpPostBytes(url string, data []byte) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
req.Header["User-Agent"] = []string{"QQ/8.2.0.1296 CFNetwork/1126"}
|
req.Header["User-Agent"] = []string{"QQ/8.2.0.1296 CFNetwork/1126"}
|
||||||
req.Header["Net-Type"] = []string{"Wifi"}
|
req.Header["Net-Type"] = []string{"Wifi"}
|
||||||
resp, err := client.Do(req)
|
resp, err := Client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -67,7 +67,7 @@ func HttpPostBytesWithCookie(url string, data []byte, cookie string, contentType
|
|||||||
if cookie != "" {
|
if cookie != "" {
|
||||||
req.Header["Cookie"] = []string{cookie}
|
req.Header["Cookie"] = []string{cookie}
|
||||||
}
|
}
|
||||||
resp, err := client.Do(req)
|
resp, err := Client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -125,7 +125,7 @@ func HTTPGetReadCloser(url string, cookie string) (io.ReadCloser, error) {
|
|||||||
if cookie != "" {
|
if cookie != "" {
|
||||||
req.Header["Cookie"] = []string{cookie}
|
req.Header["Cookie"] = []string{cookie}
|
||||||
}
|
}
|
||||||
resp, err := client.Do(req)
|
resp, err := Client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user