Skip to content

Commit c605330

Browse files
authored
🆕 #1869 【小程序】增加管理直播间小助手的相关接口
1 parent a2074a4 commit c605330

File tree

4 files changed

+222
-14
lines changed

4 files changed

+222
-14
lines changed

weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaLiveService.java

+66
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package cn.binarywang.wx.miniapp.api;
22

3+
import cn.binarywang.wx.miniapp.bean.live.WxMaAssistantResult;
4+
import cn.binarywang.wx.miniapp.bean.live.WxMaLiveAssistantInfo;
35
import cn.binarywang.wx.miniapp.bean.live.WxMaLiveResult;
46
import cn.binarywang.wx.miniapp.bean.live.WxMaLiveRoomInfo;
57
import me.chanjar.weixin.common.error.WxErrorException;
@@ -22,6 +24,10 @@ public interface WxMaLiveService {
2224
String EDIT_ROOM = "https://api.weixin.qq.com/wxaapi/broadcast/room/editroom";
2325
String GET_PUSH_URL = "https://api.weixin.qq.com/wxaapi/broadcast/room/getpushurl";
2426
String GET_SHARED_CODE = "https://api.weixin.qq.com/wxaapi/broadcast/room/getsharedcode";
27+
String ADD_ASSISTANT = "https://api.weixin.qq.com/wxaapi/broadcast/room/addassistant";
28+
String MODIFY_ASSISTANT = "https://api.weixin.qq.com/wxaapi/broadcast/room/modifyassistant";
29+
String REMOVE_ASSISTANT = "https://api.weixin.qq.com/wxaapi/broadcast/room/removeassistant";
30+
String GET_ASSISTANT_LIST = "https://api.weixin.qq.com/wxaapi/broadcast/room/getassistantlist";
2531

2632
/**
2733
* 创建直播间
@@ -150,4 +156,64 @@ public interface WxMaLiveService {
150156
* @throws WxErrorException .
151157
*/
152158
boolean addGoodsToRoom(Integer roomId, List<Integer> goodsIds) throws WxErrorException;
159+
/**
160+
* 添加管理直播间小助手
161+
* <p>
162+
* 调用接口往指定直播间添加管理直播间小助手
163+
* 调用频率
164+
* 调用额度:10000次/一天
165+
* <p>
166+
* http请求方式:POST https://api.weixin.qq.com/wxaapi/broadcast/room/addassistant?access_token=ACCESS_TOKEN
167+
* <pre>
168+
* @param roomId 房间ID
169+
* @param users 数组列表,可传入多个,"users": [{"username":"testwechat","nickname":"testnick"}]
170+
* @return 添加管理直播间小助手是否成功
171+
* @throws WxErrorException .
172+
*/
173+
boolean addAssistant(Integer roomId, List<WxMaLiveAssistantInfo> users) throws WxErrorException;
174+
/**
175+
* 修改直播间小助手昵称
176+
* <p>
177+
* 调用接口修改直播间小助手昵称
178+
* 调用频率
179+
* 调用额度:10000次/一天
180+
* <p>
181+
* http请求方式:POST https://api.weixin.qq.com/wxaapi/broadcast/room/modifyassistant?access_token=ACCESS_TOKEN
182+
* <pre>
183+
* @param roomId 房间ID
184+
* @param username 小助手微信号
185+
* @param nickname 小助手直播间昵称
186+
* @return 修改小助手昵称是否成功
187+
* @throws WxErrorException .
188+
*/
189+
boolean modifyAssistant(Integer roomId, String username,String nickname) throws WxErrorException;
190+
/**
191+
* 删除直播间小助手
192+
* <p>
193+
* 删除直播间小助手
194+
* 调用频率
195+
* 调用额度:10000次/一天
196+
* <p>
197+
* http请求方式:POST https://api.weixin.qq.com/wxaapi/broadcast/room/removeassistant?access_token=ACCESS_TOKEN
198+
* <pre>
199+
* @param roomId 房间ID
200+
* @param username 小助手微信号
201+
* @return 删除小助手昵称是否成功
202+
* @throws WxErrorException .
203+
*/
204+
boolean removeAssistant(Integer roomId, String username) throws WxErrorException;
205+
/**
206+
* 查询直播间小助手
207+
* <p>
208+
* 查询直播间小助手
209+
* 调用频率
210+
* 调用额度:10000次/一天
211+
* <p>
212+
* http请求方式:POST https://api.weixin.qq.com/wxaapi/broadcast/room/getassistantlist?access_token=ACCESS_TOKEN
213+
* <pre>
214+
* @param roomId 房间ID
215+
* @return 小助手列表
216+
* @throws WxErrorException .
217+
*/
218+
List<WxMaAssistantResult.Assistant> getAssistantList(Integer roomId) throws WxErrorException;
153219
}

weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaLiveServiceImpl.java

+69-14
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import cn.binarywang.wx.miniapp.api.WxMaLiveService;
44
import cn.binarywang.wx.miniapp.api.WxMaService;
5+
import cn.binarywang.wx.miniapp.bean.live.WxMaAssistantResult;
6+
import cn.binarywang.wx.miniapp.bean.live.WxMaLiveAssistantInfo;
57
import cn.binarywang.wx.miniapp.bean.live.WxMaLiveResult;
68
import cn.binarywang.wx.miniapp.bean.live.WxMaLiveRoomInfo;
79
import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder;
@@ -90,12 +92,6 @@ public String getSharedCode(Integer roomId, String params) throws WxErrorExcepti
9092
return jsonObject.get("cdnUrl").getAsString();
9193
}
9294

93-
@Override
94-
public WxMaLiveResult getLiveInfo(Integer start, Integer limit) throws WxErrorException {
95-
JsonObject jsonObject = getLiveInfo(start, limit, null);
96-
return WxMaLiveResult.fromJson(jsonObject.toString());
97-
}
98-
9995
@Override
10096
public List<WxMaLiveResult.RoomInfo> getLiveInfos() throws WxErrorException {
10197
List<WxMaLiveResult.RoomInfo> results = new ArrayList<>();
@@ -124,6 +120,13 @@ public List<WxMaLiveResult.RoomInfo> getLiveInfos() throws WxErrorException {
124120
return results;
125121
}
126122

123+
@Override
124+
public WxMaLiveResult getLiveInfo(Integer start, Integer limit) throws WxErrorException {
125+
JsonObject jsonObject = getLiveInfo(start, limit, null);
126+
return WxMaLiveResult.fromJson(jsonObject.toString());
127+
}
128+
129+
127130
@Override
128131
public WxMaLiveResult getLiveReplay(String action, Integer roomId, Integer start, Integer limit) throws WxErrorException {
129132
Map<String, Object> map = new HashMap<>(4);
@@ -132,7 +135,19 @@ public WxMaLiveResult getLiveReplay(String action, Integer roomId, Integer start
132135
JsonObject jsonObject = getLiveInfo(start, limit, map);
133136
return WxMaLiveResult.fromJson(jsonObject.toString());
134137
}
135-
138+
private JsonObject getLiveInfo(Integer start, Integer limit, Map<String, Object> map) throws WxErrorException {
139+
if (map == null) {
140+
map = new HashMap(2);
141+
}
142+
map.put("start", start);
143+
map.put("limit", limit);
144+
String responseContent = wxMaService.post(GET_LIVE_INFO, WxMaGsonBuilder.create().toJson(map));
145+
JsonObject jsonObject = GsonParser.parse(responseContent);
146+
if (jsonObject.get("errcode").getAsInt() != 0) {
147+
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
148+
}
149+
return jsonObject;
150+
}
136151
@Override
137152
public WxMaLiveResult getLiveReplay(Integer roomId, Integer start, Integer limit) throws WxErrorException {
138153
return getLiveReplay("get_replay", roomId, start, limit);
@@ -151,17 +166,57 @@ public boolean addGoodsToRoom(Integer roomId, List<Integer> goodsIds) throws WxE
151166
return true;
152167
}
153168

154-
private JsonObject getLiveInfo(Integer start, Integer limit, Map<String, Object> map) throws WxErrorException {
155-
if (map == null) {
156-
map = new HashMap(2);
169+
@Override
170+
public boolean addAssistant(Integer roomId, List<WxMaLiveAssistantInfo> users) throws WxErrorException {
171+
Map<String, Object> map = new HashMap<>(2);
172+
map.put("roomId", roomId);
173+
map.put("users", users);
174+
String responseContent = this.wxMaService.post(ADD_ASSISTANT, WxMaGsonBuilder.create().toJson(map));
175+
JsonObject jsonObject = GsonParser.parse(responseContent);
176+
if (jsonObject.get("errcode").getAsInt() != 0) {
177+
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
157178
}
158-
map.put("start", start);
159-
map.put("limit", limit);
160-
String responseContent = wxMaService.post(GET_LIVE_INFO, WxMaGsonBuilder.create().toJson(map));
179+
return true;
180+
}
181+
182+
@Override
183+
public boolean modifyAssistant(Integer roomId, String username,String nickname) throws WxErrorException {
184+
Map<String, Object> map = new HashMap<>(2);
185+
map.put("roomId", roomId);
186+
map.put("username",username);
187+
map.put("nickname", nickname);
188+
String responseContent = this.wxMaService.post(MODIFY_ASSISTANT, WxMaGsonBuilder.create().toJson(map));
161189
JsonObject jsonObject = GsonParser.parse(responseContent);
162190
if (jsonObject.get("errcode").getAsInt() != 0) {
163191
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
164192
}
165-
return jsonObject;
193+
return true;
194+
}
195+
196+
@Override
197+
public boolean removeAssistant(Integer roomId,String username) throws WxErrorException {
198+
Map<String, Object> map = new HashMap<>(2);
199+
map.put("roomId", roomId);
200+
map.put("username",username);
201+
String responseContent = this.wxMaService.post(REMOVE_ASSISTANT, WxMaGsonBuilder.create().toJson(map));
202+
JsonObject jsonObject = GsonParser.parse(responseContent);
203+
if (jsonObject.get("errcode").getAsInt() != 0) {
204+
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
205+
}
206+
return true;
166207
}
208+
209+
@Override
210+
public List<WxMaAssistantResult.Assistant> getAssistantList(Integer roomId) throws WxErrorException {
211+
Map<String, Object> map = new HashMap<>(2);
212+
map.put("roomId", roomId);
213+
String responseContent = this.wxMaService.post(GET_ASSISTANT_LIST, WxMaGsonBuilder.create().toJson(map));
214+
JsonObject jsonObject = GsonParser.parse(responseContent);
215+
if (jsonObject.get("errcode").getAsInt() != 0) {
216+
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
217+
}
218+
return WxMaAssistantResult.fromJson(responseContent).getList();
219+
}
220+
221+
167222
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package cn.binarywang.wx.miniapp.bean.live;
2+
3+
import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder;
4+
import lombok.Data;
5+
6+
import java.io.Serializable;
7+
import java.util.List;
8+
9+
/**
10+
* 直播间小助手用户信息
11+
*/
12+
@Data
13+
public class WxMaAssistantResult implements Serializable {
14+
private static final long serialVersionUID = 5829108618580715870L;
15+
16+
private Integer count;
17+
private Integer maxCount;
18+
private Integer errcode;
19+
20+
private List<Assistant> list;
21+
22+
public static WxMaAssistantResult fromJson(String json) {
23+
return WxMaGsonBuilder.create().fromJson(json, WxMaAssistantResult.class);
24+
}
25+
@Data
26+
public static class Assistant implements Serializable {
27+
private static final long serialVersionUID = 6362128855371134033L;
28+
/**
29+
* 修改时间
30+
*/
31+
private Long timestamp;
32+
/**
33+
* 头像
34+
**/
35+
private String headimg;
36+
/**
37+
* 用户昵称
38+
**/
39+
private String nickname;
40+
/**
41+
* 微信号
42+
**/
43+
private String alias;
44+
/**
45+
* openid
46+
**/
47+
private String openid;
48+
}
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package cn.binarywang.wx.miniapp.bean.live;
2+
3+
import lombok.Data;
4+
5+
import java.io.Serializable;
6+
7+
/**
8+
* 直播间小助手用户信息
9+
*/
10+
@Data
11+
public class WxMaLiveAssistantInfo implements Serializable {
12+
private static final long serialVersionUID = -5603581848069320808L;
13+
/**
14+
* 修改时间
15+
*/
16+
private Long timestamp;
17+
/**
18+
* 头像
19+
**/
20+
private String headimg;
21+
/**
22+
* 用户微信号
23+
**/
24+
private String username;
25+
/**
26+
* 用户昵称
27+
**/
28+
private String nickname;
29+
/**
30+
* 微信号
31+
**/
32+
private String alias;
33+
/**
34+
* openid
35+
**/
36+
private String openid;
37+
38+
}

0 commit comments

Comments
 (0)