github.com/Mrs4s/MiraiGo@v0.0.0-20240226124653-54bdd873e3fe/client/model_show.go (about) 1 package client 2 3 import ( 4 "encoding/json" 5 "fmt" 6 "net/url" 7 "strings" 8 "time" 9 10 "github.com/tidwall/gjson" 11 12 "github.com/Mrs4s/MiraiGo/utils" 13 ) 14 15 type ( 16 ModelVariant struct { 17 NeedPay bool 18 ModelShow string 19 } 20 21 ModelGet struct { 22 Req ModelReq `json:"13030"` 23 } 24 25 ModelSet struct { 26 Req ModelReq `json:"13031"` 27 } 28 29 ModelReq struct { 30 Req ModelReqData `json:"req"` 31 } 32 33 ModelReqData struct { 34 Uin int64 `json:"lUin"` 35 Model string `json:"sModel"` 36 AppType int32 `json:"iAppType"` 37 IMei string `json:"sIMei"` 38 ShowInfo bool `json:"bShowInfo"` 39 ModelShow string `json:"sModelShow"` 40 RecoverDefault bool `json:"bRecoverDefault"` 41 } 42 ) 43 44 func (c *QQClient) getGtk(domain string) int { 45 if psKey, ok := c.sig.PsKeyMap[domain]; ok { 46 accu := 5381 47 for _, b := range psKey { 48 accu = accu + (accu << 5) + int(b) 49 } 50 return 2147483647 & accu 51 } 52 return 0 53 } 54 55 func (c *QQClient) GetModelShow(modelName string) ([]*ModelVariant, error) { 56 req := ModelGet{ 57 Req: ModelReq{ 58 Req: ModelReqData{ 59 Uin: c.Uin, 60 Model: strings.ReplaceAll(url.QueryEscape(modelName), "+", "%20"), 61 AppType: 0, 62 IMei: c.Device().IMEI, 63 ShowInfo: true, 64 ModelShow: "", 65 RecoverDefault: false, 66 }, 67 }, 68 } 69 70 ts := time.Now().UnixNano() / 1e6 71 g_tk := c.getGtk("vip.qq.com") 72 data, _ := json.Marshal(req) 73 b, err := utils.HttpGetBytes( 74 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))), 75 c.getCookiesWithDomain("vip.qq.com"), 76 ) 77 if err != nil { 78 return nil, err 79 } 80 81 variants := make([]*ModelVariant, 0) 82 gjson.ParseBytes(b).Get("13030.data.rsp.vItemList").ForEach(func(_, value gjson.Result) bool { 83 variants = append(variants, &ModelVariant{ 84 ModelShow: value.Get("sModelShow").String(), 85 NeedPay: value.Get("bNeedPay").Bool(), 86 }) 87 return true 88 }) 89 return variants, nil 90 } 91 92 func (c *QQClient) SetModelShow(modelName string, modelShow string) error { 93 req := ModelSet{ 94 Req: ModelReq{ 95 Req: ModelReqData{ 96 Uin: c.Uin, 97 Model: strings.ReplaceAll(url.QueryEscape(modelName), "+", "%20"), 98 AppType: 0, 99 IMei: c.Device().IMEI, 100 ShowInfo: true, 101 ModelShow: strings.ReplaceAll(url.QueryEscape(modelShow), "+", "%20"), 102 RecoverDefault: modelShow == "", 103 }, 104 }, 105 } 106 107 ts := time.Now().UnixNano() / 1e6 108 g_tk := c.getGtk("vip.qq.com") 109 data, _ := json.Marshal(req) 110 _, err := utils.HttpGetBytes( 111 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))), 112 c.getCookiesWithDomain("vip.qq.com"), 113 ) 114 if err != nil { 115 return err 116 } 117 return nil 118 }