diff --git a/lsp/bilibili/XSpaceAccInfo.go b/lsp/bilibili/XSpaceAccInfo.go index 72719ee0..c3a9fd3c 100644 --- a/lsp/bilibili/XSpaceAccInfo.go +++ b/lsp/bilibili/XSpaceAccInfo.go @@ -18,7 +18,6 @@ const ( type XSpaceAccInfoRequest struct { Mid int64 `json:"mid"` Platform string `json:"platform"` - Jsonp string `json:"jsonp"` Token string `json:"token"` WebLocation string `json:"web_location"` } @@ -47,10 +46,9 @@ func XSpaceAccInfo(mid int64) (*XSpaceAccInfoResponse, error) { logger.WithField("FuncName", utils.FuncName()).Tracef("cost %v", ed.Sub(st)) }() url := BPath(PathXSpaceAccInfo) - params, err := utils.ToParams(&XSpaceAccInfoRequest{ + params, err := utils.ToDatas(&XSpaceAccInfoRequest{ Mid: mid, Platform: "web", - Jsonp: "jsonp", WebLocation: "1550101", }) if err != nil { diff --git a/lsp/bilibili/XWebInterfaceNav.go b/lsp/bilibili/XWebInterfaceNav.go index 7aafa661..0de07ec5 100644 --- a/lsp/bilibili/XWebInterfaceNav.go +++ b/lsp/bilibili/XWebInterfaceNav.go @@ -7,9 +7,9 @@ import ( "github.com/Sora233/DDBOT/proxy_pool" "github.com/Sora233/DDBOT/requests" "github.com/Sora233/DDBOT/utils" - "github.com/guonaihong/gout" "github.com/samber/lo" "sort" + "strconv" "strings" "time" ) @@ -40,30 +40,36 @@ func getWbi() (imgKey string, subKey string) { subKey = getKey(wbi.SubUrl) return } +func getMixinKey(orig string) string { + var str strings.Builder + for _, v := range mixinKeyEncTab { + if v < len(orig) { + str.WriteByte(orig[v]) + } + } + return str.String()[:32] +} -func signWbi(params gout.H) { +func signWbi(params map[string]string) map[string]string { imgKey, subKey := getWbi() - var sb strings.Builder - var orig = imgKey + subKey - for _, r := range mixinKeyEncTab { - sb.WriteRune(rune(orig[r])) + mixinKey := getMixinKey(imgKey + subKey) + currTime := strconv.FormatInt(time.Now().Unix(), 10) + params["wts"] = currTime + // Sort keys + keys := make([]string, 0, len(params)) + for k := range params { + keys = append(keys, k) } - salt := sb.String()[:32] - params["wts"] = time.Now().Unix() - p := lo.MapToSlice(params, func(key string, value any) lo.Tuple2[string, any] { - return lo.Tuple2[string, any]{A: key, B: value} - }) - sort.Slice(p, func(i, j int) bool { - return p[i].A < p[j].A - }) - - query := strings.Join(lo.Map(p, func(item lo.Tuple2[string, any], _ int) string { - return fmt.Sprintf("%v=%v", item.A, item.B) - }), "&") - hash := md5.New() - hash.Write([]byte(query + salt)) - wbiSign := hex.EncodeToString(hash.Sum(nil)) - params["w_rid"] = wbiSign + sort.Strings(keys) + // Build URL parameters + var str strings.Builder + for _, k := range keys { + str.WriteString(fmt.Sprintf("%s=%s&", k, params[k])) + } + query := strings.TrimSuffix(str.String(), "&") + hash := md5.Sum([]byte(query + mixinKey)) + params["w_rid"] = hex.EncodeToString(hash[:]) + return params } func XWebInterfaceNav(login bool) (*WebInterfaceNavResponse, error) { diff --git a/lsp/bilibili/bilibili.go b/lsp/bilibili/bilibili.go index d018d9ab..7554d01f 100644 --- a/lsp/bilibili/bilibili.go +++ b/lsp/bilibili/bilibili.go @@ -73,7 +73,7 @@ var ( } }) }() - mixinKeyEncTab = []rune{ + mixinKeyEncTab = []int{ 46, 47, 18, 2, 53, 8, 23, 32, 15, 50, 10, 31, 58, 3, 45, 35, 27, 43, 5, 49, 33, 9, 42, 19, 29, 28, 14, 39, 12, 38, 41, 13, 37, 48, 7, 16, 24, 55, 40, 61, 26, 17, 0, 1, 60, 51, 30, 4, 22, 25, 54, 21, 56, 59, 6, 63, 57, 62, 11, diff --git a/lsp/bilibili/concern_test.go b/lsp/bilibili/concern_test.go index 22ec3153..7dfaf3da 100644 --- a/lsp/bilibili/concern_test.go +++ b/lsp/bilibili/concern_test.go @@ -74,12 +74,11 @@ func TestConcern_FindUserLiving(t *testing.T) { assert.NotNil(t, err) assert.Nil(t, liveInfo) - const testMid int64 = 2 + const testMid int64 = 97505 userInfo, err := c.FindOrLoadUser(testMid) assert.Nil(t, err) assert.Equal(t, testMid, userInfo.Mid) - assert.Equal(t, "碧诗", userInfo.Name) liveInfo, err = c.FindUserLiving(testMid, true) assert.Nil(t, err) @@ -109,12 +108,11 @@ func TestConcern_FindUserNews(t *testing.T) { assert.NotNil(t, err) assert.Nil(t, newsInfo) - const testMid int64 = 2 + const testMid int64 = 97505 userInfo, err := c.FindOrLoadUser(testMid) assert.Nil(t, err) assert.Equal(t, testMid, userInfo.Mid) - assert.Equal(t, "碧诗", userInfo.Name) userInfo2, err := c.FindOrLoadUser(testMid) assert.Nil(t, err) @@ -135,12 +133,11 @@ func TestConcern_StatUserWithCache(t *testing.T) { c := initConcern(t) - const testMid int64 = 2 + const testMid int64 = 97505 userInfo, err := c.FindOrLoadUser(testMid) assert.Nil(t, err) assert.Equal(t, testMid, userInfo.Mid) - assert.Equal(t, "碧诗", userInfo.Name) stat, err := c.StatUserWithCache(testMid, time.Hour) assert.Nil(t, err) diff --git a/lsp/bilibili/feedList.go b/lsp/bilibili/feedList.go index cfc85fdb..06e93067 100644 --- a/lsp/bilibili/feedList.go +++ b/lsp/bilibili/feedList.go @@ -48,7 +48,7 @@ func FeedList(opt ...FeedOpt) (*FeedListResponse, error) { } url := BPath(PathRelationFeedList) - params, err := utils.ToParams(&RelationFeedRequest{ + params, err := utils.ToDatas(&RelationFeedRequest{ Page: p["page"], PageSize: p["pageSize"], }) diff --git a/requests/requests.go b/requests/requests.go index d8288f62..715042e7 100644 --- a/requests/requests.go +++ b/requests/requests.go @@ -249,7 +249,7 @@ func Do(f func(*gout.Client) *dataflow.DataFlow, out interface{}, options ...Opt return nil } -func Get(url string, params gout.H, out interface{}, options ...Option) error { +func Get(url string, params interface{}, out interface{}, options ...Option) error { return Do(func(gcli *gout.Client) *dataflow.DataFlow { return gcli.GET(url).SetQuery(params) }, out, options...)