返回提交历史
Modified
docs/misc/sign/wbi.md
+59
-1
XFEstudio/bilibili-API-collect
添加Wbi签名的Java实现 (#726)
fd313b8
代码差异
1 个文件
+59
-1
@@ -115,7 +115,7 @@
115
115
116
116
## Wbi签名算法实现Demo
117
117
118
该 Demo 提供 [Python](#Python)、[JavaScript](#JavaScript)、[Golang](#Golang)、[C#](#CSharp) 语言
118
该 Demo 提供 [Python](#Python)、[JavaScript](#JavaScript)、[Golang](#Golang)、[C#](#CSharp) 语言、[Java](#Java)
119
119
120
120
### Python
121
121
@@ -518,4 +518,62 @@ class Program
518
518
519
519
```
520
520
bar=514&baz=1919810&foo=114&wts=1687541921&w_rid=26e82b1b9b3a11dbb1807a9228a40d3b
521
```
522
523
### Java
524
525
需要 `hutool` 依赖
526
527
```java
528
package com.example.demo;
529
530
import cn.hutool.crypto.SecureUtil;
531
532
import java.util.*;
533
534
public class WbiTest {
535
private static final int[] mixinKeyEncTab = new int[]{
536
46, 47, 18, 2, 53, 8, 23, 32, 15, 50, 10, 31, 58, 3, 45, 35, 27, 43, 5, 49,
537
33, 9, 42, 19, 29, 28, 14, 39, 12, 38, 41, 13, 37, 48, 7, 16, 24, 55, 40,
538
61, 26, 17, 0, 1, 60, 51, 30, 4, 22, 25, 54, 21, 56, 59, 6, 63, 57, 62, 11,
539
36, 20, 34, 44, 52
540
};
541
542
public static String getMixinKey(String imgKey, String subKey) {
543
String s = imgKey + subKey;
544
StringBuilder key = new StringBuilder();
545
for (int i = 0; i < 32; i++) {
546
key.append(s.charAt(mixinKeyEncTab[i]));
547
}
548
return key.toString();
549
}
550
551
public static void main(String[] args) {
552
String imgKey = "653657f524a547ac981ded72ea172057";
553
String subKey = "6e4909c702f846728e64f6007736a338";
554
String mixinKey = getMixinKey(imgKey, subKey);
555
System.out.println(mixinKey);
556
//72136226c6a73669787ee4fd02a74c27
557
//{
558
// foo: 'one one four',
559
// bar: '五一四',
560
// baz: 1919810
561
//}
562
LinkedHashMap<String, Object> map = new LinkedHashMap<>();
563
map.put("foo", "one one four");
564
map.put("bar", "五一四");
565
map.put("baz", 1919810);
566
map.put("wts", System.currentTimeMillis() / 1000);
567
StringJoiner param = new StringJoiner("&");
568
//排序 + 拼接字符串
569
map.entrySet().stream()
570
.sorted(Map.Entry.comparingByKey())
571
.forEach(entry -> param.add(entry.getKey() + "=" + URLUtil.encode(entry.getValue().toString())));
572
String s = param + mixinKey;
573
String wbiSign = SecureUtil.md5(s);
574
System.out.println(wbiSign);
575
String finalParam = param + "&w_rid=" + wbiSign;
576
System.out.println(finalParam);
577
}
578
}
521
579
```