Skip to content

Commit efbc144

Browse files
committed
update sign
1 parent 24533b2 commit efbc144

File tree

6 files changed

+35
-34
lines changed

6 files changed

+35
-34
lines changed

lsp/bilibili/XSpaceAccInfo.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ const (
1818
type XSpaceAccInfoRequest struct {
1919
Mid int64 `json:"mid"`
2020
Platform string `json:"platform"`
21-
Jsonp string `json:"jsonp"`
2221
Token string `json:"token"`
2322
WebLocation string `json:"web_location"`
2423
}
@@ -47,10 +46,9 @@ func XSpaceAccInfo(mid int64) (*XSpaceAccInfoResponse, error) {
4746
logger.WithField("FuncName", utils.FuncName()).Tracef("cost %v", ed.Sub(st))
4847
}()
4948
url := BPath(PathXSpaceAccInfo)
50-
params, err := utils.ToParams(&XSpaceAccInfoRequest{
49+
params, err := utils.ToDatas(&XSpaceAccInfoRequest{
5150
Mid: mid,
5251
Platform: "web",
53-
Jsonp: "jsonp",
5452
WebLocation: "1550101",
5553
})
5654
if err != nil {

lsp/bilibili/XWebInterfaceNav.go

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import (
77
"github.com/Sora233/DDBOT/proxy_pool"
88
"github.com/Sora233/DDBOT/requests"
99
"github.com/Sora233/DDBOT/utils"
10-
"github.com/guonaihong/gout"
1110
"github.com/samber/lo"
1211
"sort"
12+
"strconv"
1313
"strings"
1414
"time"
1515
)
@@ -40,30 +40,36 @@ func getWbi() (imgKey string, subKey string) {
4040
subKey = getKey(wbi.SubUrl)
4141
return
4242
}
43+
func getMixinKey(orig string) string {
44+
var str strings.Builder
45+
for _, v := range mixinKeyEncTab {
46+
if v < len(orig) {
47+
str.WriteByte(orig[v])
48+
}
49+
}
50+
return str.String()[:32]
51+
}
4352

44-
func signWbi(params gout.H) {
53+
func signWbi(params map[string]string) map[string]string {
4554
imgKey, subKey := getWbi()
46-
var sb strings.Builder
47-
var orig = imgKey + subKey
48-
for _, r := range mixinKeyEncTab {
49-
sb.WriteRune(rune(orig[r]))
55+
mixinKey := getMixinKey(imgKey + subKey)
56+
currTime := strconv.FormatInt(time.Now().Unix(), 10)
57+
params["wts"] = currTime
58+
// Sort keys
59+
keys := make([]string, 0, len(params))
60+
for k := range params {
61+
keys = append(keys, k)
5062
}
51-
salt := sb.String()[:32]
52-
params["wts"] = time.Now().Unix()
53-
p := lo.MapToSlice(params, func(key string, value any) lo.Tuple2[string, any] {
54-
return lo.Tuple2[string, any]{A: key, B: value}
55-
})
56-
sort.Slice(p, func(i, j int) bool {
57-
return p[i].A < p[j].A
58-
})
59-
60-
query := strings.Join(lo.Map(p, func(item lo.Tuple2[string, any], _ int) string {
61-
return fmt.Sprintf("%v=%v", item.A, item.B)
62-
}), "&")
63-
hash := md5.New()
64-
hash.Write([]byte(query + salt))
65-
wbiSign := hex.EncodeToString(hash.Sum(nil))
66-
params["w_rid"] = wbiSign
63+
sort.Strings(keys)
64+
// Build URL parameters
65+
var str strings.Builder
66+
for _, k := range keys {
67+
str.WriteString(fmt.Sprintf("%s=%s&", k, params[k]))
68+
}
69+
query := strings.TrimSuffix(str.String(), "&")
70+
hash := md5.Sum([]byte(query + mixinKey))
71+
params["w_rid"] = hex.EncodeToString(hash[:])
72+
return params
6773
}
6874

6975
func XWebInterfaceNav(login bool) (*WebInterfaceNavResponse, error) {

lsp/bilibili/bilibili.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ var (
7373
}
7474
})
7575
}()
76-
mixinKeyEncTab = []rune{
76+
mixinKeyEncTab = []int{
7777
46, 47, 18, 2, 53, 8, 23, 32, 15, 50, 10, 31, 58, 3, 45, 35, 27, 43, 5, 49,
7878
33, 9, 42, 19, 29, 28, 14, 39, 12, 38, 41, 13, 37, 48, 7, 16, 24, 55, 40,
7979
61, 26, 17, 0, 1, 60, 51, 30, 4, 22, 25, 54, 21, 56, 59, 6, 63, 57, 62, 11,

lsp/bilibili/concern_test.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,11 @@ func TestConcern_FindUserLiving(t *testing.T) {
7474
assert.NotNil(t, err)
7575
assert.Nil(t, liveInfo)
7676

77-
const testMid int64 = 2
77+
const testMid int64 = 97505
7878

7979
userInfo, err := c.FindOrLoadUser(testMid)
8080
assert.Nil(t, err)
8181
assert.Equal(t, testMid, userInfo.Mid)
82-
assert.Equal(t, "碧诗", userInfo.Name)
8382

8483
liveInfo, err = c.FindUserLiving(testMid, true)
8584
assert.Nil(t, err)
@@ -109,12 +108,11 @@ func TestConcern_FindUserNews(t *testing.T) {
109108
assert.NotNil(t, err)
110109
assert.Nil(t, newsInfo)
111110

112-
const testMid int64 = 2
111+
const testMid int64 = 97505
113112

114113
userInfo, err := c.FindOrLoadUser(testMid)
115114
assert.Nil(t, err)
116115
assert.Equal(t, testMid, userInfo.Mid)
117-
assert.Equal(t, "碧诗", userInfo.Name)
118116

119117
userInfo2, err := c.FindOrLoadUser(testMid)
120118
assert.Nil(t, err)
@@ -135,12 +133,11 @@ func TestConcern_StatUserWithCache(t *testing.T) {
135133

136134
c := initConcern(t)
137135

138-
const testMid int64 = 2
136+
const testMid int64 = 97505
139137

140138
userInfo, err := c.FindOrLoadUser(testMid)
141139
assert.Nil(t, err)
142140
assert.Equal(t, testMid, userInfo.Mid)
143-
assert.Equal(t, "碧诗", userInfo.Name)
144141

145142
stat, err := c.StatUserWithCache(testMid, time.Hour)
146143
assert.Nil(t, err)

lsp/bilibili/feedList.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func FeedList(opt ...FeedOpt) (*FeedListResponse, error) {
4848
}
4949

5050
url := BPath(PathRelationFeedList)
51-
params, err := utils.ToParams(&RelationFeedRequest{
51+
params, err := utils.ToDatas(&RelationFeedRequest{
5252
Page: p["page"],
5353
PageSize: p["pageSize"],
5454
})

requests/requests.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ func Do(f func(*gout.Client) *dataflow.DataFlow, out interface{}, options ...Opt
249249
return nil
250250
}
251251

252-
func Get(url string, params gout.H, out interface{}, options ...Option) error {
252+
func Get(url string, params interface{}, out interface{}, options ...Option) error {
253253
return Do(func(gcli *gout.Client) *dataflow.DataFlow {
254254
return gcli.GET(url).SetQuery(params)
255255
}, out, options...)

0 commit comments

Comments
 (0)