mirror of
https://github.com/SocialSisterYi/bilibili-API-collect.git
synced 2025-03-11 00:40:07 +08:00
添加Wbi签名的Java实现 (#722)
This commit is contained in:
parent
33696c0fc3
commit
a8742859fc
@ -422,3 +422,60 @@ func main() {
|
||||
fmt.Println(string(body))
|
||||
}
|
||||
```
|
||||
### Java
|
||||
|
||||
需要 `hutool` 依赖
|
||||
|
||||
```java
|
||||
package com.example.demo;
|
||||
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class WbiTest {
|
||||
private static final int[] mixinKeyEncTab = new 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,
|
||||
36, 20, 34, 44, 52
|
||||
};
|
||||
|
||||
public static String getMixinKey(String imgKey, String subKey) {
|
||||
String s = imgKey + subKey;
|
||||
StringBuilder key = new StringBuilder();
|
||||
for (int i = 0; i < 32; i++) {
|
||||
key.append(s.charAt(mixinKeyEncTab[i]));
|
||||
}
|
||||
return key.toString();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String imgKey = "653657f524a547ac981ded72ea172057";
|
||||
String subKey = "6e4909c702f846728e64f6007736a338";
|
||||
String mixinKey = getMixinKey(imgKey, subKey);
|
||||
System.out.println(mixinKey);
|
||||
//72136226c6a73669787ee4fd02a74c27
|
||||
//{
|
||||
// foo: '114',
|
||||
// bar: '514',
|
||||
// zab: 1919810
|
||||
//}
|
||||
LinkedHashMap<String, Object> map = new LinkedHashMap<>();
|
||||
map.put("foo", "114");
|
||||
map.put("bar", "514");
|
||||
map.put("zab", 1919810);
|
||||
map.put("wts", System.currentTimeMillis() / 1000);
|
||||
StringJoiner param = new StringJoiner("&");
|
||||
//排序 + 拼接字符串
|
||||
map.entrySet().stream()
|
||||
.sorted(Map.Entry.comparingByKey())
|
||||
.forEach(entry -> param.add(entry.getKey() + "=" + entry.getValue().toString()));
|
||||
String s = param + mixinKey;
|
||||
String wbiSign = SecureUtil.md5(s);
|
||||
System.out.println(wbiSign);
|
||||
String finalParam = param + "&w_rid=" + wbiSign;
|
||||
System.out.println(finalParam);
|
||||
}
|
||||
}
|
||||
```
|
Loading…
Reference in New Issue
Block a user