🎨 #2567 【小程序】直播间和商品、挂件组件等相关接口完善

This commit is contained in:
linlinjava
2022-03-30 20:23:36 +08:00
committed by GitHub
parent 62645a4311
commit be49b10547
4 changed files with 448 additions and 4 deletions

View File

@@ -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;
/**
* <pre>
@@ -207,4 +208,190 @@ public interface WxMaLiveService {
* @throws WxErrorException .
*/
List<WxMaAssistantResult.Assistant> getAssistantList(Integer roomId) throws WxErrorException;
/**
* 添加主播副号
* <p>
* 调用接口添加主播副号
* <p>
* 调用额度10000次/一天
* <p>
* http请求方式POST https://api.weixin.qq.com/wxaapi/broadcast/room/addsubanchor?access_token=ACCESS_TOKEN
* <pre>
* @param roomId 房间ID
* @param username 用户微信号
* @return 是否成功
* @throws WxErrorException .
*/
boolean addSubanchor(Integer roomId, String username) throws WxErrorException;
/**
* 修改主播副号
* <p>
* 调用接口修改主播副号
* <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 username 用户微信号
* @return 是否成功
* @throws WxErrorException .
*/
boolean modifySubanchor(Integer roomId, String username) throws WxErrorException;
/**
* 删除主播副号
* <p>
* 调用频率: 10000次/一天
* <p>
* http请求方式POST https://api.weixin.qq.com/wxaapi/broadcast/room/deletesubanchor?access_token=ACCESS_TOKEN
* <pre>
* @param roomId 房间ID
* @return 是否成功
* @throws WxErrorException .
*/
boolean deleteSubanchor(Integer roomId) throws WxErrorException;
/**
* 获取主播副号
* <p>
* 调用额度10000次/一天
* <p>
* http请求方式GET https://api.weixin.qq.com/wxaapi/broadcast/room/getsubanchor?access_token=ACCESS_TOKEN
* </pre>
* @param roomId 直播间id
* @return .
* @throws WxErrorException .
*/
String getSubanchor(Integer roomId) throws WxErrorException;
/**
* 开启/关闭直播间官方收录
* <p>
* 调用额度10000次/一天
* <p>
* http请求方式POST https://api.weixin.qq.com/wxaapi/broadcast/room/updatefeedpublic?access_token=ACCESS_TOKEN
* <pre>
* @param roomId 房间ID
* @param isFeedsPublic 是否开启官方收录 【1: 开启0关闭】
* @return 是否成功
* @throws WxErrorException .
*/
boolean updatefeedpublic(Integer roomId, Integer isFeedsPublic) throws WxErrorException;
/**
* 开启/关闭回放功能
* <p>
* 调用额度10000次/一天
* <p>
* http请求方式POST https://api.weixin.qq.com/wxaapi/broadcast/room/updatereplay?access_token=ACCESS_TOKEN
* <pre>
* @param roomId 房间ID
* @param closeReplay 是否关闭回放 【0开启1关闭】
* @return 是否成功
* @throws WxErrorException .
*/
boolean updatereplay(Integer roomId, Integer closeReplay) throws WxErrorException;
/**
* 开启/关闭客服功能
* <p>
* 调用额度10000次/一天
* <p>
* http请求方式POST https://api.weixin.qq.com/wxaapi/broadcast/room/updatekf?access_token=ACCESS_TOKEN
* <pre>
* @param roomId 房间ID
* @param closeKf 是否关闭客服 【0开启1关闭】
* @return 是否成功
* @throws WxErrorException .
*/
boolean updatekf(Integer roomId, Integer closeKf) throws WxErrorException;
/**
* 开启/关闭直播间全局禁言
* <p>
* 调用额度10000次/一天
* <p>
* http请求方式POST https://api.weixin.qq.com/wxaapi/broadcast/room/updatecomment?access_token=ACCESS_TOKEN
* <pre>
* @param roomId 房间ID
* @param banComment 1-禁言0-取消禁言
* @return 是否成功
* @throws WxErrorException .
*/
boolean updatecomment(Integer roomId, Integer banComment) throws WxErrorException;
/**
* 上下架商品
* <p>
* 调用额度10000次/一天
* <p>
* http请求方式POST https://api.weixin.qq.com/wxaapi/broadcast/goods/onsale?access_token=ACCESS_TOKEN
* <pre>
* @param roomId 房间ID
* @param goodsId 商品ID
* @param onSale 上下架 【0下架1上架】
* @return 是否成功
* @throws WxErrorException .
*/
boolean onsale(Integer roomId, Integer goodsId, Integer onSale) throws WxErrorException;
/**
* 删除直播间商品
* <p>
* 调用额度10000次/一天
* <p>
* http请求方式POST https://api.weixin.qq.com/wxaapi/broadcast/goods/deleteInRoom?access_token=ACCESS_TOKEN
* <pre>
* @param roomId 房间ID
* @param goodsId 商品ID
* @return 是否成功
* @throws WxErrorException .
*/
boolean deleteInRoom(Integer roomId, Integer goodsId) throws WxErrorException;
/**
* 推送商品
* <p>
* 调用额度10000次/一天
* <p>
* http请求方式POST https://api.weixin.qq.com/wxaapi/broadcast/goods/push?access_token=ACCESS_TOKEN
* <pre>
* @param roomId 房间ID
* @param goodsId 商品ID
* @return 是否成功
* @throws WxErrorException .
*/
boolean push(Integer roomId, Integer goodsId) throws WxErrorException;
/**
* 直播间商品排序
* <p>
* 调用额度10000次/一天
* <p>
* http请求方式POST https://api.weixin.qq.com/wxaapi/broadcast/goods/sort?access_token=ACCESS_TOKEN
* <pre>
* @param roomId 房间ID
* @param goods 商品ID列表, 例如: [{"goodsId":"123"}, {"goodsId":"234"}]
* @return 是否成功
* @throws WxErrorException .
*/
boolean sort(Integer roomId, List<Map<String,String>> goods) throws WxErrorException;
/**
* 下载商品讲解视频
* <p>
* 调用额度10000次/一天
* <p>
* http请求方式GET https://api.weixin.qq.com/wxaapi/broadcast/goods/getVideo?access_token=ACCESS_TOKEN
* </pre>
* @param roomId 直播间id
* @param goodsId 商品ID
* @return .
* @throws WxErrorException .
*/
String getVideo(Integer roomId, Integer goodsId) throws WxErrorException;
}

View File

@@ -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<String, Object> 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<String, Object> 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<String, Object> 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<String, Object> 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<String, Object> 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<String, Object> 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<String, Object> 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<String, Object> 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<String, Object> 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<String, Object> 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<String, Object> 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<Map<String,String>> goods) throws WxErrorException {
Map<String, Object> 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<String, Object> 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();
}
}