From be49b1054736da19ae21eb726bdb01a4a63721dc Mon Sep 17 00:00:00 2001 From: linlinjava Date: Wed, 30 Mar 2022 20:23:36 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20#2567=20=E3=80=90=E5=B0=8F=E7=A8=8B?= =?UTF-8?q?=E5=BA=8F=E3=80=91=E7=9B=B4=E6=92=AD=E9=97=B4=E5=92=8C=E5=95=86?= =?UTF-8?q?=E5=93=81=E3=80=81=E6=8C=82=E4=BB=B6=E7=BB=84=E4=BB=B6=E7=AD=89?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E6=8E=A5=E5=8F=A3=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wx/miniapp/api/WxMaLiveService.java | 187 ++++++++++++++++++ .../miniapp/api/impl/WxMaLiveServiceImpl.java | 171 +++++++++++++++- .../miniapp/bean/live/WxMaLiveGoodInfo.java | 5 + .../miniapp/constant/WxMaApiUrlConstants.java | 89 ++++++++- 4 files changed, 448 insertions(+), 4 deletions(-) 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 a90f4756b..3b0ccc390 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 @@ -4,6 +4,7 @@ import cn.binarywang.wx.miniapp.bean.live.*; import me.chanjar.weixin.common.error.WxErrorException; import java.util.List; +import java.util.Map; /** *
@@ -207,4 +208,190 @@ public interface WxMaLiveService {
    * @throws WxErrorException .
    */
   List getAssistantList(Integer roomId) throws WxErrorException;
+
+  /**
+   * 添加主播副号
+   * 

+ * 调用接口添加主播副号 + *

+ * 调用额度:10000次/一天 + *

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

+   * @param roomId 房间ID
+   * @param username 用户微信号
+   * @return 是否成功
+   * @throws WxErrorException .
+   */
+  boolean addSubanchor(Integer roomId, String username) throws WxErrorException;
+
+  /**
+   * 修改主播副号
+   * 

+ * 调用接口修改主播副号 + *

+ * 调用频率: 10000次/一天 + *

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

+   * @param roomId 房间ID
+   * @param username 小助手微信号
+   * @param username 用户微信号
+   * @return 是否成功
+   * @throws WxErrorException .
+   */
+  boolean modifySubanchor(Integer roomId, String username) throws WxErrorException;
+
+  /**
+   * 删除主播副号
+   * 

+ * 调用频率: 10000次/一天 + *

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

+   * @param roomId 房间ID
+   * @return 是否成功
+   * @throws WxErrorException .
+   */
+  boolean deleteSubanchor(Integer roomId) throws WxErrorException;
+
+  /**
+   * 获取主播副号
+   * 

+ * 调用额度:10000次/一天 + *

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

+ * @param roomId 直播间id + * @return . + * @throws WxErrorException . + */ + String getSubanchor(Integer roomId) throws WxErrorException; + + /** + * 开启/关闭直播间官方收录 + *

+ * 调用额度:10000次/一天 + *

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

+   * @param roomId 房间ID
+   * @param isFeedsPublic 是否开启官方收录 【1: 开启,0:关闭】
+   * @return 是否成功
+   * @throws WxErrorException .
+   */
+  boolean updatefeedpublic(Integer roomId, Integer isFeedsPublic) throws WxErrorException;
+
+  /**
+   * 开启/关闭回放功能
+   * 

+ * 调用额度:10000次/一天 + *

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

+   * @param roomId 房间ID
+   * @param closeReplay 是否关闭回放 【0:开启,1:关闭】
+   * @return 是否成功
+   * @throws WxErrorException .
+   */
+  boolean updatereplay(Integer roomId, Integer closeReplay) throws WxErrorException;
+
+  /**
+   * 开启/关闭客服功能
+   * 

+ * 调用额度:10000次/一天 + *

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

+   * @param roomId 房间ID
+   * @param closeKf 是否关闭客服 【0:开启,1:关闭】
+   * @return 是否成功
+   * @throws WxErrorException .
+   */
+  boolean updatekf(Integer roomId, Integer closeKf) throws WxErrorException;
+
+  /**
+   * 开启/关闭直播间全局禁言
+   * 

+ * 调用额度:10000次/一天 + *

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

+   * @param roomId 房间ID
+   * @param banComment 1-禁言,0-取消禁言
+   * @return 是否成功
+   * @throws WxErrorException .
+   */
+  boolean updatecomment(Integer roomId, Integer banComment) throws WxErrorException;
+
+  /**
+   * 上下架商品
+   * 

+ * 调用额度:10000次/一天 + *

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

+   * @param roomId 房间ID
+   * @param goodsId 商品ID
+   * @param onSale 上下架 【0:下架,1:上架】
+   * @return 是否成功
+   * @throws WxErrorException .
+   */
+  boolean onsale(Integer roomId, Integer goodsId, Integer onSale) throws WxErrorException;
+
+  /**
+   * 删除直播间商品
+   * 

+ * 调用额度:10000次/一天 + *

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

+   * @param roomId 房间ID
+   * @param goodsId 商品ID
+   * @return 是否成功
+   * @throws WxErrorException .
+   */
+  boolean deleteInRoom(Integer roomId, Integer goodsId) throws WxErrorException;
+
+  /**
+   * 推送商品
+   * 

+ * 调用额度:10000次/一天 + *

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

+   * @param roomId 房间ID
+   * @param goodsId 商品ID
+   * @return 是否成功
+   * @throws WxErrorException .
+   */
+  boolean push(Integer roomId, Integer goodsId) throws WxErrorException;
+
+  /**
+   * 直播间商品排序
+   * 

+ * 调用额度:10000次/一天 + *

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

+   * @param roomId 房间ID
+   * @param goods 商品ID列表, 例如: [{"goodsId":"123"}, {"goodsId":"234"}]
+   * @return 是否成功
+   * @throws WxErrorException .
+   */
+  boolean sort(Integer roomId, List> goods) throws WxErrorException;
+
+  /**
+   * 下载商品讲解视频
+   * 

+ * 调用额度:10000次/一天 + *

+ * http请求方式:GET https://api.weixin.qq.com/wxaapi/broadcast/goods/getVideo?access_token=ACCESS_TOKEN + *

+ * @param roomId 直播间id + * @param goodsId 商品ID + * @return . + * @throws WxErrorException . + */ + String getVideo(Integer roomId, Integer goodsId) 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 b71e58653..abda4faa6 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 @@ -18,7 +18,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Broadcast.GET_LIVE_INFO; import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Broadcast.Room; /** @@ -152,7 +151,7 @@ public class WxMaLiveServiceImpl implements WxMaLiveService { } map.put("start", start); map.put("limit", limit); - String responseContent = wxMaService.post(GET_LIVE_INFO, WxMaGsonBuilder.create().toJson(map)); + String responseContent = wxMaService.post(Room.GET_LIVE_INFO, WxMaGsonBuilder.create().toJson(map)); JsonObject jsonObject = GsonParser.parse(responseContent); if (jsonObject.get(ERR_CODE).getAsInt() != 0) { throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); @@ -231,4 +230,172 @@ public class WxMaLiveServiceImpl implements WxMaLiveService { return WxMaAssistantResult.fromJson(responseContent).getList(); } + @Override + public boolean addSubanchor(Integer roomId, String username) throws WxErrorException { + Map map = new HashMap<>(2); + map.put(ROOM_ID, roomId); + map.put("username", username); + String responseContent = this.wxMaService.post(Room.ADD_SUBANCHOR, WxMaGsonBuilder.create().toJson(map)); + JsonObject jsonObject = GsonParser.parse(responseContent); + if (jsonObject.get(ERR_CODE).getAsInt() != 0) { + throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); + } + return true; + } + + @Override + public boolean modifySubanchor(Integer roomId, String username) throws WxErrorException { + Map map = new HashMap<>(2); + map.put(ROOM_ID, roomId); + map.put("username", username); + String responseContent = this.wxMaService.post(Room.MODIFY_SUBANCHOR, WxMaGsonBuilder.create().toJson(map)); + JsonObject jsonObject = GsonParser.parse(responseContent); + if (jsonObject.get(ERR_CODE).getAsInt() != 0) { + throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); + } + return true; + } + + @Override + public boolean deleteSubanchor(Integer roomId) throws WxErrorException { + Map map = new HashMap<>(1); + map.put(ROOM_ID, roomId); + String responseContent = this.wxMaService.post(Room.DELETE_SUBANCHOR, WxMaGsonBuilder.create().toJson(map)); + JsonObject jsonObject = GsonParser.parse(responseContent); + if (jsonObject.get(ERR_CODE).getAsInt() != 0) { + throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); + } + return true; + } + + @Override + public String getSubanchor(Integer roomId) throws WxErrorException { + Map map = new HashMap<>(1); + map.put(ROOM_ID, roomId); + String responseContent = this.wxMaService.get(Room.GET_SUBANCHOR, WxMaGsonBuilder.create().toJson(map)); + JsonObject jsonObject = GsonParser.parse(responseContent); + if (jsonObject.get(ERR_CODE).getAsInt() != 0) { + throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); + } + return jsonObject.get("username").getAsString(); + } + + @Override + public boolean updatefeedpublic(Integer roomId, Integer isFeedsPublic) throws WxErrorException { + Map map = new HashMap<>(2); + map.put(ROOM_ID, roomId); + map.put("isFeedsPublic", isFeedsPublic); + String responseContent = this.wxMaService.post(Room.UPDATE_FEED_PUBLIC, WxMaGsonBuilder.create().toJson(map)); + JsonObject jsonObject = GsonParser.parse(responseContent); + if (jsonObject.get(ERR_CODE).getAsInt() != 0) { + throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); + } + return true; + } + + @Override + public boolean updatereplay(Integer roomId, Integer closeReplay) throws WxErrorException { + Map map = new HashMap<>(2); + map.put(ROOM_ID, roomId); + map.put("closeReplay", closeReplay); + String responseContent = this.wxMaService.post(Room.UPDATE_REPLAY, WxMaGsonBuilder.create().toJson(map)); + JsonObject jsonObject = GsonParser.parse(responseContent); + if (jsonObject.get(ERR_CODE).getAsInt() != 0) { + throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); + } + return true; + } + + @Override + public boolean updatekf(Integer roomId, Integer closeKf) throws WxErrorException { + Map map = new HashMap<>(2); + map.put(ROOM_ID, roomId); + map.put("closeKf", closeKf); + String responseContent = this.wxMaService.post(Room.UPDATE_KF, WxMaGsonBuilder.create().toJson(map)); + JsonObject jsonObject = GsonParser.parse(responseContent); + if (jsonObject.get(ERR_CODE).getAsInt() != 0) { + throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); + } + return true; + } + + @Override + public boolean updatecomment(Integer roomId, Integer banComment) throws WxErrorException { + Map map = new HashMap<>(2); + map.put(ROOM_ID, roomId); + map.put("banComment", banComment); + String responseContent = this.wxMaService.post(Room.UPDATE_COMMENT, WxMaGsonBuilder.create().toJson(map)); + JsonObject jsonObject = GsonParser.parse(responseContent); + if (jsonObject.get(ERR_CODE).getAsInt() != 0) { + throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); + } + return true; + } + + @Override + public boolean onsale(Integer roomId, Integer goodsId, Integer onSale) throws WxErrorException { + Map map = new HashMap<>(3); + map.put(ROOM_ID, roomId); + map.put("goodsId", goodsId); + map.put("onSale", onSale); + String responseContent = this.wxMaService.post(Room.ONSALE, WxMaGsonBuilder.create().toJson(map)); + JsonObject jsonObject = GsonParser.parse(responseContent); + if (jsonObject.get(ERR_CODE).getAsInt() != 0) { + throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); + } + return true; + } + + @Override + public boolean deleteInRoom(Integer roomId, Integer goodsId) throws WxErrorException { + Map map = new HashMap<>(2); + map.put(ROOM_ID, roomId); + map.put("goodsId", goodsId); + String responseContent = this.wxMaService.post(Room.DELETE_IN_ROOM, WxMaGsonBuilder.create().toJson(map)); + JsonObject jsonObject = GsonParser.parse(responseContent); + if (jsonObject.get(ERR_CODE).getAsInt() != 0) { + throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); + } + return true; + } + + @Override + public boolean push(Integer roomId, Integer goodsId) throws WxErrorException { + Map map = new HashMap<>(2); + map.put(ROOM_ID, roomId); + map.put("goodsId", goodsId); + String responseContent = this.wxMaService.post(Room.PUSH, WxMaGsonBuilder.create().toJson(map)); + JsonObject jsonObject = GsonParser.parse(responseContent); + if (jsonObject.get(ERR_CODE).getAsInt() != 0) { + throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); + } + return true; + } + + @Override + public boolean sort(Integer roomId, List> goods) throws WxErrorException { + Map map = new HashMap<>(2); + map.put(ROOM_ID, roomId); + map.put("goods", goods); + String responseContent = this.wxMaService.post(Room.SORT, WxMaGsonBuilder.create().toJson(map)); + JsonObject jsonObject = GsonParser.parse(responseContent); + if (jsonObject.get(ERR_CODE).getAsInt() != 0) { + throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); + } + return true; + } + + @Override + public String getVideo(Integer roomId, Integer goodsId) throws WxErrorException { + Map map = new HashMap<>(2); + map.put(ROOM_ID, roomId); + map.put("goodsId", goodsId); + String responseContent = this.wxMaService.get(Room.GET_VIDEO, WxMaGsonBuilder.create().toJson(map)); + JsonObject jsonObject = GsonParser.parse(responseContent); + if (jsonObject.get(ERR_CODE).getAsInt() != 0) { + throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); + } + return jsonObject.get("url").getAsString(); + } + } diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/live/WxMaLiveGoodInfo.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/live/WxMaLiveGoodInfo.java index 4a63ff7a4..3ef043495 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/live/WxMaLiveGoodInfo.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/live/WxMaLiveGoodInfo.java @@ -4,6 +4,7 @@ import lombok.Data; import java.io.Serializable; import java.math.BigDecimal; +import java.util.List; /** * 直播商品信息 @@ -22,4 +23,8 @@ public class WxMaLiveGoodInfo implements Serializable { * 1, 2:表示是为api添加商品,否则是在MP添加商品 */ private String thirdPartyTag; + /** + * https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/industry/liveplayer/pendant.html + */ + private List goodsKey; } diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/constant/WxMaApiUrlConstants.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/constant/WxMaApiUrlConstants.java index 3fd6719f7..4fd7ce1db 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/constant/WxMaApiUrlConstants.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/constant/WxMaApiUrlConstants.java @@ -158,22 +158,107 @@ public class WxMaApiUrlConstants { } public interface Broadcast { - String GET_LIVE_INFO = "https://api.weixin.qq.com/wxa/business/getliveinfo"; - /** * 直播间管理相关接口 */ interface Room { + /** + * 创建直播间 + */ String CREATE_ROOM = "https://api.weixin.qq.com/wxaapi/broadcast/room/create"; + /** + * 获取直播间列表 + * 获取直播间回放 + */ + String GET_LIVE_INFO = "https://api.weixin.qq.com/wxa/business/getliveinfo"; + /** + * 直播间导入商品 + */ String ADD_GOODS = "https://api.weixin.qq.com/wxaapi/broadcast/room/addgoods"; + /** + * 删除直播间 + */ String DELETE_ROOM = "https://api.weixin.qq.com/wxaapi/broadcast/room/deleteroom"; + /** + * 编辑直播间 + */ 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"; + /** + * 添加主播副号 + */ + String ADD_SUBANCHOR = "https://api.weixin.qq.com/wxaapi/broadcast/room/addsubanchor"; + /** + * 修改主播副号 + */ + String MODIFY_SUBANCHOR = "https://api.weixin.qq.com/wxaapi/broadcast/room/modifysubanchor"; + /** + * 删除主播副号 + */ + String DELETE_SUBANCHOR = "https://api.weixin.qq.com/wxaapi/broadcast/room/deletesubanchor"; + /** + * 获取主播副号 + */ + String GET_SUBANCHOR = "https://api.weixin.qq.com/wxaapi/broadcast/room/getsubanchor"; + /** + * 开启/关闭直播间官方收录 + */ + String UPDATE_FEED_PUBLIC = "https://api.weixin.qq.com/wxaapi/broadcast/room/updatefeedpublic"; + /** + * 开启/关闭回放功能 + */ + String UPDATE_REPLAY = "https://api.weixin.qq.com/wxaapi/broadcast/room/updatereplay"; + /** + * 开启/关闭客服功能 + */ + String UPDATE_KF = "https://api.weixin.qq.com/wxaapi/broadcast/room/updatekf"; + /** + * 开启/关闭直播间全局禁言 + */ + String UPDATE_COMMENT = "https://api.weixin.qq.com/wxaapi/broadcast/room/updatecomment"; + /** + * 上下架商品 + */ + String ONSALE = "https://api.weixin.qq.com/wxaapi/broadcast/goods/onsale"; + /** + * 删除商品 + */ + String DELETE_IN_ROOM = "https://api.weixin.qq.com/wxaapi/broadcast/goods/deleteInRoom"; + /** + * 推送商品 + */ + String PUSH = "https://api.weixin.qq.com/wxaapi/broadcast/goods/push"; + /** + * 商品排序 + */ + String SORT = "https://api.weixin.qq.com/wxaapi/broadcast/goods/sort"; + /** + * 下载商品讲解视频 + */ + String GET_VIDEO = "https://api.weixin.qq.com/wxaapi/broadcast/goods/getVideo"; } /**