Skip to content

Commit be49b10

Browse files
authored
🎨 #2567 【小程序】直播间和商品、挂件组件等相关接口完善
1 parent 62645a4 commit be49b10

File tree

4 files changed

+448
-4
lines changed

4 files changed

+448
-4
lines changed

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

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import me.chanjar.weixin.common.error.WxErrorException;
55

66
import java.util.List;
7+
import java.util.Map;
78

89
/**
910
* <pre>
@@ -207,4 +208,190 @@ public interface WxMaLiveService {
207208
* @throws WxErrorException .
208209
*/
209210
List<WxMaAssistantResult.Assistant> getAssistantList(Integer roomId) throws WxErrorException;
211+
212+
/**
213+
* 添加主播副号
214+
* <p>
215+
* 调用接口添加主播副号
216+
* <p>
217+
* 调用额度:10000次/一天
218+
* <p>
219+
* http请求方式:POST https://api.weixin.qq.com/wxaapi/broadcast/room/addsubanchor?access_token=ACCESS_TOKEN
220+
* <pre>
221+
* @param roomId 房间ID
222+
* @param username 用户微信号
223+
* @return 是否成功
224+
* @throws WxErrorException .
225+
*/
226+
boolean addSubanchor(Integer roomId, String username) throws WxErrorException;
227+
228+
/**
229+
* 修改主播副号
230+
* <p>
231+
* 调用接口修改主播副号
232+
* <p>
233+
* 调用频率: 10000次/一天
234+
* <p>
235+
* http请求方式:POST https://api.weixin.qq.com/wxaapi/broadcast/room/modifyassistant?access_token=ACCESS_TOKEN
236+
* <pre>
237+
* @param roomId 房间ID
238+
* @param username 小助手微信号
239+
* @param username 用户微信号
240+
* @return 是否成功
241+
* @throws WxErrorException .
242+
*/
243+
boolean modifySubanchor(Integer roomId, String username) throws WxErrorException;
244+
245+
/**
246+
* 删除主播副号
247+
* <p>
248+
* 调用频率: 10000次/一天
249+
* <p>
250+
* http请求方式:POST https://api.weixin.qq.com/wxaapi/broadcast/room/deletesubanchor?access_token=ACCESS_TOKEN
251+
* <pre>
252+
* @param roomId 房间ID
253+
* @return 是否成功
254+
* @throws WxErrorException .
255+
*/
256+
boolean deleteSubanchor(Integer roomId) throws WxErrorException;
257+
258+
/**
259+
* 获取主播副号
260+
* <p>
261+
* 调用额度:10000次/一天
262+
* <p>
263+
* http请求方式:GET https://api.weixin.qq.com/wxaapi/broadcast/room/getsubanchor?access_token=ACCESS_TOKEN
264+
* </pre>
265+
* @param roomId 直播间id
266+
* @return .
267+
* @throws WxErrorException .
268+
*/
269+
String getSubanchor(Integer roomId) throws WxErrorException;
270+
271+
/**
272+
* 开启/关闭直播间官方收录
273+
* <p>
274+
* 调用额度:10000次/一天
275+
* <p>
276+
* http请求方式:POST https://api.weixin.qq.com/wxaapi/broadcast/room/updatefeedpublic?access_token=ACCESS_TOKEN
277+
* <pre>
278+
* @param roomId 房间ID
279+
* @param isFeedsPublic 是否开启官方收录 【1: 开启,0:关闭】
280+
* @return 是否成功
281+
* @throws WxErrorException .
282+
*/
283+
boolean updatefeedpublic(Integer roomId, Integer isFeedsPublic) throws WxErrorException;
284+
285+
/**
286+
* 开启/关闭回放功能
287+
* <p>
288+
* 调用额度:10000次/一天
289+
* <p>
290+
* http请求方式:POST https://api.weixin.qq.com/wxaapi/broadcast/room/updatereplay?access_token=ACCESS_TOKEN
291+
* <pre>
292+
* @param roomId 房间ID
293+
* @param closeReplay 是否关闭回放 【0:开启,1:关闭】
294+
* @return 是否成功
295+
* @throws WxErrorException .
296+
*/
297+
boolean updatereplay(Integer roomId, Integer closeReplay) throws WxErrorException;
298+
299+
/**
300+
* 开启/关闭客服功能
301+
* <p>
302+
* 调用额度:10000次/一天
303+
* <p>
304+
* http请求方式:POST https://api.weixin.qq.com/wxaapi/broadcast/room/updatekf?access_token=ACCESS_TOKEN
305+
* <pre>
306+
* @param roomId 房间ID
307+
* @param closeKf 是否关闭客服 【0:开启,1:关闭】
308+
* @return 是否成功
309+
* @throws WxErrorException .
310+
*/
311+
boolean updatekf(Integer roomId, Integer closeKf) throws WxErrorException;
312+
313+
/**
314+
* 开启/关闭直播间全局禁言
315+
* <p>
316+
* 调用额度:10000次/一天
317+
* <p>
318+
* http请求方式:POST https://api.weixin.qq.com/wxaapi/broadcast/room/updatecomment?access_token=ACCESS_TOKEN
319+
* <pre>
320+
* @param roomId 房间ID
321+
* @param banComment 1-禁言,0-取消禁言
322+
* @return 是否成功
323+
* @throws WxErrorException .
324+
*/
325+
boolean updatecomment(Integer roomId, Integer banComment) throws WxErrorException;
326+
327+
/**
328+
* 上下架商品
329+
* <p>
330+
* 调用额度:10000次/一天
331+
* <p>
332+
* http请求方式:POST https://api.weixin.qq.com/wxaapi/broadcast/goods/onsale?access_token=ACCESS_TOKEN
333+
* <pre>
334+
* @param roomId 房间ID
335+
* @param goodsId 商品ID
336+
* @param onSale 上下架 【0:下架,1:上架】
337+
* @return 是否成功
338+
* @throws WxErrorException .
339+
*/
340+
boolean onsale(Integer roomId, Integer goodsId, Integer onSale) throws WxErrorException;
341+
342+
/**
343+
* 删除直播间商品
344+
* <p>
345+
* 调用额度:10000次/一天
346+
* <p>
347+
* http请求方式:POST https://api.weixin.qq.com/wxaapi/broadcast/goods/deleteInRoom?access_token=ACCESS_TOKEN
348+
* <pre>
349+
* @param roomId 房间ID
350+
* @param goodsId 商品ID
351+
* @return 是否成功
352+
* @throws WxErrorException .
353+
*/
354+
boolean deleteInRoom(Integer roomId, Integer goodsId) throws WxErrorException;
355+
356+
/**
357+
* 推送商品
358+
* <p>
359+
* 调用额度:10000次/一天
360+
* <p>
361+
* http请求方式:POST https://api.weixin.qq.com/wxaapi/broadcast/goods/push?access_token=ACCESS_TOKEN
362+
* <pre>
363+
* @param roomId 房间ID
364+
* @param goodsId 商品ID
365+
* @return 是否成功
366+
* @throws WxErrorException .
367+
*/
368+
boolean push(Integer roomId, Integer goodsId) throws WxErrorException;
369+
370+
/**
371+
* 直播间商品排序
372+
* <p>
373+
* 调用额度:10000次/一天
374+
* <p>
375+
* http请求方式:POST https://api.weixin.qq.com/wxaapi/broadcast/goods/sort?access_token=ACCESS_TOKEN
376+
* <pre>
377+
* @param roomId 房间ID
378+
* @param goods 商品ID列表, 例如: [{"goodsId":"123"}, {"goodsId":"234"}]
379+
* @return 是否成功
380+
* @throws WxErrorException .
381+
*/
382+
boolean sort(Integer roomId, List<Map<String,String>> goods) throws WxErrorException;
383+
384+
/**
385+
* 下载商品讲解视频
386+
* <p>
387+
* 调用额度:10000次/一天
388+
* <p>
389+
* http请求方式:GET https://api.weixin.qq.com/wxaapi/broadcast/goods/getVideo?access_token=ACCESS_TOKEN
390+
* </pre>
391+
* @param roomId 直播间id
392+
* @param goodsId 商品ID
393+
* @return .
394+
* @throws WxErrorException .
395+
*/
396+
String getVideo(Integer roomId, Integer goodsId) throws WxErrorException;
210397
}

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

