|
|
|
## 打赏组件
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### 版本历史
|
|
|
|
|
|
|
|
| 版本号 | 更新时间 | 更新描述 |
|
|
|
|
| ------ | -------- | -------- |
|
|
|
|
| 1.0.0 | 2022.4.2 | 组件上线 |
|
|
|
|
| | | |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### 组件引入
|
|
|
|
|
|
|
|
注意:所有使用互动组件必须要引入basemodule库,最新版本见 [互动组件对接文档](互动组件/互动组件对接文档)
|
|
|
|
|
|
|
|
项目根目录build.gradle引入:
|
|
|
|
|
|
|
|
```groovy
|
|
|
|
repositories {
|
|
|
|
maven { url 'http://nexus-app.bokecc.com/repository/sdk-group/' }
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
module的build.gradle引入:
|
|
|
|
|
|
|
|
```java
|
|
|
|
dependencies {
|
|
|
|
api ('com.bokecc:basemodule:x.x.x')
|
|
|
|
api ('com.bokecc.module:giftmodule:x.x.x')
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
Application的onCreate方法中,调用`DWLiveEngine.init`初始化dwlivesdk后,添加代码:
|
|
|
|
|
|
|
|
```java
|
|
|
|
GiftInteractSDK.getInstance().init(app);
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## 1. 结构图
|
|
|
|
|
|
|
|
![结构图](gift.png)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## 对外参数说明
|
|
|
|
|
|
|
|
#### 对外API
|
|
|
|
|
|
|
|
```java
|
|
|
|
public interface GiftManager {
|
|
|
|
/**
|
|
|
|
* 初始化打赏模块
|
|
|
|
* @param giftListener 礼物模块回调监听
|
|
|
|
* @param userId 用户id
|
|
|
|
* @param roomId 房间id
|
|
|
|
* @param interactToken 互动组件token
|
|
|
|
* @param giftSwitch 根据直播间的配置 是走账户级礼物还是走直播间的礼物 主要用于获取礼物列表
|
|
|
|
*/
|
|
|
|
void init(GiftListener giftListener,String userId,String roomId,String interactToken,int giftSwitch);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 打赏
|
|
|
|
*/
|
|
|
|
void sendGift(int giftId,int giftNum,SendGiftCallBack sendGiftCallBack);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 重连
|
|
|
|
*/
|
|
|
|
void reConnect();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 释放
|
|
|
|
*/
|
|
|
|
void release();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取历史打赏记录
|
|
|
|
* @param historyCallBack
|
|
|
|
*/
|
|
|
|
void getGiftHistory(HistoryCallBack historyCallBack);
|
|
|
|
}
|
|
|
|
```
|
|
|
|
#### 对外回调
|
|
|
|
```java
|
|
|
|
public abstract class GiftListener {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 初始化失败
|
|
|
|
*/
|
|
|
|
public abstract void onInitFailure();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 初始化成功
|
|
|
|
*
|
|
|
|
* @param giftInfos 礼物列表
|
|
|
|
*/
|
|
|
|
public abstract void onInitSuccess(List<GiftInfo> giftInfos);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 收到打赏消息
|
|
|
|
* @param gift
|
|
|
|
*/
|
|
|
|
public abstract void onGift(Gift gift);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 打赏模块连接失败
|
|
|
|
*/
|
|
|
|
public abstract void onConnectFailure();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 打赏连接成功
|
|
|
|
*/
|
|
|
|
public void onConnect() {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public interface HistoryCallBack {
|
|
|
|
/**
|
|
|
|
* 获取成功
|
|
|
|
* @param list
|
|
|
|
*/
|
|
|
|
void onSuccess(List<Gift> list);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取失败
|
|
|
|
*/
|
|
|
|
void onFailure();
|
|
|
|
}
|
|
|
|
|
|
|
|
public interface SendGiftCallBack {
|
|
|
|
/**
|
|
|
|
* 发送成功
|
|
|
|
*/
|
|
|
|
void onSuccess();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 发送失败
|
|
|
|
*/
|
|
|
|
void onFailure();
|
|
|
|
}
|
|
|
|
```
|
|
|
|
#### 参数说明
|
|
|
|
```java
|
|
|
|
public class Gift {
|
|
|
|
//发送这名称
|
|
|
|
private String fromUserName;
|
|
|
|
//礼物图片地址
|
|
|
|
private String giftImg;
|
|
|
|
//礼物数量
|
|
|
|
private int giftNum;
|
|
|
|
//发送者的id
|
|
|
|
private String fromUserId;
|
|
|
|
//发送这的头像
|
|
|
|
private String fromUserAvatar;
|
|
|
|
//礼物名称
|
|
|
|
private String giftName;
|
|
|
|
}
|
|
|
|
|
|
|
|
public class GiftInfo {
|
|
|
|
//礼物id
|
|
|
|
public int id;
|
|
|
|
//礼物名称
|
|
|
|
public String giftName;
|
|
|
|
//礼物图片
|
|
|
|
public String giftThumbnail;
|
|
|
|
//礼物单价
|
|
|
|
public int giftPrice;
|
|
|
|
}
|
|
|
|
``` |
|
|
|
\ No newline at end of file |