🆕 #1863 【小程序】增加删除直播间、编辑直播间、获取直播间推流地址、获取直播间分享二维码等接口

This commit is contained in:
微同科技
2020-11-11 23:50:31 +08:00
committed by GitHub
parent f301912154
commit edc04cb0ae
4 changed files with 162 additions and 2 deletions

View File

@@ -18,6 +18,10 @@ public interface WxMaLiveService {
String GET_LIVE_INFO = "https://api.weixin.qq.com/wxa/business/getliveinfo";
String CREATE_ROOM = "https://api.weixin.qq.com/wxaapi/broadcast/room/create";
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";
/**
* 创建直播间
@@ -33,6 +37,61 @@ public interface WxMaLiveService {
*/
Integer createRoom(WxMaLiveRoomInfo roomInfo) throws WxErrorException;
/**
* 删除直播间
* <pre>
* 调用额度10000次/一天
* 文档地址https://developers.weixin.qq.com/miniprogram/dev/framework/liveplayer/studio-api.html#5
* http请求方式POST https://api.weixin.qq.com/wxaapi/broadcast/room/deleteroom?access_token=ACCESS_TOKEN
* </pre>
*
* @param roomId 直播间id
* @return .
* @throws WxErrorException .
*/
boolean deleteRoom(Integer roomId) throws WxErrorException;
/**
* 编辑直播间
* <pre>
* 调用此接口编辑直播间调用额度10000次/一天
* 文档地址https://developers.weixin.qq.com/miniprogram/dev/framework/liveplayer/studio-api.html#6
* http请求方式POST https://api.weixin.qq.com/wxaapi/broadcast/room/editroom?access_token=ACCESS_TOKEN
* </pre>
*
* @param roomInfo 直播间信息
* @return .
* @throws WxErrorException .
*/
boolean editRoom(WxMaLiveRoomInfo roomInfo) throws WxErrorException;
/**
* 获取直播间推流地址
* <pre>
* 调用额度10000次/一天
* 文档地址https://developers.weixin.qq.com/miniprogram/dev/framework/liveplayer/studio-api.html#7
* http请求方式GET https://api.weixin.qq.com/wxaapi/broadcast/room/getpushurl?access_token=ACCESS_TOKEN
* </pre>
*
* @param roomId 直播间id
* @return .
* @throws WxErrorException .
*/
String getPushUrl(Integer roomId) throws WxErrorException;
/**
* 获取直播间分享二维码
* <pre>
* 调用额度10000次/一天
* 文档地址https://developers.weixin.qq.com/miniprogram/dev/framework/liveplayer/studio-api.html#8
* http请求方式GET https://api.weixin.qq.com/wxaapi/broadcast/room/getsharedcode?access_token=ACCESS_TOKEN
* </pre>
*
* @param roomId 直播间id
* @return .
* @throws WxErrorException .
*/
String getSharedCode(Integer roomId, String params) throws WxErrorException;
/**
* 获取直播房间列表.(分页)
*

View File

@@ -5,6 +5,7 @@ import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.live.WxMaLiveResult;
import cn.binarywang.wx.miniapp.bean.live.WxMaLiveRoomInfo;
import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder;
import com.google.common.base.Joiner;
import com.google.gson.JsonObject;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -40,6 +41,55 @@ public class WxMaLiveServiceImpl implements WxMaLiveService {
return jsonObject.get("roomId").getAsInt();
}
@Override
public boolean deleteRoom(Integer roomId) throws WxErrorException {
Map<String, Object> map = new HashMap<>(2);
map.put("id", roomId);
String responseContent = this.wxMaService.post(DELETE_ROOM, 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 editRoom(WxMaLiveRoomInfo roomInfo) throws WxErrorException {
String responseContent = this.wxMaService.post(EDIT_ROOM, WxMaGsonBuilder.create().toJson(roomInfo));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get("errcode").getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return true;
}
@Override
public String getPushUrl(Integer roomId) throws WxErrorException {
Map<String, Object> map = new HashMap<>(2);
map.put("roomId", roomId);
String responseContent = this.wxMaService.get(GET_PUSH_URL, Joiner.on("&").withKeyValueSeparator("=").join(map));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get("errcode").getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return jsonObject.get("pushAddr").getAsString();
}
@Override
public String getSharedCode(Integer roomId, String params) throws WxErrorException {
Map<String, Object> map = new HashMap<>(2);
map.put("roomId", roomId);
if (null != params) {
map.put("params", params);
}
String responseContent = this.wxMaService.get(GET_SHARED_CODE, Joiner.on("&").withKeyValueSeparator("=").join(map));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get("errcode").getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
return jsonObject.get("cdnUrl").getAsString();
}
@Override
public WxMaLiveResult getLiveInfo(Integer start, Integer limit) throws WxErrorException {
JsonObject jsonObject = getLiveInfo(start, limit, null);

View File

@@ -11,6 +11,10 @@ import java.io.Serializable;
public class WxMaLiveRoomInfo implements Serializable {
private static final long serialVersionUID = 7745775280267417154L;
/**
* 直播间ID
*/
private Integer id;
/**
* 直播间名字最短3个汉字最长17个汉字1个汉字相当于2个字符
**/
@@ -39,6 +43,10 @@ public class WxMaLiveRoomInfo implements Serializable {
* 主播副号微信号,如果未实名认证,需要先前往“小程序直播”小程序进行实名验证, 小程序二维码链接https://res.wx.qq.com/op_res/BbVNeczA1XudfjVqCVoKgfuWe7e3aUhokktRVOqf_F0IqS6kYR--atCpVNUUC3zr
**/
private String subAnchorWechat;
/**
* 创建者微信号,不传入则此直播间所有成员可见。传入则此房间仅创建者、管理员、超管、直播间主播可见
**/
private String createrWechat;
/**
* 分享图填入mediaIDmediaID获取后三天内有效图片mediaID的获取请参考以下文档 https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/New_temporary_materials.html直播间分享图图片规则建议像素800*640大小不超过1M
**/