Lines changed: 169 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import java.util.List;
1919
import java.util.Map;
2020

21-
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Broadcast.GET_LIVE_INFO;
2221
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Broadcast.Room;
2322

2423
/**
@@ -152,7 +151,7 @@ private JsonObject getLiveInfo(Integer start, Integer limit, Map<String, Object>
152151
}
153152
map.put("start", start);
154153
map.put("limit", limit);
155-
String responseContent = wxMaService.post(GET_LIVE_INFO, WxMaGsonBuilder.create().toJson(map));
154+
String responseContent = wxMaService.post(Room.GET_LIVE_INFO, WxMaGsonBuilder.create().toJson(map));
156155
JsonObject jsonObject = GsonParser.parse(responseContent);
157156
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
158157
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
@@ -231,4 +230,172 @@ public List<WxMaAssistantResult.Assistant> getAssistantList(Integer roomId) thro
231230
return WxMaAssistantResult.fromJson(responseContent).getList();
232231
}
233232

233+
@Override
234+
public boolean addSubanchor(Integer roomId, String username) throws WxErrorException {
235+
Map<String, Object> map = new HashMap<>(2);
236+
map.put(ROOM_ID, roomId);
237+
map.put("username", username);
238+
String responseContent = this.wxMaService.post(Room.ADD_SUBANCHOR, WxMaGsonBuilder.create().toJson(map));
239+
JsonObject jsonObject = GsonParser.parse(responseContent);
240+
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
241+
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
242+
}
243+
return true;
244+
}
245+
246+
@Override
247+
public boolean modifySubanchor(Integer roomId, String username) throws WxErrorException {
248+
Map<String, Object> map = new HashMap<>(2);
249+
map.put(ROOM_ID, roomId);
250+
map.put("username", username);
251+
String responseContent = this.wxMaService.post(Room.MODIFY_SUBANCHOR, WxMaGsonBuilder.create().toJson(map));
252+
JsonObject jsonObject = GsonParser.parse(responseContent);
253+
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
254+
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
255+
}
256+
return true;
257+
}
258+
259+
@Override
260+
public boolean deleteSubanchor(Integer roomId) throws WxErrorException {
261+
Map<String, Object> map = new HashMap<>(1);
262+
map.put(ROOM_ID, roomId);
263+
String responseContent = this.wxMaService.post(Room.DELETE_SUBANCHOR, WxMaGsonBuilder.create().toJson(map));
264+
JsonObject jsonObject = GsonParser.parse(responseContent);
265+
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
266+
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
267+
}
268+
return true;
269+
}
270+
271+
@Override
272+
public String getSubanchor(Integer roomId) throws WxErrorException {
273+
Map<String, Object> map = new HashMap<>(1);
274+
map.put(ROOM_ID, roomId);
275+
String responseContent = this.wxMaService.get(Room.GET_SUBANCHOR, WxMaGsonBuilder.create().toJson(map));
276+
JsonObject jsonObject = GsonParser.parse(responseContent);
277+
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
278+
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
279+
}
280+
return jsonObject.get("username").getAsString();
281+
}
282+
283+
@Override
284+
public boolean updatefeedpublic(Integer roomId, Integer isFeedsPublic) throws WxErrorException {
285+
Map<String, Object> map = new HashMap<>(2);
286+
map.put(ROOM_ID, roomId);
287+
map.put("isFeedsPublic", isFeedsPublic);
288+
String responseContent = this.wxMaService.post(Room.UPDATE_FEED_PUBLIC, WxMaGsonBuilder.create().toJson(map));
289+
JsonObject jsonObject = GsonParser.parse(responseContent);
290+
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
291+
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
292+
}
293+
return true;
294+
}
295+
296+
@Override
297+
public boolean updatereplay(Integer roomId, Integer closeReplay) throws WxErrorException {
298+
Map<String, Object> map = new HashMap<>(2);
299+
map.put(ROOM_ID, roomId);
300+
map.put("closeReplay", closeReplay);
301+
String responseContent = this.wxMaService.post(Room.UPDATE_REPLAY, WxMaGsonBuilder.create().toJson(map));
302+
JsonObject jsonObject = GsonParser.parse(responseContent);
303+
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
304+
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
305+
}
306+
return true;
307+
}
308+
309+
@Override
310+
public boolean updatekf(Integer roomId, Integer closeKf) throws WxErrorException {
311+
Map<String, Object> map = new HashMap<>(2);
312+
map.put(ROOM_ID, roomId);
313+
map.put("closeKf", closeKf);
314+
String responseContent = this.wxMaService.post(Room.UPDATE_KF, WxMaGsonBuilder.create().toJson(map));
315+
JsonObject jsonObject = GsonParser.parse(responseContent);
316+
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
317+
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
318+
}
319+
return true;
320+
}
321+
322+
@Override
323+
public boolean updatecomment(Integer roomId, Integer banComment) throws WxErrorException {
324+
Map<String, Object> map = new HashMap<>(2);
325+
map.put(ROOM_ID, roomId);
326+
map.put("banComment", banComment);
327+
String responseContent = this.wxMaService.post(Room.UPDATE_COMMENT, WxMaGsonBuilder.create().toJson(map));
328+
JsonObject jsonObject = GsonParser.parse(responseContent);
329+
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
330+
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
331+
}
332+
return true;
333+
}
334+
335+
@Override
336+
public boolean onsale(Integer roomId, Integer goodsId, Integer onSale) throws WxErrorException {
337+
Map<String, Object> map = new HashMap<>(3);
338+
map.put(ROOM_ID, roomId);
339+
map.put("goodsId", goodsId);
340+
map.put("onSale", onSale);
341+
String responseContent = this.wxMaService.post(Room.ONSALE, WxMaGsonBuilder.create().toJson(map));
342+
JsonObject jsonObject = GsonParser.parse(responseContent);
343+
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
344+
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
345+
}
346+
return true;
347+
}
348+
349+
@Override
350+
public boolean deleteInRoom(Integer roomId, Integer goodsId) throws WxErrorException {
351+
Map<String, Object> map = new HashMap<>(2);
352+
map.put(ROOM_ID, roomId);
353+
map.put("goodsId", goodsId);
354+
String responseContent = this.wxMaService.post(Room.DELETE_IN_ROOM, WxMaGsonBuilder.create().toJson(map));
355+
JsonObject jsonObject = GsonParser.parse(responseContent);
356+
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
357+
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
358+
}
359+
return true;
360+
}
361+
362+
@Override
363+
public boolean push(Integer roomId, Integer goodsId) throws WxErrorException {
364+
Map<String, Object> map = new HashMap<>(2);
365+
map.put(ROOM_ID, roomId);
366+
map.put("goodsId", goodsId);
367+
String responseContent = this.wxMaService.post(Room.PUSH, WxMaGsonBuilder.create().toJson(map));
368+
JsonObject jsonObject = GsonParser.parse(responseContent);
369+
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
370+
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
371+
}
372+
return true;
373+
}
374+
375+
@Override
376+
public boolean sort(Integer roomId, List<Map<String,String>> goods) throws WxErrorException {
377+
Map<String, Object> map = new HashMap<>(2);
378+
map.put(ROOM_ID, roomId);
379+
map.put("goods", goods);
380+
String responseContent = this.wxMaService.post(Room.SORT, WxMaGsonBuilder.create().toJson(map));
381+
JsonObject jsonObject = GsonParser.parse(responseContent);
382+
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
383+
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
384+
}
385+
return true;
386+
}
387+
388+
@Override
389+
public String getVideo(Integer roomId, Integer goodsId) throws WxErrorException {
390+
Map<String, Object> map = new HashMap<>(2);
391+
map.put(ROOM_ID, roomId);
392+
map.put("goodsId", goodsId);
393+
String responseContent = this.wxMaService.get(Room.GET_VIDEO, WxMaGsonBuilder.create().toJson(map));
394+
JsonObject jsonObject = GsonParser.parse(responseContent);
395+
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
396+
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
397+
}
398+
return jsonObject.get("url").getAsString();
399+
}
400+
234401
}

0 commit comments

Comments
 (0)