Skip to content

Commit

Permalink
🆕 #1869 【小程序】增加管理直播间小助手的相关接口
Browse files Browse the repository at this point in the history
  • Loading branch information
GaoMinzhu authored Nov 13, 2020
1 parent a2074a4 commit c605330
Show file tree
Hide file tree
Showing 4 changed files with 222 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package cn.binarywang.wx.miniapp.api;

import cn.binarywang.wx.miniapp.bean.live.WxMaAssistantResult;
import cn.binarywang.wx.miniapp.bean.live.WxMaLiveAssistantInfo;
import cn.binarywang.wx.miniapp.bean.live.WxMaLiveResult;
import cn.binarywang.wx.miniapp.bean.live.WxMaLiveRoomInfo;
import me.chanjar.weixin.common.error.WxErrorException;
Expand All @@ -22,6 +24,10 @@ public interface WxMaLiveService {
String EDIT_ROOM = "https://api.weixin.qq.com/wxaapi/broadcast/room/editroom";
String GET_PUSH_URL = "https://api.weixin.qq.com/wxaapi/broadcast/room/getpushurl";
String GET_SHARED_CODE = "https://api.weixin.qq.com/wxaapi/broadcast/room/getsharedcode";
String ADD_ASSISTANT = "https://api.weixin.qq.com/wxaapi/broadcast/room/addassistant";
String MODIFY_ASSISTANT = "https://api.weixin.qq.com/wxaapi/broadcast/room/modifyassistant";
String REMOVE_ASSISTANT = "https://api.weixin.qq.com/wxaapi/broadcast/room/removeassistant";
String GET_ASSISTANT_LIST = "https://api.weixin.qq.com/wxaapi/broadcast/room/getassistantlist";

/**
* 创建直播间
Expand Down Expand Up @@ -150,4 +156,64 @@ public interface WxMaLiveService {
* @throws WxErrorException .
*/
boolean addGoodsToRoom(Integer roomId, List<Integer> goodsIds) throws WxErrorException;
/**
* 添加管理直播间小助手
* <p>
* 调用接口往指定直播间添加管理直播间小助手
* 调用频率
* 调用额度:10000次/一天
* <p>
* http请求方式:POST https://api.weixin.qq.com/wxaapi/broadcast/room/addassistant?access_token=ACCESS_TOKEN
* <pre>
* @param roomId 房间ID
* @param users 数组列表,可传入多个,"users": [{"username":"testwechat","nickname":"testnick"}]
* @return 添加管理直播间小助手是否成功
* @throws WxErrorException .
*/
boolean addAssistant(Integer roomId, List<WxMaLiveAssistantInfo> users) throws WxErrorException;
/**
* 修改直播间小助手昵称
* <p>
* 调用接口修改直播间小助手昵称
* 调用频率
* 调用额度:10000次/一天
* <p>
* http请求方式:POST https://api.weixin.qq.com/wxaapi/broadcast/room/modifyassistant?access_token=ACCESS_TOKEN
* <pre>
* @param roomId 房间ID
* @param username 小助手微信号
* @param nickname 小助手直播间昵称
* @return 修改小助手昵称是否成功
* @throws WxErrorException .
*/
boolean modifyAssistant(Integer roomId, String username,String nickname) throws WxErrorException;
/**
* 删除直播间小助手
* <p>
* 删除直播间小助手
* 调用频率
* 调用额度:10000次/一天
* <p>
* http请求方式:POST https://api.weixin.qq.com/wxaapi/broadcast/room/removeassistant?access_token=ACCESS_TOKEN
* <pre>
* @param roomId 房间ID
* @param username 小助手微信号
* @return 删除小助手昵称是否成功
* @throws WxErrorException .
*/
boolean removeAssistant(Integer roomId, String username) throws WxErrorException;
/**
* 查询直播间小助手
* <p>
* 查询直播间小助手
* 调用频率
* 调用额度:10000次/一天
* <p>
* http请求方式:POST https://api.weixin.qq.com/wxaapi/broadcast/room/getassistantlist?access_token=ACCESS_TOKEN
* <pre>
* @param roomId 房间ID
* @return 小助手列表
* @throws WxErrorException .
*/
List<WxMaAssistantResult.Assistant> getAssistantList(Integer roomId) throws WxErrorException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import cn.binarywang.wx.miniapp.api.WxMaLiveService;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.live.WxMaAssistantResult;
import cn.binarywang.wx.miniapp.bean.live.WxMaLiveAssistantInfo;
import cn.binarywang.wx.miniapp.bean.live.WxMaLiveResult;
import cn.binarywang.wx.miniapp.bean.live.WxMaLiveRoomInfo;
import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder;
Expand Down Expand Up @@ -90,12 +92,6 @@ public String getSharedCode(Integer roomId, String params) throws WxErrorExcepti
return jsonObject.get("cdnUrl").getAsString();
}

@Override
public WxMaLiveResult getLiveInfo(Integer start, Integer limit) throws WxErrorException {
JsonObject jsonObject = getLiveInfo(start, limit, null);
return WxMaLiveResult.fromJson(jsonObject.toString());
}

