Skip to content

Commit

Permalink
🆕 #1863 【小程序】增加删除直播间、编辑直播间、获取直播间推流地址、获取直播间分享二维码等接口
Browse files Browse the repository at this point in the history
  • Loading branch information
lipengjun92 authored Nov 11, 2020
1 parent f301912 commit edc04cb
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";

/**
* 创建直播间
Expand All @@ -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;
/**
* 获取直播房间列表.(分页)
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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;
Expand Down Expand Up @@ -40,6 +41,55 @@ public Integer createRoom(WxMaLiveRoomInfo roomInfo) throws WxErrorException {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
public class WxMaLiveRoomInfo implements Serializable {
private static final long serialVersionUID = 7745775280267417154L;

/**
* 直播间ID
*/
private Integer id;
/**
* 直播间名字,最短3个汉字,最长17个汉字,1个汉字相当于2个字符
**/
Expand Down Expand Up @@ -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;
/**
* 分享图,填入mediaID(mediaID获取后,三天内有效);图片mediaID的获取,请参考以下文档: https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/New_temporary_materials.html;直播间分享图,图片规则:建议像素800*640,大小不超过1M;
**/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ public void createRoom() throws Exception {
roomInfo.setName("订阅通知直播间");
roomInfo.setCoverImg(mediaUpload.getMediaId());
Calendar c = Calendar.getInstance();
c.set(2020, Calendar.SEPTEMBER, 10, 8, 0);
c.set(2020, Calendar.DECEMBER, 10, 8, 0);
roomInfo.setStartTime(c.getTimeInMillis() / 1000);
c.set(2020, Calendar.SEPTEMBER, 10, 12, 0);
c.set(2020, Calendar.DECEMBER, 10, 12, 0);
roomInfo.setEndTime(c.getTimeInMillis() / 1000);
roomInfo.setAnchorName("鹏军_专业小程序开发");
roomInfo.setAnchorWechat("pengjun939961241");
roomInfo.setCreaterWechat("pengjun939961241");
roomInfo.setShareImg(mediaUpload.getMediaId());
roomInfo.setType(1);
roomInfo.setScreenType(1);
Expand All @@ -53,6 +54,48 @@ public void createRoom() throws Exception {
System.out.println(roomId);
}

@Test
public void deletRoom() throws Exception {
this.wxService.getLiveService().deleteRoom(29);
}

@Test
public void editRoom() throws Exception {
//上传临时素材
// WxMediaUploadResult mediaUpload = this.wxService.getMediaService().uploadMedia("image", new File("E:\\1.png"));

WxMaLiveRoomInfo roomInfo = new WxMaLiveRoomInfo();
roomInfo.setId(39);
roomInfo.setName("修改订阅通知直播间");
roomInfo.setCoverImg("http://mmbiz.qpic.cn/mmbiz_png/omYktZNGamuBLBYlP2FjpIL2AHoiayH8HXeZRibtXDMesHn5aevEaM4etUVwfnX1HHqrXBDY3KPgT8MIlqbtqX8Q/0");
Calendar c = Calendar.getInstance();
c.set(2021, Calendar.SEPTEMBER, 10, 8, 0);
roomInfo.setStartTime(c.getTimeInMillis() / 1000);
c.set(2021, Calendar.SEPTEMBER, 10, 12, 0);
roomInfo.setEndTime(c.getTimeInMillis() / 1000);
roomInfo.setAnchorName("鹏军_专业小程序开发");
roomInfo.setAnchorWechat("pengjun939961241");
roomInfo.setShareImg("http://mmbiz.qpic.cn/mmbiz_png/omYktZNGamuBLBYlP2FjpIL2AHoiayH8HXeZRibtXDMesHn5aevEaM4etUVwfnX1HHqrXBDY3KPgT8MIlqbtqX8Q/0");
roomInfo.setType(1);
roomInfo.setScreenType(1);
roomInfo.setCloseLike(0);
roomInfo.setCloseGoods(0);
roomInfo.setCloseComment(0);
boolean editRoom = this.wxService.getLiveService().editRoom(roomInfo);
System.out.println(editRoom);
}
@Test
public void getPushUrl() throws Exception {
String result = this.wxService.getLiveService().getPushUrl(39);
System.out.println(result);
}

@Test
public void getSharedCode() throws Exception {
String result = this.wxService.getLiveService().getSharedCode(39, null);
System.out.println(result);
}

@Test
public void getLiveInfo() throws Exception {
WxMaLiveResult list = this.wxService.getLiveService().getLiveInfo(0, 10);
Expand Down

0 comments on commit edc04cb

Please sign in to comment.