确保已经拥有了该插件。
可以登录人宅学院找到该插件
如果想知道里面的技术实现 ,可以看这个 Bilibili接入技术如何实现
该插件支持三种模式来获取弹幕;
1.账户验证(推荐)
2.直连
3.HTTP获取弹幕
我们也支持发送弹幕到直播间
适合的场景:虚拟人直播,互动游戏,无人直播等
我们介绍一下账户验证获取弹幕,这种方式是极其推荐的,这也是官方主流方式
一.账户验证接入B站直播
首先我们要拿到 key 密钥 appid
1.先登录 哔哩哔哩直播服务中心 点击进入中心,确保已经注册了,如果没有注册,需要注册,一般两三天就可以收到注册成功的信息。
2.接下来需要创建项目
3.填写基础信息 项目名称 随便写一个,项目分类 直播工具,简单简介 图标等
4.创建完成后打开创建的项目,我们需要里面的 项目ID(APP ID)
5.来到这个项目页面,点击个人资料:
6.获取对应的密钥和key
接下来我们拿到code 主播身份码 打开直播姬 点击互动游戏,上面有获取身份码
至此,我们已经拿到了密钥,key, appid, 主播身份码,接下来我们进入UE界面:
7.初始化账户信息 把刚刚获取到的信息填入下面
8.绑定回调代理
9.打开对应的响应:
关于直播API的详细分析分析可以参考这个代码解释 (当前验证方式接入属于 LIVE_OPEN_PLATFORM):
UENUM(BlueprintType)
enum class EBilibiliLinkCMD :uint8
{
BilibiliLinkCMD_NONE UMETA(DisplayName = "None"),//空
//LIVE_OPEN_PLATFORM
LIVE_OPEN_PLATFORM_DM UMETA(DisplayName = "Dan Mu (LiveOpenPlatform)"),//弹幕
LIVE_OPEN_PLATFORM_SEND_GIFT UMETA(DisplayName = "Send Gift (LiveOpenPlatform)"),//发送的礼物
LIVE_OPEN_PLATFORM_SUPER_CHAT UMETA(DisplayName = "Super Chat (LiveOpenPlatform)"),//获取付费留言
LIVE_OPEN_PLATFORM_SUPER_CHAT_DEL UMETA(DisplayName = "Super Chat Del(LiveOpenPlatform)"),//获取付费留言
LIVE_OPEN_PLATFORM_GUARD UMETA(DisplayName = "Guard (LiveOpenPlatform)"),//付费大航海
LIVE_OPEN_PLATFORM_LIKE UMETA(DisplayName = "Like (LiveOpenPlatform)"),//点赞
//WebScoketCMD
WATCHED_CHANGE UMETA(DisplayName = "Watched Change (WebScoket)"),//看过的人数
WIDGET_BANNER UMETA(DisplayName = "Widget Banner (WebScoket)"),//横幅广告
STOP_LIVE_ROOM_LIST UMETA(DisplayName = "Stop Live Room List (WebScoket)"),//停止直播间列表
POPULAR_RANK_CHANGED UMETA(DisplayName = "Popular Rank Changed (WebScoket)"),//受欢迎排行变化
ONLINE_RANK_COUNT UMETA(DisplayName = "Online Rank Count (WebScoket)"),//在线排名数
LIVE_INTERACTIVE_GAME UMETA(DisplayName = "Live Interactive Game (WebScoket)"),//现场互动游戏
LIKE_INFO_V3_UPDATE UMETA(DisplayName = "Like Info V3 Update (WebScoket)"),//点赞信息更新
LIKE_INFO_V3_CLICK UMETA(DisplayName = "Like Info V3 Click (WebScoket)"),//点赞信息点击
INTERACT_WORD UMETA(DisplayName = "Interact Word (WebScoket)"),//互动词
DANMU_MSG UMETA(DisplayName = "Dan Mu (WebScoket)"),//弹幕
WELCOME UMETA(DisplayName = "Welcome (WebScoket)"),//欢迎
WELCOME_GUARD UMETA(DisplayName = "Welcome Guard (WebScoket)"),//欢迎舰长
GUARD_BUY UMETA(DisplayName = "Guard Buy (WebScoket)"),//购买舰长
USER_TOAST_MSG UMETA(DisplayName = "User Toast Msg (WebScoket)"),//续费舰长
NOTICE_MSG UMETA(DisplayName = "Notice Msg (WebScoket)"),//注意信息
PERSON_NUMBER UMETA(DisplayName = "Person Number (WebScoket)"),//人气
ENTRY_EFFECT UMETA(DisplayName = "Entry Effect (WebScoket)"),//进入效果
COMBO_SEND UMETA(DisplayName = "Combo Send (WebScoket)"),//连击礼物
COMBO_END UMETA(DisplayName = "Combo End (WebScoket)"),//连击结束
BilibiliLinkCMD_HTTP_GET UMETA(DisplayName = "HTTP Get Damu"),//通过HTTP来获取弹幕
BilibiliLinkCMD_HTTP_SEND UMETA(DisplayName = "HTTP SEN Damu"),//通过HTTP来发送弹幕
};
我们可以调用JsonStringToDanMUData:
Msg:弹幕信息
UFace:图标的http链接
EmojiImgURL:情绪图标,如果有的话
DMType:详细可以参考这个:
//弹幕类型 0:普通弹幕 1:表情包弹幕
UENUM(BlueprintType)
enum class EBilibiliDaMuType :uint8
{
NORMAL_DAMU = 0 UMETA(DisplayName = "Normal"),//普通弹幕
EMOTICON_DAMU = 1 UMETA(DisplayName = "Emoticon"),//表情包弹幕
};
关于各类返回的字符串转换,可以参考如下:
// Copyright (C) RenZhai.2023.All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "SimpleBiliBiliOpenPlatformType.h"
#include "SimpleBiliBiliOpenPlatformBPLibrary.generated.h"
UCLASS()
class SIMPLEBILIBILIOPENPLATFORM_API USimpleBiliBiliOpenPlatformBPLibrary : public UObject
{
GENERATED_UCLASS_BODY()
//live open platform
//弹幕
UFUNCTION(BlueprintCallable, meta = (DisplayName = "ToDanMUData(live open platform)"),Category = "SimpleBiliBiliOpenPlatformTesting|live open platform")
static void JsonStringToDanMUData(const FString& InJsonString, FBilibiliDanMUData& OutDanMuData);
//发送的礼物
UFUNCTION(BlueprintCallable, meta = (DisplayName = "ToSendGift(live open platform)"), Category = "SimpleBiliBiliOpenPlatformTesting|live open platform")
static void JsonStringToSendGift(const FString& InJsonString, FBilibiliSendGift& OutiSendGift);
//获取付费留言
UFUNCTION(BlueprintCallable, meta = (DisplayName = "ToSuperChat(live open platform)"), Category = "SimpleBiliBiliOpenPlatformTesting|live open platform")
static void JsonStringToSuperChat(const FString& InJsonString, FBilibiliSuperChat& OutSuperChat);
UFUNCTION(BlueprintCallable, meta = (DisplayName = "ToSuperChatDel(live open platform)"), Category = "SimpleBiliBiliOpenPlatformTesting|live open platform")
static void JsonStringToSuperChatDel(const FString& InJsonString, FBilibiliSuperChatDel& OutSuperChatDel);
//付费大航海
UFUNCTION(BlueprintCallable, meta = (DisplayName = "ToGuard(live open platform)"), Category = "SimpleBiliBiliOpenPlatformTesting|live open platform")
static void JsonStringToGuard(const FString& InJsonString, FBilibiliGuard& OutGuard);
//点赞
UFUNCTION(BlueprintCallable, meta = (DisplayName = "ToLike(live open platform)"), Category = "SimpleBiliBiliOpenPlatformTesting|live open platform")
static void JsonStringToLike(const FString& InJsonString, FBilibiliLike& OutLike);
//CMD websocket
//看过的人数
UFUNCTION(BlueprintCallable, meta = (DisplayName = "ToWatchedChange(websocket)"), Category = "SimpleBiliBiliOpenPlatformTesting|websocket")
static void JsonStringToWatchedChange(const FString& InJsonString, FBilibiliWatchedChange& OutWatchedChange);
//横幅广告
UFUNCTION(BlueprintCallable, meta = (DisplayName = "ToWidgetBanner(websocket)"), Category = "SimpleBiliBiliOpenPlatformTesting|websocket")
static void JsonStringToWidgetBanner(const FString& InJsonString, FBilibiliWidgetBanner& OutWidgetBanner);
//停止直播间列表
UFUNCTION(BlueprintCallable, meta = (DisplayName = "ToStopLiveRoomList(websocket)"), Category = "SimpleBiliBiliOpenPlatformTesting|websocket")
static void JsonStringToStopLiveRoomList(const FString& InJsonString, FBilibiliStopLiveRoomList& OutStopLiveRoomList);
//受欢迎排行变化
UFUNCTION(BlueprintCallable, meta = (DisplayName = "ToPopularRankChanged(websocket)"), Category = "SimpleBiliBiliOpenPlatformTesting|websocket")
static void JsonStringToPopularRankChanged(const FString& InJsonString, FBilibiliPopularRankChanged& OutPopularRankChanged);
//在线排名数
UFUNCTION(BlueprintCallable, meta = (DisplayName = "ToOnlineRankCount(websocket)"), Category = "SimpleBiliBiliOpenPlatformTesting|websocket")
static void JsonStringToOnlineRankCount(const FString& InJsonString, FBilibiliOnlineRankCount& OutOnlineRankCount);
//现场互动游戏
UFUNCTION(BlueprintCallable, meta = (DisplayName = "ToLiveInteractiveGame(websocket)"), Category = "SimpleBiliBiliOpenPlatformTesting|websocket")
static void JsonStringToLiveInteractiveGame(const FString& InJsonString, FBilibiliLiveInteractiveGame& OutLiveInteractiveGame);
//点赞信息更新
UFUNCTION(BlueprintCallable, meta = (DisplayName = "ToLikeInfoUpdate(websocket)"), Category = "SimpleBiliBiliOpenPlatformTesting|websocket")
static void JsonStringToLikeInfoUpdate(const FString& InJsonString, FBilibiliLikeInfoUpdate& OutLikeInfoUpdate);
//点赞信息点击
UFUNCTION(BlueprintCallable, meta = (DisplayName = "ToLikeInfoClick(websocket)"), Category = "SimpleBiliBiliOpenPlatformTesting|websocket")
static void JsonStringToLikeInfoClick(const FString& InJsonString, FBilibiliLikeInfoClick& OutLikeInfoClick);
//互动词
UFUNCTION(BlueprintCallable, meta = (DisplayName = "ToInteractWord(websocket)"), Category = "SimpleBiliBiliOpenPlatformTesting|websocket")
static void JsonStringToInteractWord(const FString& InJsonString, FBilibiliInteractWord& OutInteractWord);
//弹幕
UFUNCTION(BlueprintCallable, meta = (DisplayName = "ToDanMuMsg(websocket)"), Category = "SimpleBiliBiliOpenPlatformTesting|websocket")
static void JsonStringToDanMuMsg(const FString& InJsonString, FBilibiliDanMuMsg& OutDanMuMsg);
//购买舰长
UFUNCTION(BlueprintCallable, meta = (DisplayName = "ToGuardBuy(websocket)"), Category = "SimpleBiliBiliOpenPlatformTesting|websocket")
static void JsonStringToGuardBuy(const FString& InJsonString, FBilibiliGuardBuy& OutGuardBuy);
//续费舰长
UFUNCTION(BlueprintCallable, meta = (DisplayName = "ToUserToastMsg(websocket)"), Category = "SimpleBiliBiliOpenPlatformTesting|websocket")
static void JsonStringToUserToastMsg(const FString& InJsonString, FBilibiliUserToastMsg& OutUserToastMsg);
//人气
UFUNCTION(BlueprintCallable, meta = (DisplayName = "ToPersonNumber(websocket)"), Category = "SimpleBiliBiliOpenPlatformTesting|websocket")
static void JsonStringToPersonNumber(const FString& InJsonString, FBilibiliPersonNumber& OutPersonNumber);
UFUNCTION(BlueprintCallable, meta = (DisplayName = "ToNoticeMsg(websocket)"), Category = "SimpleBiliBiliOpenPlatformTesting|websocket")
static void JsonStringToNoticeMsg(const FString& InJsonString, FBilibiliNoticeMsg& OutNoticeMsg);
UFUNCTION(BlueprintCallable, meta = (DisplayName = "ToComboSend(websocket)"), Category = "SimpleBiliBiliOpenPlatformTesting|websocket")
static void JsonStringToComboSend(const FString& InJsonString, FBilibiliComboSend& OutComboSend);
//欢迎
UFUNCTION(BlueprintCallable, meta = (DisplayName = "ToWelcome(websocket)"), Category = "SimpleBiliBiliOpenPlatformTesting|websocket")
static void JsonStringToWelcome(const FString& InJsonString, FBilibiliWelcome& OutWelcome);
//欢迎舰长
UFUNCTION(BlueprintCallable, meta = (DisplayName = "ToWelcomeGuard(websocket)"), Category = "SimpleBiliBiliOpenPlatformTesting|websocket")
static void JsonStringToWelcomeGuard(const FString& InJsonString, FBilibiliWelcomeGuard& OutWelcomeGuard);
UFUNCTION(BlueprintCallable, meta = (DisplayName = "ToComboEnd(websocket)"), Category = "SimpleBiliBiliOpenPlatformTesting|websocket")
static void JsonStringToComboEnd(const FString& InJsonString, FBilibiliComboEnd& OutComboEnd);
//进入效果
UFUNCTION(BlueprintCallable, meta = (DisplayName = "ToEntryEffect(websocket)"), Category = "SimpleBiliBiliOpenPlatformTesting|websocket")
static void JsonStringToEntryEffect(const FString& InJsonString, FBilibiliEntryEffect& OutEntryEffect);
//其他
UFUNCTION(BlueprintCallable, meta = (DisplayName = "ToCommon(websocket)"), Category = "SimpleBiliBiliOpenPlatformTesting|websocket")
static void JsonStringToCommon(const FString& InJsonString, FBilibiliCommon& OutCommon);
//HTTP 获取弹幕
UFUNCTION(BlueprintCallable, meta = (DisplayName = "ToCommon(websocket)"), Category = "SimpleBiliBiliOpenPlatformTesting|HTTP|Get")
static void JsonStringToSimpleDanMu(const FString& InJsonString, TArray<FBilibiliSimpleDanMu>& OutSimpleDaMu);
//HTTP 发送弹幕
UFUNCTION(BlueprintCallable, meta = (DisplayName = "ToCommon(websocket)"), Category = "SimpleBiliBiliOpenPlatformTesting|HTTP|Get")
static void JsonStringToBilibiliSimpleResponse(const FString& InJsonString, FBilibiliSimpleResponse& OutResponse);
};
或者
// Copyright (C) RenZhai.2023.All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "SimpleBiliBiliOpenPlatformType.h"
namespace SimpleBilibiliJson
{
SIMPLEBILIBILIOPENPLATFORM_API EBilibiliLinkCMD JsonStringToBilibiliCMD(const FString& InJsonString);
SIMPLEBILIBILIOPENPLATFORM_API EBilibiliLinkCMD StringToBilibiliCMD(const FString& InCMDValue);
SIMPLEBILIBILIOPENPLATFORM_API FString BilibiliCMDToString(EBilibiliLinkCMD InCMD);
//live open platform
SIMPLEBILIBILIOPENPLATFORM_API void JsonStringToDanMUData(const FString& InJsonString, FBilibiliDanMUData& OutDanMuData);
SIMPLEBILIBILIOPENPLATFORM_API void JsonStringToSendGift(const FString& InJsonString, FBilibiliSendGift& OutiSendGift);
SIMPLEBILIBILIOPENPLATFORM_API void JsonStringToSuperChat(const FString& InJsonString, FBilibiliSuperChat& OutSuperChat);
SIMPLEBILIBILIOPENPLATFORM_API void JsonStringToSuperChatDel(const FString& InJsonString, FBilibiliSuperChatDel& OutSuperChatDel);
SIMPLEBILIBILIOPENPLATFORM_API void JsonStringToGuard(const FString& InJsonString, FBilibiliGuard& OutGuard);
SIMPLEBILIBILIOPENPLATFORM_API void JsonStringToLike(const FString& InJsonString, FBilibiliLike& OutLike);
//CMD websocket
SIMPLEBILIBILIOPENPLATFORM_API void JsonStringToWatchedChange(const FString& InJsonString, FBilibiliWatchedChange& OutWatchedChange);
SIMPLEBILIBILIOPENPLATFORM_API void JsonStringToWidgetBanner(const FString& InJsonString, FBilibiliWidgetBanner& OutWidgetBanner);
SIMPLEBILIBILIOPENPLATFORM_API void JsonStringToStopLiveRoomList(const FString& InJsonString, FBilibiliStopLiveRoomList& OutStopLiveRoomList);
SIMPLEBILIBILIOPENPLATFORM_API void JsonStringToPopularRankChanged(const FString& InJsonString, FBilibiliPopularRankChanged& OutPopularRankChanged);
SIMPLEBILIBILIOPENPLATFORM_API void JsonStringToOnlineRankCount(const FString& InJsonString, FBilibiliOnlineRankCount& OutOnlineRankCount);
SIMPLEBILIBILIOPENPLATFORM_API void JsonStringToLiveInteractiveGame(const FString& InJsonString, FBilibiliLiveInteractiveGame& OutLiveInteractiveGame);
SIMPLEBILIBILIOPENPLATFORM_API void JsonStringToLikeInfoUpdate(const FString& InJsonString, FBilibiliLikeInfoUpdate& OutLikeInfoUpdate);
SIMPLEBILIBILIOPENPLATFORM_API void JsonStringToLikeInfoClick(const FString& InJsonString, FBilibiliLikeInfoClick& OutLikeInfoClick);
SIMPLEBILIBILIOPENPLATFORM_API void JsonStringToInteractWord(const FString& InJsonString, FBilibiliInteractWord& OutInteractWord);
SIMPLEBILIBILIOPENPLATFORM_API void JsonStringToDanMuMsg(const FString& InJsonString, FBilibiliDanMuMsg& OutDanMuMsg);
SIMPLEBILIBILIOPENPLATFORM_API void JsonStringToGuardBuy(const FString& InJsonString, FBilibiliGuardBuy& OutGuardBuy);
SIMPLEBILIBILIOPENPLATFORM_API void JsonStringToUserToastMsg(const FString& InJsonString, FBilibiliUserToastMsg& OutUserToastMsg);
SIMPLEBILIBILIOPENPLATFORM_API void JsonStringToPersonNumber(const FString& InJsonString, FBilibiliPersonNumber& OutPersonNumber);
SIMPLEBILIBILIOPENPLATFORM_API void JsonStringToNoticeMsg(const FString& InJsonString, FBilibiliNoticeMsg& OutNoticeMsg);
SIMPLEBILIBILIOPENPLATFORM_API void JsonStringToComboSend(const FString& InJsonString, FBilibiliComboSend& OutComboSend);
SIMPLEBILIBILIOPENPLATFORM_API void JsonStringToWelcome(const FString& InJsonString, FBilibiliWelcome& OutWelcome);
SIMPLEBILIBILIOPENPLATFORM_API void JsonStringToWelcomeGuard(const FString& InJsonString, FBilibiliWelcomeGuard& OutWelcomeGuard);
SIMPLEBILIBILIOPENPLATFORM_API void JsonStringToComboEnd(const FString& InJsonString, FBilibiliComboEnd& OutComboEnd);
SIMPLEBILIBILIOPENPLATFORM_API void JsonStringToEntryEffect(const FString& InJsonString, FBilibiliEntryEffect& OutEntryEffect);
//其他
SIMPLEBILIBILIOPENPLATFORM_API void JsonStringToCommon(const FString& InJsonString, FBilibiliCommon& OutCommon);
//解析弹幕
SIMPLEBILIBILIOPENPLATFORM_API void JsonStringToSimpleDanMu(const FString& InJsonString, TArray<FBilibiliSimpleDanMu>& OutSimpleDaMu);
//验签的响应
SIMPLEBILIBILIOPENPLATFORM_API void JsonStringToBiliSigVerificationResponse(const FString& InJsonString, FBiliSigVerificationResponse& OutResponse);
//发送弹幕
SIMPLEBILIBILIOPENPLATFORM_API void BilibiliSimpleSendDanMuDataToArrayString(const FString &InBoundary,const FBilibiliSimpleSendDanMuData& InDanMuData, TArray<FString>& BuildData);
//针对响应
SIMPLEBILIBILIOPENPLATFORM_API void JsonStringToBilibiliSimpleResponse(const FString &InJsonString,FBilibiliSimpleResponse &OutResponse);
}
最后,可以使用Start开始弹幕捕获 用Stop停止弹幕捕获:
验证链接方式,就讲解完毕了。
二.通过HTTP获取弹幕
1.可以通过房间ID直接链接房间,获取弹幕:
2.可以通过JsonStringToSimpleDanMu 获取转换的弹幕信息
3.房间ID获取:
就是这个/14614095? ,/和?中间的那个就是房间ID(RoomID)
至此,HTTP直链的方式我们讲解完毕了。
三.如何发送弹幕
发送弹幕,严格来说不是官方的app,官方也没有讲解如何发送,这里我们通过其他方式来是实现发送弹幕:
首先保证拥有谷歌浏览器,因为我们要获取到几个重要的参数:
1.首先进入浏览器,进入直播间,按F12,进入调试模式,点击红点,发一个弹幕,捕捉了一个send。
2.来到负载这个位置,这里显示了roomid和csrf以及csrf_token,这些我们后面会用到,先记录一下。
3.接下来来到Headers里面,我们需要cookie和user-agent这两个数据,复制一下,后面用到。
4.接下来我们进入UE里面,构建如下的信息:
5.发送弹幕到直播间
6.这个对应发送到直播间后,对应的回调:
7.记得绑定代理:
至此,我们的发送弹幕也完结了。
发表回复
要发表评论,您必须先登录。