mirror of
https://github.com/czp3009/bilibili-api.git
synced 2025-02-19 20:50:28 +08:00
BilibiliAPI 现在可以自定义是否自动刷新 Token
This commit is contained in:
parent
4d2ae98561
commit
72ea245c7f
@ -40,6 +40,8 @@ public class BilibiliAPI implements BilibiliServiceProvider, BilibiliCaptchaProv
|
||||
private final BilibiliClientProperties bilibiliClientProperties;
|
||||
private final BilibiliAccount bilibiliAccount;
|
||||
|
||||
private Boolean autoRefreshToken = true;
|
||||
|
||||
//用于阻止进行多次错误的 refreshToken 操作
|
||||
private String invalidToken;
|
||||
private String invalidRefreshToken;
|
||||
@ -142,8 +144,9 @@ public class BilibiliAPI implements BilibiliServiceProvider, BilibiliCaptchaProv
|
||||
() -> "trace_id", () -> new SimpleDateFormat("yyyyMMddHHmm000ss").format(new Date())
|
||||
))
|
||||
.addInterceptor(new AddAppKeyInterceptor(bilibiliClientProperties))
|
||||
.addInterceptor(new RefreshTokenInterceptor(
|
||||
.addInterceptor(new AutoRefreshTokenInterceptor(
|
||||
this,
|
||||
autoRefreshToken,
|
||||
ServerErrorCode.Common.UNAUTHORIZED,
|
||||
ServerErrorCode.Live.USER_NO_LOGIN,
|
||||
ServerErrorCode.Live.PLEASE_LOGIN,
|
||||
@ -401,4 +404,13 @@ public class BilibiliAPI implements BilibiliServiceProvider, BilibiliCaptchaProv
|
||||
public BilibiliAccount getBilibiliAccount() {
|
||||
return bilibiliAccount;
|
||||
}
|
||||
|
||||
public boolean isAutoRefreshToken() {
|
||||
return autoRefreshToken;
|
||||
}
|
||||
|
||||
public BilibiliAPI setAutoRefreshToken(boolean autoRefreshToken) {
|
||||
this.autoRefreshToken = autoRefreshToken;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
@ -13,14 +13,16 @@ import java.io.IOException;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
//自动刷新 token
|
||||
public class RefreshTokenInterceptor implements Interceptor {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(RefreshTokenInterceptor.class);
|
||||
public class AutoRefreshTokenInterceptor implements Interceptor {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AutoRefreshTokenInterceptor.class);
|
||||
|
||||
private BilibiliAPI bilibiliAPI;
|
||||
private Boolean autoRefreshToken;
|
||||
private int[] codes;
|
||||
|
||||
public RefreshTokenInterceptor(BilibiliAPI bilibiliAPI, int... codes) {
|
||||
public AutoRefreshTokenInterceptor(BilibiliAPI bilibiliAPI, Boolean autoRefreshToken, int... codes) {
|
||||
this.bilibiliAPI = bilibiliAPI;
|
||||
this.autoRefreshToken = autoRefreshToken;
|
||||
this.codes = codes;
|
||||
}
|
||||
|
||||
@ -28,6 +30,10 @@ public class RefreshTokenInterceptor implements Interceptor {
|
||||
public Response intercept(Chain chain) throws IOException {
|
||||
Response response = chain.proceed(chain.request());
|
||||
|
||||
if (!autoRefreshToken) {
|
||||
return response;
|
||||
}
|
||||
|
||||
JsonObject jsonObject = InterceptorHelper.getJsonInBody(response);
|
||||
JsonElement codeElement = jsonObject.get("code");
|
||||
if (codeElement == null) {
|
@ -32,7 +32,7 @@ public interface LiveService {
|
||||
@POST("feed/v1/feed/isFollowed")
|
||||
Call<IsFollowedResponseEntity> isFollowed(@Query("follow") long hostUserId);
|
||||
|
||||
//该 API 意义不明
|
||||
//该 API 意义不明(似乎跟什么 每日背包任务 有关)
|
||||
@GET("AppBag/sendDaily")
|
||||
Call<SendDailyResponseEntity> sendDaily();
|
||||
|
||||
@ -40,16 +40,19 @@ public interface LiveService {
|
||||
@GET("AppIndex/getAllItem")
|
||||
Call<ItemsEntity> getAllItem();
|
||||
|
||||
//该 API 的返回值意义不明确, 所有房间似乎都一样, 且返回的 code 为 -400
|
||||
//查看可用的小电视抽奖
|
||||
//当目标房间没有可用的小电视抽奖时返回 -400
|
||||
@GET("AppSmallTV/index")
|
||||
Call<AppSmallTVEntity> getAppSmallTV();
|
||||
Call<AppSmallTVEntity> getAppSmallTV(@Query("roomid") long roomId);
|
||||
//TODO 参与抽奖
|
||||
//TODO 查看抽奖结果
|
||||
|
||||
//获得所有头衔的列表
|
||||
//这里的 Title 是头衔的意思
|
||||
@GET("appUser/getTitle")
|
||||
Call<TitlesEntity> getTitle();
|
||||
|
||||
//这个 API 不是很明确, 所有房间都一样, 可能和什么活动有关
|
||||
//这个 API 不是很明确, 似乎和 节奏风暴 有关系
|
||||
@GET("SpecialGift/room/{roomId}")
|
||||
Call<SpecialGiftEntity> getSpecialGift(@Path("roomId") long roomId);
|
||||
|
||||
|
@ -2,19 +2,24 @@ package com.hiczp.bilibili.api.live.entity;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class AppSmallTVEntity {
|
||||
/**
|
||||
* code : -400
|
||||
* message : no
|
||||
* data : {"status":-1}
|
||||
* code : 0
|
||||
* msg : OK
|
||||
* message : OK
|
||||
* data : {"lastid":0,"join":[{"id":39674,"dtime":32}],"unjoin":[{"id":39674,"dtime":32}]}
|
||||
*/
|
||||
|
||||
@SerializedName("code")
|
||||
private int code;
|
||||
@SerializedName("msg")
|
||||
private String msg;
|
||||
@SerializedName("message")
|
||||
private String message;
|
||||
@SerializedName("data")
|
||||
private DataEntity data;
|
||||
private Data data;
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
@ -24,6 +29,14 @@ public class AppSmallTVEntity {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
public void setMsg(String msg) {
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
@ -32,28 +45,106 @@ public class AppSmallTVEntity {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public DataEntity getData() {
|
||||
public Data getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(DataEntity data) {
|
||||
public void setData(Data data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public static class DataEntity {
|
||||
public static class Data {
|
||||
/**
|
||||
* status : -1
|
||||
* lastid : 0
|
||||
* join : [{"id":39674,"dtime":32}]
|
||||
* unjoin : [{"id":39674,"dtime":32}]
|
||||
*/
|
||||
|
||||
@SerializedName("status")
|
||||
private int status;
|
||||
@SerializedName("lastid")
|
||||
private int lastid;
|
||||
@SerializedName("join")
|
||||
private List<Join> join;
|
||||
@SerializedName("unjoin")
|
||||
private List<Unjoin> unjoin;
|
||||
|
||||
public int getStatus() {
|
||||
return status;
|
||||
public int getLastid() {
|
||||
return lastid;
|
||||
}
|
||||
|
||||
public void setStatus(int status) {
|
||||
this.status = status;
|
||||
public void setLastid(int lastid) {
|
||||
this.lastid = lastid;
|
||||
}
|
||||
|
||||
public List<Join> getJoin() {
|
||||
return join;
|
||||
}
|
||||
|
||||
public void setJoin(List<Join> join) {
|
||||
this.join = join;
|
||||
}
|
||||
|
||||
public List<Unjoin> getUnjoin() {
|
||||
return unjoin;
|
||||
}
|
||||
|
||||
public void setUnjoin(List<Unjoin> unjoin) {
|
||||
this.unjoin = unjoin;
|
||||
}
|
||||
|
||||
public static class Join {
|
||||
/**
|
||||
* id : 39674
|
||||
* dtime : 32
|
||||
*/
|
||||
|
||||
@SerializedName("id")
|
||||
private int id;
|
||||
@SerializedName("dtime")
|
||||
private int dtime;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getDtime() {
|
||||
return dtime;
|
||||
}
|
||||
|
||||
public void setDtime(int dtime) {
|
||||
this.dtime = dtime;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Unjoin {
|
||||
/**
|
||||
* id : 39674
|
||||
* dtime : 32
|
||||
*/
|
||||
|
||||
@SerializedName("id")
|
||||
private int id;
|
||||
@SerializedName("dtime")
|
||||
private int dtime;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getDtime() {
|
||||
return dtime;
|
||||
}
|
||||
|
||||
public void setDtime(int dtime) {
|
||||
this.dtime = dtime;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,8 @@ public class BulletScreenEntity {
|
||||
|
||||
private long mid;
|
||||
|
||||
//弹幕长度限制为 LiveRoomInfoEntity.getData().getMsgLength(), 但是实际上所有房间的弹幕长度限制都是 20
|
||||
//弹幕长度限制为 LiveRoomInfoEntity.getData().getMsgLength(), 对于每个用户而言, 每个房间都一样
|
||||
//通过完成 B站 有关任务, 获得成就, 可以加大这个限制(舰长, 老爷等可以直接加大限制), 最长好像是 40 个字
|
||||
@SerializedName("msg")
|
||||
private String message;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user