|
|
|
## 红包雨组件
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### 版本历史
|
|
|
|
|
|
|
|
| 版本号 | 更新时间 | 更新描述 |
|
|
|
|
| ------ | ---------- | -------------- |
|
|
|
|
| 1.0.1 | 2022.5.7 | 红包雨组件上线 |
|
|
|
|
| 1.0.2 | 2022.11.24 | 支持自定义封面 |
|
|
|
|
| | | |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### 组件引入
|
|
|
|
|
|
|
|
注意:所有使用互动组件必须要引入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:redpacketmodule:x.x.x')
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
Application的onCreate方法中,调用`DWLiveEngine.init`初始化dwlivesdk后,添加代码:
|
|
|
|
|
|
|
|
```java
|
|
|
|
RedPacketInteractSDK.getInstance().init(app);
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### 1. 组件描述
|
|
|
|
|
|
|
|
红包雨组件是基于基础组件库扩展的红包雨组件服务,通过IM组件实现红包雨活动事件的实时推送,包括接收红包雨事件,查询红包雨详情、提交红包雨结果等功能,为业务方提供红包雨能力。红包雨组件包含管理器和基于管理器实现的UI界面,接入方可基于管理器对外API实现完全自定义UI的红包雨,也可直接集成组件SDK提供的UI。
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### 2. 组件架构
|
|
|
|
|
|
|
|
#### 2.1 组件架构图
|
|
|
|
|
|
|
|
![image-20220506100931572](组件架构图.png)
|
|
|
|
|
|
|
|
#### 2.2 核心对外API
|
|
|
|
|
|
|
|
IRedPacketManager内部唯一实现类为RedPacketManagerImpl
|
|
|
|
|
|
|
|
| 作用 | API |
|
|
|
|
| ---------------- | ------------------------------------------------------------ |
|
|
|
|
| 初始化 | init(BaseRedPacketListener listener, String userId, String roomId, String interactToken) |
|
|
|
|
| 发送礼物 | robRed(String redActivityId, IBaseCallBack<RobRedBean> sendVoteCallBack) |
|
|
|
|
| 红包结果列表 | getRankList(String redActivityId, IBaseCallBack<RankListBean> voteListCallBack) |
|
|
|
|
| 获取用户红包记录 | getUserRecord(IBaseCallBack<UserRecordBean> historyCallBack) |
|
|
|
|
| 获取红包详情 | getRedDetail(String redActivityId, IBaseCallBack<RedPacketBean> historyCallBack) |
|
|
|
|
| 重连 | reConnect() |
|
|
|
|
| 释放 | release() |
|
|
|
|
|
|
|
|
API接口代码
|
|
|
|
|
|
|
|
```java
|
|
|
|
public interface IRedPacketManager {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param listener 监听
|
|
|
|
* @param userId viewerId
|
|
|
|
* @param roomId 房间id
|
|
|
|
* @param interactToken token
|
|
|
|
*/
|
|
|
|
void init(BaseRedPacketListener listener, String userId, String roomId, String interactToken);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 抢红包
|
|
|
|
*
|
|
|
|
* @param redActivityId 红包雨活动id
|
|
|
|
* @param sendVoteCallBack 回调
|
|
|
|
*/
|
|
|
|
void robRed(String redActivityId, IBaseCallBack<RobRedBean> sendVoteCallBack);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 红包结果列表
|
|
|
|
*
|
|
|
|
* @param redActivityId 红包雨活动id
|
|
|
|
* @param voteListCallBack 回调
|
|
|
|
*/
|
|
|
|
void getRankList(String redActivityId, IBaseCallBack<RankListBean> voteListCallBack);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取用户红包记录
|
|
|
|
*
|
|
|
|
* @param historyCallBack 回调
|
|
|
|
*/
|
|
|
|
void getUserRecord(IBaseCallBack<UserRecordBean> historyCallBack);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取红包详情
|
|
|
|
*
|
|
|
|
* @param redActivityId 红包雨活动id
|
|
|
|
* @param historyCallBack 回调
|
|
|
|
*/
|
|
|
|
void getRedDetail(String redActivityId, IBaseCallBack<RedPacketBean> historyCallBack);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 重连
|
|
|
|
*/
|
|
|
|
void reConnect();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 释放
|
|
|
|
*/
|
|
|
|
void release();
|
|
|
|
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
#### 2.3 数据参数定义
|
|
|
|
|
|
|
|
数据类参数说明
|
|
|
|
|
|
|
|
#####
|
|
|
|
|
|
|
|
```java
|
|
|
|
public class RankListBean {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 本人中奖总金额 分
|
|
|
|
*/
|
|
|
|
private long totalPrice;
|
|
|
|
/**
|
|
|
|
* win
|
|
|
|
*/
|
|
|
|
private String win;
|
|
|
|
/**
|
|
|
|
* 本人id
|
|
|
|
*/
|
|
|
|
private String userId;
|
|
|
|
/**
|
|
|
|
* 1@现金红包 2@几分红包
|
|
|
|
*/
|
|
|
|
private int redKind;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 记录
|
|
|
|
*/
|
|
|
|
private List<RecordsDTO> records;
|
|
|
|
}
|
|
|
|
|
|
|
|
public class RedPacketBean {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 订单编号
|
|
|
|
*/
|
|
|
|
private String orderNo;
|
|
|
|
/**
|
|
|
|
* 红包活动id
|
|
|
|
*/
|
|
|
|
private String redActivityId;
|
|
|
|
/**
|
|
|
|
* 红包名称
|
|
|
|
*/
|
|
|
|
private String redName;
|
|
|
|
/**
|
|
|
|
* 红包发送时间
|
|
|
|
*/
|
|
|
|
private String redSendTime;
|
|
|
|
/**
|
|
|
|
* 红包价格 分
|
|
|
|
*/
|
|
|
|
private long redPrice;
|
|
|
|
/**
|
|
|
|
* 红包类型:1@随机红包 2@等分红包
|
|
|
|
*/
|
|
|
|
private int redType;
|
|
|
|
/**
|
|
|
|
* 红包种类:1@普通红包 2@积分红包
|
|
|
|
*/
|
|
|
|
private int redKind;
|
|
|
|
/**
|
|
|
|
* 红包领取金额
|
|
|
|
*/
|
|
|
|
private long redReceive;
|
|
|
|
/**
|
|
|
|
* 红包数量
|
|
|
|
*/
|
|
|
|
private int redNumber;
|
|
|
|
/**
|
|
|
|
* 红包有效期
|
|
|
|
*/
|
|
|
|
private int redExpireTime;
|
|
|
|
/**
|
|
|
|
* 红包时长
|
|
|
|
*/
|
|
|
|
private long redDuration;
|
|
|
|
/**
|
|
|
|
* 红包描述
|
|
|
|
*/
|
|
|
|
private String redDesc;
|
|
|
|
/**
|
|
|
|
* 红包概率
|
|
|
|
*/
|
|
|
|
private int redProbability;
|
|
|
|
/**
|
|
|
|
* 红包掉落的速度:1@慢 2@正常 3@快 4@很快
|
|
|
|
*/
|
|
|
|
private int redSpeed;
|
|
|
|
/**
|
|
|
|
* 红包最小金额 分
|
|
|
|
*/
|
|
|
|
private long redMinPrice;
|
|
|
|
/**
|
|
|
|
* 红包状态 1@初始化 2@充值完成 3@活动开始 4@活动结束
|
|
|
|
*/
|
|
|
|
private int redStatus;
|
|
|
|
/**
|
|
|
|
* 中奖次数
|
|
|
|
*/
|
|
|
|
private int redWinTimes;
|
|
|
|
/**
|
|
|
|
* 是否自动关闭 1@是 0@不是
|
|
|
|
*/
|
|
|
|
private int redAutoClose;
|
|
|
|
/**
|
|
|
|
* 服务器时间
|
|
|
|
*/
|
|
|
|
private long serverTime;
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
### 3. 组件接入
|
|
|
|
|
|
|
|
#### 3.1 使用组件提供UI
|
|
|
|
|
|
|
|
投票ViewGroup为VoteMainLayout
|
|
|
|
|
|
|
|
1. 登录业务SDK(云直播等)
|
|
|
|
|
|
|
|
2. 初始化组件
|
|
|
|
|
|
|
|
1. 获取token-初始化投票需要传递参数token,可以通过业务SDK(云直播等)提供的对外API获取token
|
|
|
|
|
|
|
|
2. 获取正在进行活动-如果需要进入时就展示互动组件,需要调用业务SDK提供的正在进行中组件活动API获取正在进行的活动
|
|
|
|
|
|
|
|
3. 初始化组件-使用前两步获取的信息初始化组件SDK
|
|
|
|
|
|
|
|
代码示例(以云直播为例):
|
|
|
|
|
|
|
|
```java
|
|
|
|
DWLive..getInstance().getInteractiveToken(new BaseCallback<String>() {
|
|
|
|
@Override
|
|
|
|
public void onError(String error) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(String token) {
|
|
|
|
//获取正在进行的互动
|
|
|
|
DWLive.getInstance().getInteractiveOngoing(new BaseCallback<List<InteractionOngoing>>() {
|
|
|
|
@Override
|
|
|
|
public void onError(String error) {
|
|
|
|
initRedPacket(token,
|
|
|
|
loginInfo.getUserId(),
|
|
|
|
loginInfo.getRoomId(),
|
|
|
|
false,
|
|
|
|
""
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(List<InteractionOngoing> interactionOngoings) {
|
|
|
|
//是否正在进行
|
|
|
|
boolean isOngoing = false;
|
|
|
|
String ongoingId = "";
|
|
|
|
if (interactionOngoings != null) {
|
|
|
|
for (int i = 0; i < interactionOngoings.size(); i++) {
|
|
|
|
// 互动组件红包雨 TYPE_INTERACT_RED_PACKET = 6;
|
|
|
|
// 互动组件投票 TYPE_INTERACT_VOTE = 7;
|
|
|
|
if (interactionOngoings.get(i).getType() == InteractionOngoing.TYPE_INTERACT_VOTE) {
|
|
|
|
isOngoing = true;
|
|
|
|
ongoingId = interactionOngoings.get(i).getId();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
initRedPacket(
|
|
|
|
token,
|
|
|
|
loginInfo.getUserId(),
|
|
|
|
loginInfo.getRoomId(),
|
|
|
|
isOngoing,
|
|
|
|
ongoingId
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void initRedPacket(String token, String userId, String roomId, boolean isOngoing, String ongoingId) {
|
|
|
|
//获取组件开关,用于判断房间组件是否开启,以云直播为例
|
|
|
|
if (DWLive.getInstance().getInteractionConfigure().getRedEnvelopesSwitch() == 1) {
|
|
|
|
redPacketBaseHelper = new RedPacketHelper(RedPacketTestActivity.this);
|
|
|
|
redPacketBaseHelper.initialize(new RedPacketBaseHelper.RedPacketConfig()
|
|
|
|
.setUserId(userId)
|
|
|
|
.setRoomId(roomId)
|
|
|
|
.setInteractToken(token)
|
|
|
|
.setOngoing(isOngoing)
|
|
|
|
.setOngoingId(ongoingId));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
5. 销毁组件
|
|
|
|
|
|
|
|
```java
|
|
|
|
@Override
|
|
|
|
protected void onDestroy() {
|
|
|
|
super.onDestroy();
|
|
|
|
if (redPacketBaseHelper!=null){
|
|
|
|
redPacketBaseHelper.release();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#### 3.2 使用组件管理器+自定义UI
|
|
|
|
|
|
|
|
红包雨管理器实现类为RedPacketManagerImpl,对外方法参照IRedPacketManager,helper实现可以参考RedPacketBaseHelper以及其子类RedPacketHelper实现
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### 4. 混淆配置
|
|
|
|
|
|
|
|
混淆配置
|
|
|
|
|
|
|
|
```
|
|
|
|
-keep class com.bokecc.**{*;}
|
|
|
|
-keep interface com.bokecc.**{*;}
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### 5. 组件库依赖
|
|
|
|
|
|
|
|
```groovy
|
|
|
|
implementation 'com.android.support:appcompat-v7:28.0.0'
|
|
|
|
implementation 'com.android.support:recyclerview-v7:28.0.0'
|
|
|
|
implementation 'com.github.bumptech.glide:glide:3.7.0'
|
|
|
|
``` |
|
|
|
\ No newline at end of file |