diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaLiveService.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaLiveService.java index 3047c9a3b2..96e6d879b4 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaLiveService.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaLiveService.java @@ -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 goodsIds) throws WxErrorException; + /** + * 添加管理直播间小助手 + *

+ * 调用接口往指定直播间添加管理直播间小助手 + * 调用频率 + * 调用额度:10000次/一天 + *

+ * http请求方式:POST https://api.weixin.qq.com/wxaapi/broadcast/room/addassistant?access_token=ACCESS_TOKEN + *

+   * @param roomId 房间ID
+   * @param users 数组列表,可传入多个,"users": [{"username":"testwechat","nickname":"testnick"}]
+   * @return 添加管理直播间小助手是否成功
+   * @throws WxErrorException .
+   */
+  boolean addAssistant(Integer roomId, List users) throws WxErrorException;
+  /**
+   * 修改直播间小助手昵称
+   * 

+ * 调用接口修改直播间小助手昵称 + * 调用频率 + * 调用额度:10000次/一天 + *

+ * http请求方式:POST https://api.weixin.qq.com/wxaapi/broadcast/room/modifyassistant?access_token=ACCESS_TOKEN + *

+   * @param roomId 房间ID
+   * @param username 小助手微信号
+   * @param nickname 小助手直播间昵称
+   * @return 修改小助手昵称是否成功
+   * @throws WxErrorException .
+   */
+  boolean modifyAssistant(Integer roomId, String username,String nickname) throws WxErrorException;
+  /**
+   * 删除直播间小助手
+   * 

+ * 删除直播间小助手 + * 调用频率 + * 调用额度:10000次/一天 + *

+ * http请求方式:POST https://api.weixin.qq.com/wxaapi/broadcast/room/removeassistant?access_token=ACCESS_TOKEN + *

+   * @param roomId 房间ID
+   * @param username 小助手微信号
+   * @return 删除小助手昵称是否成功
+   * @throws WxErrorException .
+   */
+  boolean removeAssistant(Integer roomId, String username) throws WxErrorException;
+  /**
+   * 查询直播间小助手
+   * 

+ * 查询直播间小助手 + * 调用频率 + * 调用额度:10000次/一天 + *

+ * http请求方式:POST https://api.weixin.qq.com/wxaapi/broadcast/room/getassistantlist?access_token=ACCESS_TOKEN + *

+   * @param roomId 房间ID
+   * @return 小助手列表
+   * @throws WxErrorException .
+   */
+  List getAssistantList(Integer roomId) throws WxErrorException;
 }
diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaLiveServiceImpl.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaLiveServiceImpl.java
index 84aaab708f..e3af028253 100644
--- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaLiveServiceImpl.java
+++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaLiveServiceImpl.java
@@ -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;
@@ -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 getLiveInfos() throws WxErrorException {
     List results = new ArrayList<>();
@@ -124,6 +120,13 @@ public List 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 map = new HashMap<>(4);
@@ -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 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 boolean addGoodsToRoom(Integer roomId, List goodsIds) throws WxE
     return true;
   }
 
-  private JsonObject getLiveInfo(Integer start, Integer limit, Map map) throws WxErrorException {
-    if (map == null) {
-      map = new HashMap(2);
+  @Override
+  public boolean addAssistant(Integer roomId, List users) throws WxErrorException {
+    Map 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 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 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 getAssistantList(Integer roomId) throws WxErrorException {
+    Map 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();
+  }
+
+
 }
diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/live/WxMaAssistantResult.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/live/WxMaAssistantResult.java
new file mode 100644
index 0000000000..4137efc9fd
--- /dev/null
+++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/live/WxMaAssistantResult.java
@@ -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 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;
+  }
+}
diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/live/WxMaLiveAssistantInfo.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/live/WxMaLiveAssistantInfo.java
new file mode 100644
index 0000000000..bfd727ca82
--- /dev/null
+++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/live/WxMaLiveAssistantInfo.java
@@ -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;
+
+}