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

This commit is contained in:
linlinjava 2022-03-30 20:23:36 +08:00 committed by GitHub
parent 62645a4311
commit be49b10547
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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();
}
}

View File

@ -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<String> goodsKey;
}

View File

@ -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";
}
/**