mirror of
https://github.com/Mrs4s/MiraiGo.git
synced 2025-05-04 11:07:40 +08:00
fix: get group honor info (#340)
* fix: get group honor info * update: use newDecoder instead manual parse
This commit is contained in:
parent
e4b6dc62fd
commit
a8213e127b
@ -9,6 +9,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"net/textproto"
|
"net/textproto"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@ -59,15 +60,20 @@ const (
|
|||||||
Emotion HonorType = 6 // 快乐源泉
|
Emotion HonorType = 6 // 快乐源泉
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// 匹配 window.__INITIAL_STATE__ = 后的内容
|
||||||
|
var honorRe = regexp.MustCompile(`window\.__INITIAL_STATE__\s*?=\s*?(\{.*\})`)
|
||||||
|
|
||||||
func (c *QQClient) GetGroupHonorInfo(groupCode int64, honorType HonorType) (*GroupHonorInfo, error) {
|
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"))
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
b = b[bytes.Index(b, []byte(`window.__INITIAL_STATE__=`))+25:]
|
matched := honorRe.FindSubmatch(b)
|
||||||
b = b[:bytes.Index(b, []byte("</script>"))]
|
if len(matched) == 0 {
|
||||||
|
return nil, errors.New("无匹配结果")
|
||||||
|
}
|
||||||
ret := GroupHonorInfo{}
|
ret := GroupHonorInfo{}
|
||||||
err = json.Unmarshal(b, &ret)
|
err = json.NewDecoder(bytes.NewReader(matched[1])).Decode(&ret)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user