mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-10-29 17:48:50 +08:00
🆕 #1869 【小程序】增加管理直播间小助手的相关接口
This commit is contained in:
@ -1,5 +1,7 @@
|
|||||||
package cn.binarywang.wx.miniapp.api;
|
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.WxMaLiveResult;
|
||||||
import cn.binarywang.wx.miniapp.bean.live.WxMaLiveRoomInfo;
|
import cn.binarywang.wx.miniapp.bean.live.WxMaLiveRoomInfo;
|
||||||
import me.chanjar.weixin.common.error.WxErrorException;
|
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 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_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 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 .
|
* @throws WxErrorException .
|
||||||
*/
|
*/
|
||||||
boolean addGoodsToRoom(Integer roomId, List<Integer> goodsIds) 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.WxMaLiveService;
|
||||||
import cn.binarywang.wx.miniapp.api.WxMaService;
|
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.WxMaLiveResult;
|
||||||
import cn.binarywang.wx.miniapp.bean.live.WxMaLiveRoomInfo;
|
import cn.binarywang.wx.miniapp.bean.live.WxMaLiveRoomInfo;
|
||||||
import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder;
|
import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder;
|
||||||
@ -90,12 +92,6 @@ public class WxMaLiveServiceImpl implements WxMaLiveService {
|
|||||||
return jsonObject.get("cdnUrl").getAsString();
|
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
|
@Override
|
||||||
public List<WxMaLiveResult.RoomInfo> getLiveInfos() throws WxErrorException {
|
public List<WxMaLiveResult.RoomInfo> getLiveInfos() throws WxErrorException {
|
||||||
List<WxMaLiveResult.RoomInfo> results = new ArrayList<>();
|
List<WxMaLiveResult.RoomInfo> results = new ArrayList<>();
|
||||||
@ -124,6 +120,13 @@ public class WxMaLiveServiceImpl implements WxMaLiveService {
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public WxMaLiveResult getLiveInfo(Integer start, Integer limit) throws WxErrorException {
|
||||||
|
JsonObject jsonObject = getLiveInfo(start, limit, null);
|
||||||
|
return WxMaLiveResult.fromJson(jsonObject.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WxMaLiveResult getLiveReplay(String action, Integer roomId, Integer start, Integer limit) throws WxErrorException {
|
public WxMaLiveResult getLiveReplay(String action, Integer roomId, Integer start, Integer limit) throws WxErrorException {
|
||||||
Map<String, Object> map = new HashMap<>(4);
|
Map<String, Object> map = new HashMap<>(4);
|
||||||
@ -132,7 +135,19 @@ public class WxMaLiveServiceImpl implements WxMaLiveService {
|
|||||||
JsonObject jsonObject = getLiveInfo(start, limit, map);
|
JsonObject jsonObject = getLiveInfo(start, limit, map);
|
||||||
return WxMaLiveResult.fromJson(jsonObject.toString());
|
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
|
@Override
|
||||||
public WxMaLiveResult getLiveReplay(Integer roomId, Integer start, Integer limit) throws WxErrorException {
|
public WxMaLiveResult getLiveReplay(Integer roomId, Integer start, Integer limit) throws WxErrorException {
|
||||||
return getLiveReplay("get_replay", roomId, start, limit);
|
return getLiveReplay("get_replay", roomId, start, limit);
|
||||||
@ -151,17 +166,57 @@ public class WxMaLiveServiceImpl implements WxMaLiveService {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private JsonObject getLiveInfo(Integer start, Integer limit, Map<String, Object> map) throws WxErrorException {
|
@Override
|
||||||
if (map == null) {
|
public boolean addAssistant(Integer roomId, List<WxMaLiveAssistantInfo> users) throws WxErrorException {
|
||||||
map = new HashMap(2);
|
Map<String, Object> map = new HashMap<>(2);
|
||||||
}
|
map.put("roomId", roomId);
|
||||||
map.put("start", start);
|
map.put("users", users);
|
||||||
map.put("limit", limit);
|
String responseContent = this.wxMaService.post(ADD_ASSISTANT, WxMaGsonBuilder.create().toJson(map));
|
||||||
String responseContent = wxMaService.post(GET_LIVE_INFO, WxMaGsonBuilder.create().toJson(map));
|
|
||||||
JsonObject jsonObject = GsonParser.parse(responseContent);
|
JsonObject jsonObject = GsonParser.parse(responseContent);
|
||||||
if (jsonObject.get("errcode").getAsInt() != 0) {
|
if (jsonObject.get("errcode").getAsInt() != 0) {
|
||||||
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
|
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;
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user