forked from Mrs4s/MiraiGo
/
model_show.go
118 lines (104 loc) · 2.76 KB
/
model_show.go
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
package client
import (
"encoding/json"
"fmt"
"net/url"
"strings"
"time"
"github.com/tidwall/gjson"
"github.com/shacha086/MiraiGo/utils"
)
type (
ModelVariant struct {
NeedPay bool
ModelShow string
}
ModelGet struct {
Req ModelReq `json:"13030"`
}
ModelSet struct {
Req ModelReq `json:"13031"`
}
ModelReq struct {
Req ModelReqData `json:"req"`
}
ModelReqData struct {
Uin int64 `json:"lUin"`
Model string `json:"sModel"`
AppType int32 `json:"iAppType"`
IMei string `json:"sIMei"`
ShowInfo bool `json:"bShowInfo"`
ModelShow string `json:"sModelShow"`
RecoverDefault bool `json:"bRecoverDefault"`
}
)
func (c *QQClient) getGtk(domain string) int {
if psKey, ok := c.sig.PsKeyMap[domain]; ok {
accu := 5381
for _, b := range psKey {
accu = accu + (accu << 5) + int(b)
}
return 2147483647 & accu
}
return 0
}
func (c *QQClient) GetModelShow(modelName string) ([]*ModelVariant, error) {
req := ModelGet{
Req: ModelReq{
Req: ModelReqData{
Uin: c.Uin,
Model: strings.ReplaceAll(url.QueryEscape(modelName), "+", "%20"),
AppType: 0,
IMei: c.deviceInfo.IMEI,
ShowInfo: true,
ModelShow: "",
RecoverDefault: false,
},
},
}
ts := time.Now().UnixNano() / 1e6
g_tk := c.getGtk("vip.qq.com")
data, _ := json.Marshal(req)
b, err := utils.HttpGetBytes(
fmt.Sprintf("https://proxy.vip.qq.com/cgi-bin/srfentry.fcgi?ts=%d&daid=18&g_tk=%d&pt4_token=&data=%s", ts, g_tk, url.QueryEscape(string(data))),
c.getCookiesWithDomain("vip.qq.com"),
)
if err != nil {
return nil, err
}
variants := make([]*ModelVariant, 0)
gjson.ParseBytes(b).Get("13030.data.rsp.vItemList").ForEach(func(_, value gjson.Result) bool {
variants = append(variants, &ModelVariant{
ModelShow: value.Get("sModelShow").String(),
NeedPay: value.Get("bNeedPay").Bool(),
})
return true
})
return variants, nil
}
func (c *QQClient) SetModelShow(modelName string, modelShow string) error {
req := ModelSet{
Req: ModelReq{
Req: ModelReqData{
Uin: c.Uin,
Model: strings.ReplaceAll(url.QueryEscape(modelName), "+", "%20"),
AppType: 0,
IMei: c.deviceInfo.IMEI,
ShowInfo: true,
ModelShow: strings.ReplaceAll(url.QueryEscape(modelShow), "+", "%20"),
RecoverDefault: modelShow == "",
},
},
}
ts := time.Now().UnixNano() / 1e6
g_tk := c.getGtk("vip.qq.com")
data, _ := json.Marshal(req)
_, err := utils.HttpGetBytes(
fmt.Sprintf("https://proxy.vip.qq.com/cgi-bin/srfentry.fcgi?ts=%d&daid=18&g_tk=%d&pt4_token=&data=%s", ts, g_tk, url.QueryEscape(string(data))),
c.getCookiesWithDomain("vip.qq.com"),
)
if err != nil {
return err
}
return nil
}