|
|
|
|
@@ -2,10 +2,7 @@ package cn.binarywang.wx.miniapp.api.impl;
|
|
|
|
|
|
|
|
|
|
import cn.binarywang.wx.miniapp.api.WxMaLiveService;
|
|
|
|
|
import cn.binarywang.wx.miniapp.api.WxMaService;
|
|
|
|
|
import cn.binarywang.wx.miniapp.bean.live.WxMaAssistantResult;
|
|
|
|
|
import cn.binarywang.wx.miniapp.bean.live.WxMaLiveAssistantInfo;
|
|
|
|
|
import cn.binarywang.wx.miniapp.bean.live.WxMaLiveResult;
|
|
|
|
|
import cn.binarywang.wx.miniapp.bean.live.WxMaLiveRoomInfo;
|
|
|
|
|
import cn.binarywang.wx.miniapp.bean.live.*;
|
|
|
|
|
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
|
|
|
|
|
import com.google.common.base.Joiner;
|
|
|
|
|
import com.google.gson.JsonObject;
|
|
|
|
|
@@ -31,16 +28,19 @@ import java.util.Map;
|
|
|
|
|
@Slf4j
|
|
|
|
|
@AllArgsConstructor
|
|
|
|
|
public class WxMaLiveServiceImpl implements WxMaLiveService {
|
|
|
|
|
private static final String ERR_CODE = "errcode";
|
|
|
|
|
private static final String ROOM_ID = "roomId";
|
|
|
|
|
private final WxMaService wxMaService;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Integer createRoom(WxMaLiveRoomInfo roomInfo) throws WxErrorException {
|
|
|
|
|
public WxMaCreateRoomResult createRoom(WxMaLiveRoomInfo roomInfo) throws WxErrorException {
|
|
|
|
|
String responseContent = this.wxMaService.post(CREATE_ROOM, WxMaGsonBuilder.create().toJson(roomInfo));
|
|
|
|
|
JsonObject jsonObject = GsonParser.parse(responseContent);
|
|
|
|
|
if (jsonObject.get("errcode").getAsInt() != 0) {
|
|
|
|
|
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
|
|
|
|
|
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
|
|
|
|
|
}
|
|
|
|
|
return jsonObject.get("roomId").getAsInt();
|
|
|
|
|
|
|
|
|
|
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaCreateRoomResult.class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@@ -49,7 +49,7 @@ public class WxMaLiveServiceImpl implements WxMaLiveService {
|
|
|
|
|
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) {
|
|
|
|
|
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
|
|
|
|
|
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
@@ -59,7 +59,7 @@ public class WxMaLiveServiceImpl implements WxMaLiveService {
|
|
|
|
|
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) {
|
|
|
|
|
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
|
|
|
|
|
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
@@ -68,10 +68,10 @@ public class WxMaLiveServiceImpl implements WxMaLiveService {
|
|
|
|
|
@Override
|
|
|
|
|
public String getPushUrl(Integer roomId) throws WxErrorException {
|
|
|
|
|
Map<String, Object> map = new HashMap<>(2);
|
|
|
|
|
map.put("roomId", roomId);
|
|
|
|
|
map.put(ROOM_ID, 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) {
|
|
|
|
|
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
|
|
|
|
|
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
|
|
|
|
|
}
|
|
|
|
|
return jsonObject.get("pushAddr").getAsString();
|
|
|
|
|
@@ -80,13 +80,13 @@ public class WxMaLiveServiceImpl implements WxMaLiveService {
|
|
|
|
|
@Override
|
|
|
|
|
public String getSharedCode(Integer roomId, String params) throws WxErrorException {
|
|
|
|
|
Map<String, Object> map = new HashMap<>(2);
|
|
|
|
|
map.put("roomId", roomId);
|
|
|
|
|
map.put(ROOM_ID, 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) {
|
|
|
|
|
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
|
|
|
|
|
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
|
|
|
|
|
}
|
|
|
|
|
return jsonObject.get("cdnUrl").getAsString();
|
|
|
|
|
@@ -135,19 +135,21 @@ public class WxMaLiveServiceImpl implements WxMaLiveService {
|
|
|
|
|
JsonObject jsonObject = getLiveInfo(start, limit, map);
|
|
|
|
|
return WxMaLiveResult.fromJson(jsonObject.toString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private JsonObject getLiveInfo(Integer start, Integer limit, Map<String, Object> map) throws WxErrorException {
|
|
|
|
|
if (map == null) {
|
|
|
|
|
map = new HashMap(2);
|
|
|
|
|
map = new HashMap<>(2);
|
|
|
|
|
}
|
|
|
|
|
map.put("start", start);
|
|
|
|
|
map.put("limit", limit);
|
|
|
|
|
String responseContent = wxMaService.post(GET_LIVE_INFO, WxMaGsonBuilder.create().toJson(map));
|
|
|
|
|
JsonObject jsonObject = GsonParser.parse(responseContent);
|
|
|
|
|
if (jsonObject.get("errcode").getAsInt() != 0) {
|
|
|
|
|
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
|
|
|
|
|
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
|
|
|
|
|
}
|
|
|
|
|
return jsonObject;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public WxMaLiveResult getLiveReplay(Integer roomId, Integer start, Integer limit) throws WxErrorException {
|
|
|
|
|
return getLiveReplay("get_replay", roomId, start, limit);
|
|
|
|
|
@@ -156,11 +158,11 @@ public class WxMaLiveServiceImpl implements WxMaLiveService {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean addGoodsToRoom(Integer roomId, List<Integer> goodsIds) throws WxErrorException {
|
|
|
|
|
Map<String, Object> map = new HashMap<>(2);
|
|
|
|
|
map.put("roomId", roomId);
|
|
|
|
|
map.put(ROOM_ID, roomId);
|
|
|
|
|
map.put("ids", goodsIds);
|
|
|
|
|
String responseContent = this.wxMaService.post(ADD_GOODS, WxMaGsonBuilder.create().toJson(map));
|
|
|
|
|
JsonObject jsonObject = GsonParser.parse(responseContent);
|
|
|
|
|
if (jsonObject.get("errcode").getAsInt() != 0) {
|
|
|
|
|
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
|
|
|
|
|
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
@@ -169,38 +171,38 @@ public class WxMaLiveServiceImpl implements WxMaLiveService {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean addAssistant(Integer roomId, List<WxMaLiveAssistantInfo> users) throws WxErrorException {
|
|
|
|
|
Map<String, Object> map = new HashMap<>(2);
|
|
|
|
|
map.put("roomId", roomId);
|
|
|
|
|
map.put(ROOM_ID, roomId);
|
|
|
|
|
map.put("users", users);
|
|
|
|
|
String responseContent = this.wxMaService.post(ADD_ASSISTANT, WxMaGsonBuilder.create().toJson(map));
|
|
|
|
|
JsonObject jsonObject = GsonParser.parse(responseContent);
|
|
|
|
|
if (jsonObject.get("errcode").getAsInt() != 0) {
|
|
|
|
|
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
|
|
|
|
|
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean modifyAssistant(Integer roomId, String username,String nickname) throws WxErrorException {
|
|
|
|
|
public boolean modifyAssistant(Integer roomId, String username, String nickname) throws WxErrorException {
|
|
|
|
|
Map<String, Object> map = new HashMap<>(2);
|
|
|
|
|
map.put("roomId", roomId);
|
|
|
|
|
map.put("username",username);
|
|
|
|
|
map.put(ROOM_ID, roomId);
|
|
|
|
|
map.put("username", username);
|
|
|
|
|
map.put("nickname", nickname);
|
|
|
|
|
String responseContent = this.wxMaService.post(MODIFY_ASSISTANT, WxMaGsonBuilder.create().toJson(map));
|
|
|
|
|
JsonObject jsonObject = GsonParser.parse(responseContent);
|
|
|
|
|
if (jsonObject.get("errcode").getAsInt() != 0) {
|
|
|
|
|
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
|
|
|
|
|
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean removeAssistant(Integer roomId,String username) throws WxErrorException {
|
|
|
|
|
public boolean removeAssistant(Integer roomId, String username) throws WxErrorException {
|
|
|
|
|
Map<String, Object> map = new HashMap<>(2);
|
|
|
|
|
map.put("roomId", roomId);
|
|
|
|
|
map.put("username",username);
|
|
|
|
|
map.put(ROOM_ID, roomId);
|
|
|
|
|
map.put("username", username);
|
|
|
|
|
String responseContent = this.wxMaService.post(REMOVE_ASSISTANT, WxMaGsonBuilder.create().toJson(map));
|
|
|
|
|
JsonObject jsonObject = GsonParser.parse(responseContent);
|
|
|
|
|
if (jsonObject.get("errcode").getAsInt() != 0) {
|
|
|
|
|
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
|
|
|
|
|
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
@@ -209,14 +211,13 @@ public class WxMaLiveServiceImpl implements WxMaLiveService {
|
|
|
|
|
@Override
|
|
|
|
|
public List<WxMaAssistantResult.Assistant> getAssistantList(Integer roomId) throws WxErrorException {
|
|
|
|
|
Map<String, Object> map = new HashMap<>(2);
|
|
|
|
|
map.put("roomId", roomId);
|
|
|
|
|
map.put(ROOM_ID, roomId);
|
|
|
|
|
String responseContent = this.wxMaService.post(GET_ASSISTANT_LIST, WxMaGsonBuilder.create().toJson(map));
|
|
|
|
|
JsonObject jsonObject = GsonParser.parse(responseContent);
|
|
|
|
|
if (jsonObject.get("errcode").getAsInt() != 0) {
|
|
|
|
|
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
|
|
|
|
|
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
|
|
|
|
|
}
|
|
|
|
|
return WxMaAssistantResult.fromJson(responseContent).getList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|