更新 README

This commit is contained in:
czp 2018-02-01 09:45:37 +08:00
parent e7c79b7fe1
commit 8b79cff89e
5 changed files with 46 additions and 2 deletions

View File

@ -97,6 +97,24 @@ LoginException 在 accessToken 错误或过期时抛出
liveHistoryBulletScreenEntity.getText())
);
发送一条弹幕到指定直播间
String username = "yourUsername";
String password = "yourPassword";
int roomId = 3;
BilibiliAPI bilibiliAPI = new BilibiliAPI()
.login(username, password);
bilibiliAPI.getLiveService()
.sendBulletScreen(
new BulletScreenEntity(
roomId,
bilibiliAPI.getBilibiliAccount().getUserId(), //实际上并不需要包含 mid 就可以正常发送弹幕, 但是真实的 Android 客户端确实发送了 mid
"这是自动发送的弹幕"
)
).execute();
(如果要调用需要鉴权的 API, 需要先登录)
API 文档
@ -116,6 +134,8 @@ API 文档
(connect 以及 close 方法都是阻塞的)
使用 .getLiveClient() 前可以先登录也可以不登陆直接用, 如果 API 已经登录, 那么进房数据包中会带有用户ID, 尚不明确有什么作用, 可能与一些统计有关.
(connect 方法运行结束只代表 socket 确实是连上了, 但是服务器还没有响应进房请求数据包)
(当服务器响应进房请求数据包时才代表真的连上了, 此时会有一个连接成功的事件, 见下文)

View File

@ -37,6 +37,7 @@ public class BulletScreenEntity {
private String playTime = "0.0";
//实际上并不需要包含 mid 就可以正常发送弹幕, 但是真实的 Android 客户端确实发送了 mid
public BulletScreenEntity(long cid, long mid, String message) {
this.cid = cid;
this.mid = mid;

View File

@ -18,7 +18,7 @@ import java.util.List;
public class LiveClientTest {
private static final Logger LOGGER = LoggerFactory.getLogger(LiveClientTest.class);
private static final BilibiliAPI BILIBILI_API = Config.getBilibiliAPI();
private static final int ROOM_ID = 3;
private static final long ROOM_ID = 3;
private static final long TEST_TIME = 70 * 1000;
@Ignore

View File

@ -16,7 +16,8 @@ import java.io.InputStreamReader;
@Suite.SuiteClasses({
UserInfoTest.class,
LiveClientTest.class,
SsoTest.class
SsoTest.class,
SendBulletScreenTest.class
})
public class RuleSuite {
@ClassRule

View File

@ -0,0 +1,22 @@
package com.hiczp.bilibili.api.test;
import com.hiczp.bilibili.api.BilibiliAPI;
import com.hiczp.bilibili.api.live.entity.BulletScreenEntity;
import org.junit.Test;
public class SendBulletScreenTest {
private static final long ROOM_ID = 29434;
private static final BilibiliAPI BILIBILI_API = Config.getBilibiliAPI();
@Test
public void sendBulletScreen() throws Exception {
BILIBILI_API.getLiveService()
.sendBulletScreen(
new BulletScreenEntity(
ROOM_ID,
BILIBILI_API.getBilibiliAccount().getUserId(),
"这是自动发送的弹幕"
)
).execute();
}
}