feat: bili_ticket 算法 Java 实现 及 信息补充 及 错误修正 (#1061)
* feat: 空间头图及拼写错误修正 * feat(fav/info.md): code 11010 * fix(misc/sign/wbi.md): java extra params * feat(misc/sign/bili_ticket.md): description and java demo * feat(video_ranking/dynamic.md): 分区视频相关接口 * fix(video_ranking/dynamic.md): 未关闭的标签 * feat(README.md): 补充链接 * feat(clientinfo/ip.md): 查询任意 IP 地址的归属地 * feat: get buvid3 buvid4 from api * feat: new error code & format * feat(misc/picture.md): 图片格式化更多规则
This commit is contained in:
@@ -248,10 +248,9 @@ print(av2bv(avid: 111298867365120))
|
||||
print(bv2av(bvid: "BV1L9Uoa9EUx"))
|
||||
```
|
||||
|
||||
|
||||
### Java
|
||||
|
||||
```
|
||||
```java
|
||||
import java.math.BigInteger;
|
||||
|
||||
/**
|
||||
@@ -266,8 +265,7 @@ public class AVBVConverter {
|
||||
|
||||
private static final String DATA = "FcwAPNKTMug3GV5Lj7EJnHpWsx4tb8haYeviqBz6rkCy12mUSDQX9RdoZf";
|
||||
|
||||
public static String av2bv(int aidParam) {
|
||||
|
||||
public static String av2bv(long aidParam) {
|
||||
BigInteger aid = BigInteger.valueOf(aidParam);
|
||||
char[] bytes = {'B', 'V', '1', '0', '0', '0', '0', '0', '0', '0', '0', '0'};
|
||||
int bvIndex = bytes.length - 1;
|
||||
@@ -275,18 +273,14 @@ public class AVBVConverter {
|
||||
while (tmp.compareTo(BigInteger.ZERO) > 0) {
|
||||
bytes[bvIndex] = DATA.charAt(tmp.mod(BigInteger.valueOf(BASE)).intValue());
|
||||
tmp = tmp.divide(BigInteger.valueOf(BASE));
|
||||
bvIndex -= 1;
|
||||
bvIndex--;
|
||||
}
|
||||
swap(bytes, 3, 9);
|
||||
swap(bytes, 4, 7);
|
||||
StringBuilder sb = new StringBuilder(bytes.length);
|
||||
for (Character ch : bytes) {
|
||||
sb.append(ch);
|
||||
}
|
||||
return sb.toString();
|
||||
return new String(bytes);
|
||||
}
|
||||
|
||||
public static int bv2av(String bvid) {
|
||||
public static long bv2av(String bvid) {
|
||||
char[] bvidArr = bvid.toCharArray();
|
||||
swap(bvidArr, 3, 9);
|
||||
swap(bvidArr, 4, 7);
|
||||
@@ -296,7 +290,7 @@ public class AVBVConverter {
|
||||
tmp = tmp.multiply(BigInteger.valueOf(BASE)).add(BigInteger.valueOf(DATA.indexOf(c)));
|
||||
}
|
||||
BigInteger xor = tmp.and(MASK_CODE).xor(XOR_CODE);
|
||||
return xor.intValue();
|
||||
return xor.longValue();
|
||||
}
|
||||
|
||||
|
||||
@@ -314,21 +308,17 @@ public class AVBVConverter {
|
||||
final int aid2 = 305988942;
|
||||
final String bv2 = "BV1aP411K7it";
|
||||
|
||||
|
||||
//av ==> bv
|
||||
assert av2bv(aid1).equals(bv1);
|
||||
assert av2bv(aid2).equals(bv2);
|
||||
|
||||
|
||||
//bv ==>av
|
||||
assert bv2av(bv1) == aid1;
|
||||
assert bv2av(bv2) == aid2;
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
|
||||
### Golang
|
||||
|
||||
```go
|
||||
|
||||
Reference in New Issue
Block a user