mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-04-05 17:38:05 +08:00
🆕 #1869 【小程序】增加管理直播间小助手的相关接口
This commit is contained in:
parent
a2074a4d39
commit
c605330661
@ -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;
|
||||
@ -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";
|
||||
|
||||
/**
|
||||
* 创建直播间
|
||||
@ -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;
|
||||
}
|
||||
|
@ -2,6 +2,8 @@ package cn.binarywang.wx.miniapp.api.impl;
|
||||
|
||||
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;
|
||||
@ -90,12 +92,6 @@ public class WxMaLiveServiceImpl implements WxMaLiveService {
|
||||
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<>();
|
||||
@ -124,6 +120,13 @@ public class WxMaLiveServiceImpl implements WxMaLiveService {
|
||||
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);
|
||||
@ -132,7 +135,19 @@ public class WxMaLiveServiceImpl implements WxMaLiveService {
|
||||
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);
|
||||
@ -151,17 +166,57 @@ public class WxMaLiveServiceImpl implements WxMaLiveService {
|
||||
return true;
|
||||
}
|
||||
|
||||
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));
|
||||
@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));
|
||||
}
|
||||
return jsonObject;
|
||||
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 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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user