diff --git a/src/main/java/com/hiczp/bilibili/api/BaseUrlDefinition.java b/src/main/java/com/hiczp/bilibili/api/BaseUrlDefinition.java index 42cd128..f6342e2 100644 --- a/src/main/java/com/hiczp/bilibili/api/BaseUrlDefinition.java +++ b/src/main/java/com/hiczp/bilibili/api/BaseUrlDefinition.java @@ -2,5 +2,5 @@ package com.hiczp.bilibili.api; public class BaseUrlDefinition { public static final String PASSPORT = "https://passport.bilibili.com/"; - public static final String LIVE = "http://api.live.bilibili.com/"; + public static final String LIVE = "https://api.live.bilibili.com/"; } diff --git a/src/main/java/com/hiczp/bilibili/api/live/LiveService.java b/src/main/java/com/hiczp/bilibili/api/live/LiveService.java index 3a5d1c4..0747fb6 100644 --- a/src/main/java/com/hiczp/bilibili/api/live/LiveService.java +++ b/src/main/java/com/hiczp/bilibili/api/live/LiveService.java @@ -18,13 +18,16 @@ public interface LiveService { return getBulletScreenConfig("all"); } + //获得房间的历史弹幕(十条) @GET("AppRoom/msg") Call getHistoryBulletScreens(@Query("room_id") long roomId); + //获取房间信息 //登录后访问该 API 将在服务器新增一条直播间观看历史 @GET("AppRoom/index") Call getRoomInfo(@Query("room_id") long roomId); + //获得是否关注了一个主播 //未登录时返回 401 @POST("feed/v1/feed/isFollowed") Call isFollowed(@Query("follow") long hostUserId); @@ -33,6 +36,7 @@ public interface LiveService { @GET("AppBag/sendDaily") Call sendDaily(); + //获得所有礼物的列表 @GET("AppIndex/getAllItem") Call getAllItem(); @@ -40,6 +44,7 @@ public interface LiveService { @GET("AppSmallTV/index") Call getAppSmallTV(); + //获得所有头衔的列表 //这里的 Title 是头衔的意思 @GET("appUser/getTitle") Call getTitle(); @@ -48,10 +53,12 @@ public interface LiveService { @GET("SpecialGift/room/{roomId}") Call getSpecialGift(@Path("roomId") long roomId); + //获取自己的用户信息(live 站的个人信息, 非总站) //未登录时返回 3 @GET("mobile/getUser") Call getUserInfo(); + //获取一个直播间的流地址(flv) //这里的 cid 必须用实际的 room_id, 不能使用 show_room_id, 否则得不到 playUrl. 实际 room_id 要首先通过 getRoomInfo() 获取 //outputType 为固定值 "json", 否则返回一个空的 JsonArray (以前是返回一个 XML) @GET("api/playurl") @@ -61,6 +68,7 @@ public interface LiveService { return getPlayUrl(cid, "json"); } + //发送一个 Restful 的心跳包, 五分钟一次. 这被用于统计观看直播的时间, 可以提升观众等级 //未登录时返回 3 @POST("mobile/userOnlineHeart") @FormUrlEncoded @@ -70,6 +78,7 @@ public interface LiveService { return sendOnlineHeart(roomId, BilibiliClientProperties.defaultSetting().getScale()); } + //发送一条弹幕 @POST("api/sendmsg") @FormUrlEncoded Call sendBulletScreen(@Field("cid") long cid, @@ -98,18 +107,23 @@ public interface LiveService { ); } + //获取下一个宝箱任务的信息 @GET("mobile/freeSilverCurrentTask") Call getFreeSilverCurrentTask(); + //领取宝箱 @GET("mobile/freeSilverAward") Call getFreeSilverAward(); + //查看自己的背包(礼物) @GET("AppBag/playerBag") Call getPlayerBag(); + //查看哪些礼物是活动礼物, 在客户端上, 活动礼物会有一个右上角标记 "活动" @GET("AppRoom/activityGift") Call getActivityGifts(@Query("room_id") long roomId); + //送礼物 @POST("AppBag/send") @FormUrlEncoded Call sendGift(@Field("giftId") long giftId, @@ -132,18 +146,21 @@ public interface LiveService { ); } + //获得礼物榜(七日榜) @GET("AppRoom/getGiftTop") Call getGiftTop(@Query("room_id") int roomId); + //签到(live 站签到, 非总站(虽然我也不知道总站有没有签到功能))(侧拉抽屉 -> 直播中心 -> 右上角日历图标) //无论是否已经签到, 返回的 code 都是 0. 除了字符串比对, 要想知道是否已经签到要通过 getUserInfo().getIsSign() @GET("AppUser/getSignInfo") Call getSignInfo(); - //获得关注列表("关注主播" 页面) + //获得关注列表(直播 -> 关注) //未登录时返回 32205 @GET("AppFeed/index") Call getFollowedHosts(@Query("page") long page, @Query("pagesize") long pageSize); + //live 站的搜索 //type 为 room 时只返回 房间 的搜索结果 //type 为 user 时只返回 用户 的搜索结果 //type 为 all 时 房间 与 用户 的搜索结果都有 @@ -157,4 +174,13 @@ public interface LiveService { //"直播" 页面下面的推荐, 每个分类有六个的那种 @GET("mobile/rooms") Call getRooms(); + + //侧拉抽屉 -> 直播中心 -> 佩戴中心 + //获得用户拥有的头衔 + @GET("appUser/myTitleList") + Call getMyTitleList(); + + //佩戴头衔 + @GET("AppUser/wearTitle") + Call wearTitle(@Query("title") String title); } diff --git a/src/main/java/com/hiczp/bilibili/api/live/entity/MyTitleListEntity.java b/src/main/java/com/hiczp/bilibili/api/live/entity/MyTitleListEntity.java new file mode 100644 index 0000000..e1568ef --- /dev/null +++ b/src/main/java/com/hiczp/bilibili/api/live/entity/MyTitleListEntity.java @@ -0,0 +1,295 @@ +package com.hiczp.bilibili.api.live.entity; + +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class MyTitleListEntity { + /** + * code : 0 + * message : 获取成功 + * data : {"list":[{"uid":2866663,"had":true,"title":"title-111-1","status":0,"activity":"2017Blink","score":0,"level":[],"category":[{"name":"热门","class":"red"}],"title_pic":{"id":"title-111-1","title":"2017Blink","img":"https://s1.hdslb.com/bfs/static/blive/live-assets/mobile/titles/title/3/title-111-1.png?20171116172700","width":0,"height":0,"is_lihui":0,"lihui_img":"","lihui_width":0,"lihui_height":0}}]} + */ + + @SerializedName("code") + private int code; + @SerializedName("message") + private String message; + @SerializedName("data") + private Data data; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public Data getData() { + return data; + } + + public void setData(Data data) { + this.data = data; + } + + public static class Data { + @SerializedName("list") + private List list; + + public List<Title> getList() { + return list; + } + + public void setList(List<Title> list) { + this.list = list; + } + + public static class Title { + /** + * uid : 2866663 + * had : true + * title : title-111-1 + * status : 0 + * activity : 2017Blink + * score : 0 + * level : [] + * category : [{"name":"热门","class":"red"}] + * title_pic : {"id":"title-111-1","title":"2017Blink","img":"https://s1.hdslb.com/bfs/static/blive/live-assets/mobile/titles/title/3/title-111-1.png?20171116172700","width":0,"height":0,"is_lihui":0,"lihui_img":"","lihui_width":0,"lihui_height":0} + */ + + @SerializedName("uid") + private int uid; + @SerializedName("had") + private boolean had; + @SerializedName("title") + private String title; + @SerializedName("status") + private int status; + @SerializedName("activity") + private String activity; + @SerializedName("score") + private int score; + @SerializedName("title_pic") + private TitlePic titlePic; + @SerializedName("level") + private List<?> level; + @SerializedName("category") + private List<Category> category; + + public int getUid() { + return uid; + } + + public void setUid(int uid) { + this.uid = uid; + } + + public boolean isHad() { + return had; + } + + public void setHad(boolean had) { + this.had = had; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public int getStatus() { + return status; + } + + public void setStatus(int status) { + this.status = status; + } + + public String getActivity() { + return activity; + } + + public void setActivity(String activity) { + this.activity = activity; + } + + public int getScore() { + return score; + } + + public void setScore(int score) { + this.score = score; + } + + public TitlePic getTitlePic() { + return titlePic; + } + + public void setTitlePic(TitlePic titlePic) { + this.titlePic = titlePic; + } + + public List<?> getLevel() { + return level; + } + + public void setLevel(List<?> level) { + this.level = level; + } + + public List<Category> getCategory() { + return category; + } + + public void setCategory(List<Category> category) { + this.category = category; + } + + public static class TitlePic { + /** + * id : title-111-1 + * title : 2017Blink + * img : https://s1.hdslb.com/bfs/static/blive/live-assets/mobile/titles/title/3/title-111-1.png?20171116172700 + * width : 0 + * height : 0 + * is_lihui : 0 + * lihui_img : + * lihui_width : 0 + * lihui_height : 0 + */ + + @SerializedName("id") + private String id; + @SerializedName("title") + private String title; + @SerializedName("img") + private String img; + @SerializedName("width") + private int width; + @SerializedName("height") + private int height; + @SerializedName("is_lihui") + private int isLihui; + @SerializedName("lihui_img") + private String lihuiImg; + @SerializedName("lihui_width") + private int lihuiWidth; + @SerializedName("lihui_height") + private int lihuiHeight; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getImg() { + return img; + } + + public void setImg(String img) { + this.img = img; + } + + public int getWidth() { + return width; + } + + public void setWidth(int width) { + this.width = width; + } + + public int getHeight() { + return height; + } + + public void setHeight(int height) { + this.height = height; + } + + public int getIsLihui() { + return isLihui; + } + + public void setIsLihui(int isLihui) { + this.isLihui = isLihui; + } + + public String getLihuiImg() { + return lihuiImg; + } + + public void setLihuiImg(String lihuiImg) { + this.lihuiImg = lihuiImg; + } + + public int getLihuiWidth() { + return lihuiWidth; + } + + public void setLihuiWidth(int lihuiWidth) { + this.lihuiWidth = lihuiWidth; + } + + public int getLihuiHeight() { + return lihuiHeight; + } + + public void setLihuiHeight(int lihuiHeight) { + this.lihuiHeight = lihuiHeight; + } + } + + public static class Category { + /** + * name : 热门 + * class : red + */ + + @SerializedName("name") + private String name; + @SerializedName("class") + private String classX; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getClassX() { + return classX; + } + + public void setClassX(String classX) { + this.classX = classX; + } + } + } + } +} diff --git a/src/main/java/com/hiczp/bilibili/api/live/entity/WearTitleResponseEntity.java b/src/main/java/com/hiczp/bilibili/api/live/entity/WearTitleResponseEntity.java new file mode 100644 index 0000000..aa03ded --- /dev/null +++ b/src/main/java/com/hiczp/bilibili/api/live/entity/WearTitleResponseEntity.java @@ -0,0 +1,44 @@ +package com.hiczp.bilibili.api.live.entity; + +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class WearTitleResponseEntity { + /** + * code : 0 + * message : 佩戴成功 + * data : [] + */ + + @SerializedName("code") + private int code; + @SerializedName("message") + private String message; + @SerializedName("data") + private List<?> data; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public List<?> getData() { + return data; + } + + public void setData(List<?> data) { + this.data = data; + } +} diff --git a/src/test/java/com/hiczp/bilibili/api/test/ManualLoginTool.java b/src/test/java/com/hiczp/bilibili/api/test/ManualLoginTool.java index 6868dc9..bce4651 100644 --- a/src/test/java/com/hiczp/bilibili/api/test/ManualLoginTool.java +++ b/src/test/java/com/hiczp/bilibili/api/test/ManualLoginTool.java @@ -2,18 +2,21 @@ package com.hiczp.bilibili.api.test; import com.google.gson.GsonBuilder; import com.hiczp.bilibili.api.BilibiliAPI; +import com.hiczp.bilibili.api.BilibiliSecurityHelper; import com.hiczp.bilibili.api.passport.entity.LoginResponseEntity; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + +import java.util.Scanner; public class ManualLoginTool { - private static final Logger LOGGER = LoggerFactory.getLogger(ManualLoginTool.class); - public static void main(String[] args) throws Exception { - RuleSuite.init(); - Config config = Config.getInstance(); - LoginResponseEntity loginResponseEntity = new BilibiliAPI() - .login(config.getUsername(), config.getPassword()); - LOGGER.info(new GsonBuilder().setPrettyPrinting().create().toJson(loginResponseEntity)); + Scanner scanner = new Scanner(System.in); + System.out.println("Please input username and password"); + LoginResponseEntity loginResponseEntity = BilibiliSecurityHelper + .login(new BilibiliAPI(), scanner.nextLine(), scanner.nextLine()); + + new GsonBuilder() + .setPrettyPrinting() + .create() + .toJson(loginResponseEntity, System.out); } }