implements WxMaService, RequestH
return this.liveGoodsService;
}
+ @Override
+ public WxMaLiveMemberService getLiveMemberService() {
+ return this.liveMemberService;
+ }
+
@Override
public WxOcrService getOcrService() {
return this.ocrService;
diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaLiveGoodsServiceImpl.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaLiveGoodsServiceImpl.java
index da2fff572..99d82fdbf 100644
--- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaLiveGoodsServiceImpl.java
+++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaLiveGoodsServiceImpl.java
@@ -11,6 +11,7 @@ import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.error.WxErrorException;
+import me.chanjar.weixin.common.util.json.GsonHelper;
import me.chanjar.weixin.common.util.json.GsonParser;
import java.io.Serializable;
@@ -18,7 +19,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.LiveGoods.*;
+import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Broadcast.Goods.*;
/**
*
@@ -34,32 +35,26 @@ public class WxMaLiveGoodsServiceImpl implements WxMaLiveGoodsService {
@Override
public WxMaLiveResult addGoods(WxMaLiveGoodInfo goods) throws WxErrorException {
return WxMaLiveResult.fromJson(this.wxMaService.post(ADD_GOODS,
- WxMaGsonBuilder.create().toJson(ImmutableMap.of("goodsInfo", goods))));
+ GsonHelper.buildJsonObject("goodsInfo", goods)));
}
@Override
public boolean resetAudit(Integer auditId, Integer goodsId) throws WxErrorException {
- Map map = new HashMap<>(4);
- map.put("auditId", auditId);
- map.put("goodsId", goodsId);
- this.wxMaService.post(RESET_AUDIT_GOODS, WxMaGsonBuilder.create().toJson(map));
+ this.wxMaService.post(RESET_AUDIT_GOODS,
+ GsonHelper.buildJsonObject("auditId", auditId, "goodsId", goodsId));
return true;
}
@Override
public String auditGoods(Integer goodsId) throws WxErrorException {
- Map map = new HashMap<>(2);
- map.put("goodsId", goodsId);
- String responseContent = this.wxMaService.post(AUDIT_GOODS, WxMaGsonBuilder.create().toJson(map));
- JsonObject jsonObject = GsonParser.parse(responseContent);
- return jsonObject.get("auditId").getAsString();
+ String responseContent = this.wxMaService.post(AUDIT_GOODS,
+ GsonHelper.buildJsonObject("goodsId", goodsId));
+ return GsonParser.parse(responseContent).get("auditId").getAsString();
}
@Override
public boolean deleteGoods(Integer goodsId) throws WxErrorException {
- Map map = new HashMap<>(2);
- map.put("goodsId", goodsId);
- this.wxMaService.post(DELETE_GOODS, WxMaGsonBuilder.create().toJson(map));
+ this.wxMaService.post(DELETE_GOODS, GsonHelper.buildJsonObject("goodsId", goodsId));
return true;
}
diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaLiveMemberServiceImpl.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaLiveMemberServiceImpl.java
new file mode 100644
index 000000000..568630466
--- /dev/null
+++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaLiveMemberServiceImpl.java
@@ -0,0 +1,42 @@
+package cn.binarywang.wx.miniapp.api.impl;
+
+import cn.binarywang.wx.miniapp.api.WxMaLiveMemberService;
+import cn.binarywang.wx.miniapp.api.WxMaService;
+import cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Broadcast.Role;
+import com.google.gson.JsonArray;
+import lombok.RequiredArgsConstructor;
+import me.chanjar.weixin.common.error.WxErrorException;
+import me.chanjar.weixin.common.util.json.GsonHelper;
+import me.chanjar.weixin.common.util.json.GsonParser;
+
+import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Broadcast.Role.LIST_BY_ROLE;
+
+/**
+ * .
+ *
+ * @author Binary Wang
+ * @date 2021-02-15
+ */
+@RequiredArgsConstructor
+public class WxMaLiveMemberServiceImpl implements WxMaLiveMemberService {
+ private final WxMaService service;
+
+ @Override
+ public String addRole(String username, int role) throws WxErrorException {
+ return this.service.post(Role.ADD_ROLE,
+ GsonHelper.buildJsonObject("username", username, "role", role));
+ }
+
+ @Override
+ public String deleteRole(String username, int role) throws WxErrorException {
+ return this.service.post(Role.DELETE_ROLE,
+ GsonHelper.buildJsonObject("username", username, "role", role));
+ }
+
+ @Override
+ public JsonArray listByRole(Integer role, Integer offset, Integer limit, String keyword) throws WxErrorException {
+ final String response = this.service.get(LIST_BY_ROLE, GsonHelper.buildJsonObject("role", role, "offset", offset,
+ "limit", limit, "keyword", keyword).toString());
+ return GsonParser.parse(response).getAsJsonArray("list");
+ }
+}
diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaLiveServiceImpl.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaLiveServiceImpl.java
index 9040957c7..9e192eb48 100644
--- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaLiveServiceImpl.java
+++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaLiveServiceImpl.java
@@ -18,7 +18,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Live.*;
+import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Broadcast.*;
/**
*
@@ -36,7 +36,7 @@ public class WxMaLiveServiceImpl implements WxMaLiveService {
@Override
public WxMaCreateRoomResult createRoom(WxMaLiveRoomInfo roomInfo) throws WxErrorException {
- String responseContent = this.wxMaService.post(CREATE_ROOM, WxMaGsonBuilder.create().toJson(roomInfo));
+ String responseContent = this.wxMaService.post(Room.CREATE_ROOM, WxMaGsonBuilder.create().toJson(roomInfo));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
@@ -49,7 +49,7 @@ public class WxMaLiveServiceImpl implements WxMaLiveService {
public boolean deleteRoom(Integer roomId) throws WxErrorException {
Map map = new HashMap<>(2);
map.put("id", roomId);
- String responseContent = this.wxMaService.post(DELETE_ROOM, WxMaGsonBuilder.create().toJson(map));
+ String responseContent = this.wxMaService.post(Room.DELETE_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));
@@ -59,7 +59,7 @@ public class WxMaLiveServiceImpl implements WxMaLiveService {
@Override
public boolean editRoom(WxMaLiveRoomInfo roomInfo) throws WxErrorException {
- String responseContent = this.wxMaService.post(EDIT_ROOM, WxMaGsonBuilder.create().toJson(roomInfo));
+ String responseContent = this.wxMaService.post(Room.EDIT_ROOM, WxMaGsonBuilder.create().toJson(roomInfo));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
@@ -71,7 +71,7 @@ public class WxMaLiveServiceImpl implements WxMaLiveService {
public String getPushUrl(Integer roomId) throws WxErrorException {
Map map = new HashMap<>(2);
map.put(ROOM_ID, roomId);
- String responseContent = this.wxMaService.get(GET_PUSH_URL, Joiner.on("&").withKeyValueSeparator("=").join(map));
+ String responseContent = this.wxMaService.get(Room.GET_PUSH_URL, Joiner.on("&").withKeyValueSeparator("=").join(map));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
@@ -86,7 +86,7 @@ public class WxMaLiveServiceImpl implements WxMaLiveService {
if (null != params) {
map.put("params", params);
}
- String responseContent = this.wxMaService.get(GET_SHARED_CODE, Joiner.on("&").withKeyValueSeparator("=").join(map));
+ String responseContent = this.wxMaService.get(Room.GET_SHARED_CODE, Joiner.on("&").withKeyValueSeparator("=").join(map));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
@@ -162,7 +162,7 @@ public class WxMaLiveServiceImpl implements WxMaLiveService {
Map map = new HashMap<>(2);
map.put(ROOM_ID, roomId);
map.put("ids", goodsIds);
- String responseContent = this.wxMaService.post(ADD_GOODS, WxMaGsonBuilder.create().toJson(map));
+ String responseContent = this.wxMaService.post(Room.ADD_GOODS, WxMaGsonBuilder.create().toJson(map));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
@@ -175,7 +175,7 @@ public class WxMaLiveServiceImpl implements WxMaLiveService {
Map map = new HashMap<>(2);
map.put(ROOM_ID, roomId);
map.put("users", users);
- String responseContent = this.wxMaService.post(ADD_ASSISTANT, WxMaGsonBuilder.create().toJson(map));
+ String responseContent = this.wxMaService.post(Room.ADD_ASSISTANT, WxMaGsonBuilder.create().toJson(map));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
@@ -189,7 +189,7 @@ public class WxMaLiveServiceImpl implements WxMaLiveService {
map.put(ROOM_ID, roomId);
map.put("username", username);
map.put("nickname", nickname);
- String responseContent = this.wxMaService.post(MODIFY_ASSISTANT, WxMaGsonBuilder.create().toJson(map));
+ String responseContent = this.wxMaService.post(Room.MODIFY_ASSISTANT, WxMaGsonBuilder.create().toJson(map));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
@@ -202,7 +202,7 @@ public class WxMaLiveServiceImpl implements WxMaLiveService {
Map map = new HashMap<>(2);
map.put(ROOM_ID, roomId);
map.put("username", username);
- String responseContent = this.wxMaService.post(REMOVE_ASSISTANT, WxMaGsonBuilder.create().toJson(map));
+ String responseContent = this.wxMaService.post(Room.REMOVE_ASSISTANT, WxMaGsonBuilder.create().toJson(map));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
@@ -214,7 +214,7 @@ public class WxMaLiveServiceImpl implements WxMaLiveService {
public List getAssistantList(Integer roomId) throws WxErrorException {
Map map = new HashMap<>(2);
map.put(ROOM_ID, roomId);
- String responseContent = this.wxMaService.post(GET_ASSISTANT_LIST, WxMaGsonBuilder.create().toJson(map));
+ String responseContent = this.wxMaService.post(Room.GET_ASSISTANT_LIST, WxMaGsonBuilder.create().toJson(map));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/constant/WxMaApiUrlConstants.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/constant/WxMaApiUrlConstants.java
index 49f6a18db..84b1f806d 100644
--- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/constant/WxMaApiUrlConstants.java
+++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/constant/WxMaApiUrlConstants.java
@@ -157,28 +157,46 @@ public class WxMaApiUrlConstants {
String GET_JSAPI_TICKET_URL = "https://api.weixin.qq.com/cgi-bin/ticket/getticket";
}
- public interface LiveGoods {
- String ADD_GOODS = "https://api.weixin.qq.com/wxaapi/broadcast/goods/add";
- String RESET_AUDIT_GOODS = "https://api.weixin.qq.com/wxaapi/broadcast/goods/resetaudit";
- String AUDIT_GOODS = "https://api.weixin.qq.com/wxaapi/broadcast/goods/audit";
- String DELETE_GOODS = "https://api.weixin.qq.com/wxaapi/broadcast/goods/delete";
- String UPDATE_GOODS = "https://api.weixin.qq.com/wxaapi/broadcast/goods/update";
- String GET_GOODS_WARE_HOUSE = "https://api.weixin.qq.com/wxa/business/getgoodswarehouse";
- String GET_APPROVED_GOODS = "https://api.weixin.qq.com/wxaapi/broadcast/goods/getapproved";
- }
-
- public interface Live {
+ public interface Broadcast {
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";
- 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";
+
+ /**
+ * 直播间管理相关接口
+ */
+ interface Room {
+ 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";
+ 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";
+ }
+
+ /**
+ * 直播商品管理相关接口
+ */
+ interface Goods {
+ String ADD_GOODS = "https://api.weixin.qq.com/wxaapi/broadcast/goods/add";
+ String RESET_AUDIT_GOODS = "https://api.weixin.qq.com/wxaapi/broadcast/goods/resetaudit";
+ String AUDIT_GOODS = "https://api.weixin.qq.com/wxaapi/broadcast/goods/audit";
+ String DELETE_GOODS = "https://api.weixin.qq.com/wxaapi/broadcast/goods/delete";
+ String UPDATE_GOODS = "https://api.weixin.qq.com/wxaapi/broadcast/goods/update";
+ String GET_GOODS_WARE_HOUSE = "https://api.weixin.qq.com/wxa/business/getgoodswarehouse";
+ String GET_APPROVED_GOODS = "https://api.weixin.qq.com/wxaapi/broadcast/goods/getapproved";
+ }
+
+ /**
+ * 小程序直播成员管理接口
+ */
+ interface Role {
+ String ADD_ROLE = "https://api.weixin.qq.com/wxaapi/broadcast/role/addrole";
+ String DELETE_ROLE = "https://api.weixin.qq.com/wxaapi/broadcast/role/deleterole";
+ String LIST_BY_ROLE = "https://api.weixin.qq.com/wxaapi/broadcast/role/getrolelist";
+ }
}
public interface Media {
diff --git a/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaLiveMemberServiceImplTest.java b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaLiveMemberServiceImplTest.java
new file mode 100644
index 000000000..f5ffb59d7
--- /dev/null
+++ b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaLiveMemberServiceImplTest.java
@@ -0,0 +1,40 @@
+package cn.binarywang.wx.miniapp.api.impl;
+
+import cn.binarywang.wx.miniapp.api.WxMaService;
+import cn.binarywang.wx.miniapp.test.ApiTestModule;
+import com.google.gson.JsonArray;
+import com.google.inject.Inject;
+import me.chanjar.weixin.common.error.WxErrorException;
+import org.testng.annotations.Guice;
+import org.testng.annotations.Test;
+
+/**
+ * 测试.
+ *
+ * @author Binary Wang
+ * @date 2021-02-15
+ */
+@Test
+@Guice(modules = ApiTestModule.class)
+public class WxMaLiveMemberServiceImplTest {
+ @Inject
+ private WxMaService wxService;
+
+ @Test
+ public void testAddRole() throws WxErrorException {
+ final String result = this.wxService.getLiveMemberService().addRole("abc", 1);
+ System.out.println(result);
+ }
+
+ @Test
+ public void testDeleteRole() throws WxErrorException {
+ final String result = this.wxService.getLiveMemberService().deleteRole("abc", 1);
+ System.out.println(result);
+ }
+
+ @Test
+ public void testListByRole() throws WxErrorException {
+ final JsonArray result = this.wxService.getLiveMemberService().listByRole(null, null, null, null);
+ System.out.println(result);
+ }
+}