@Override
public List<WxMaLiveResult.RoomInfo> getLiveInfos() throws WxErrorException {
List<WxMaLiveResult.RoomInfo> results = new ArrayList<>();
Expand Down Expand Up @@ -124,6 +120,13 @@ public List<WxMaLiveResult.RoomInfo> getLiveInfos() throws WxErrorException {
return results;
}

@Override
public WxMaLiveResult getLiveInfo(Integer start, Integer limit) throws WxErrorException {
JsonObject jsonObject = getLiveInfo(start, limit, null);
return WxMaLiveResult.fromJson(jsonObject.toString());
}


@Override
public WxMaLiveResult getLiveReplay(String action, Integer roomId, Integer start, Integer limit) throws WxErrorException {
Map<String, Object> map = new HashMap<>(4);
Expand All @@ -132,7 +135,19 @@ public WxMaLiveResult getLiveReplay(String action, Integer roomId, Integer start
JsonObject jsonObject = getLiveInfo(start, limit, map);
return WxMaLiveResult.fromJson(jsonObject.toString());
}

private JsonObject getLiveInfo(Integer start, Integer limit, Map<String, Object> map) throws WxErrorException {
if (map == null) {
map = new HashMap(2);
}
map.put("start", start);
map.put("limit", limit);
String responseContent = wxMaService.post(GET_LIVE_INFO, WxMaGsonBuilder.create().toJson(map));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get("errcode").getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return jsonObject;
}
@Override
public WxMaLiveResult getLiveReplay(Integer roomId, Integer start, Integer limit) throws WxErrorException {
return getLiveReplay("get_replay", roomId, start, limit);
Expand All @@ -151,17 +166,57 @@ public boolean addGoodsToRoom(Integer roomId, List<Integer> goodsIds) throws WxE
return true;
}

private JsonObject getLiveInfo(Integer start, Integer limit, Map<String, Object> map) throws WxErrorException {
if (map == null) {
map = new HashMap(2);
@Override
public boolean addAssistant(Integer roomId, List<WxMaLiveAssistantInfo> users) throws WxErrorException {
Map<String, Object> map = new HashMap<>(2);
map.put("roomId", roomId);
map.put("users", users);
String responseContent = this.wxMaService.post(ADD_ASSISTANT, WxMaGsonBuilder.create().toJson(map));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get("errcode").getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
map.put("start", start);
map.put("limit", limit);
String responseContent = wxMaService.post(GET_LIVE_INFO, WxMaGsonBuilder.create().toJson(map));
return true;
}

@Override
public boolean modifyAssistant(Integer roomId, String username,String nickname) throws WxErrorException {
Map<String, Object> map = new HashMap<>(2);
map.put("roomId", roomId);
map.put("username",username);
map.put("nickname", nickname);
String responseContent = this.wxMaService.post(MODIFY_ASSISTANT, WxMaGsonBuilder.create().toJson(map));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get("errcode").getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return jsonObject;
return true;
}

@Override
public boolean removeAssistant(Integer roomId,String username) throws WxErrorException {
Map<String, Object> map = new HashMap<>(2);
map.put("roomId", roomId);
map.put("username",username);
String responseContent = this.wxMaService.post(REMOVE_ASSISTANT, WxMaGsonBuilder.create().toJson(map));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get("errcode").getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return true;
}

@Override
public List<WxMaAssistantResult.Assistant> getAssistantList(Integer roomId) throws WxErrorException {
Map<String, Object> map = new HashMap<>(2);
map.put("roomId", roomId);
String responseContent = this.wxMaService.post(GET_ASSISTANT_LIST, WxMaGsonBuilder.create().toJson(map));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get("errcode").getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return WxMaAssistantResult.fromJson(responseContent).getList();
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package cn.binarywang.wx.miniapp.bean.live;

import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder;
import lombok.Data;

import java.io.Serializable;
import java.util.List;

/**
* 直播间小助手用户信息
*/
@Data
public class WxMaAssistantResult implements Serializable {
private static final long serialVersionUID = 5829108618580715870L;

private Integer count;
private Integer maxCount;
private Integer errcode;

private List<Assistant> list;

public static WxMaAssistantResult fromJson(String json) {
return WxMaGsonBuilder.create().fromJson(json, WxMaAssistantResult.class);
}
@Data
public static class Assistant implements Serializable {
private static final long serialVersionUID = 6362128855371134033L;
/**
* 修改时间
*/
private Long timestamp;
/**
* 头像
**/
private String headimg;
/**
* 用户昵称
**/
private String nickname;
/**
* 微信号
**/
private String alias;
/**
* openid
**/
private String openid;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package cn.binarywang.wx.miniapp.bean.live;

import lombok.Data;

import java.io.Serializable;

/**
* 直播间小助手用户信息
*/
@Data
public class WxMaLiveAssistantInfo implements Serializable {
private static final long serialVersionUID = -5603581848069320808L;
/**
* 修改时间
*/
private Long timestamp;
/**
* 头像
**/
private String headimg;
/**
* 用户微信号
**/
private String username;
/**
* 用户昵称
**/
private String nickname;
/**
* 微信号
**/
private String alias;
/**
* openid
**/
private String openid;

}

0 comments on commit c605330

Please sign in to comment.