diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java index f10a4dd12..9b465fd0c 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java @@ -70,7 +70,7 @@ public final class WxCpApiPathConsts { @Deprecated public static final String GET_APPROVAL_DATA = "/cgi-bin/corp/getapprovaldata"; public static final String GET_TEMPLATE_DETAIL = "/cgi-bin/oa/gettemplatedetail"; - public static final String APPLY_EVENT="/cgi-bin/oa/applyevent"; + public static final String APPLY_EVENT = "/cgi-bin/oa/applyevent"; } public static class Tag { diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaLiveService.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaLiveService.java index 01883481c..185085478 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaLiveService.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaLiveService.java @@ -46,35 +46,35 @@ public interface WxMaLiveService { /** * 获取所有直播间信息(没有分页直接获取全部) * - * @return - * @throws WxErrorException + * @return . + * @throws WxErrorException . */ - List getLiveinfos() throws WxErrorException; + List getLiveInfos() throws WxErrorException; /** * 获取直播房间回放数据信息. * - * @param action 获取回放 - * @param room_id 直播间 id - * @param start 起始拉取视频,start = 0 表示从第 1 个视频片段开始拉取 - * @param limit 每次拉取的个数上限,不要设置过大,建议 100 以内 - * @return - * @throws WxErrorException + * @param action 获取回放 + * @param roomId 直播间 id + * @param start 起始拉取视频,start = 0 表示从第 1 个视频片段开始拉取 + * @param limit 每次拉取的个数上限,不要设置过大,建议 100 以内 + * @return . + * @throws WxErrorException . */ - WxMaLiveResult getLiveReplay(String action, Integer room_id, Integer start, Integer limit) throws WxErrorException; + WxMaLiveResult getLiveReplay(String action, Integer roomId, Integer start, Integer limit) throws WxErrorException; /** * 获取直播房间回放数据信息. *

* 获取回放 (默认:get_replay) * - * @param room_id 直播间 id - * @param start 起始拉取视频,start = 0 表示从第 1 个视频片段开始拉取 - * @param limit 每次拉取的个数上限,不要设置过大,建议 100 以内 - * @return - * @throws WxErrorException + * @param roomId 直播间 id + * @param start 起始拉取视频,start = 0 表示从第 1 个视频片段开始拉取 + * @param limit 每次拉取的个数上限,不要设置过大,建议 100 以内 + * @return . + * @throws WxErrorException . */ - WxMaLiveResult getLiveReplay(Integer room_id, Integer start, Integer limit) throws WxErrorException; + WxMaLiveResult getLiveReplay(Integer roomId, Integer start, Integer limit) throws WxErrorException; /** * 直播间导入商品 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 41c7d6087..4e8857769 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 @@ -8,6 +8,7 @@ import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; import me.chanjar.weixin.common.WxType; import me.chanjar.weixin.common.error.WxError; import me.chanjar.weixin.common.error.WxErrorException; @@ -24,10 +25,11 @@ import java.util.Map; * * @author yjwang */ +@Slf4j @AllArgsConstructor public class WxMaLiveServiceImpl implements WxMaLiveService { private static final JsonParser JSON_PARSER = new JsonParser(); - private WxMaService wxMaService; + private final WxMaService wxMaService; @Override public Integer createRoom(WxMaLiveInfo.RoomInfo roomInfo) throws WxErrorException { @@ -41,19 +43,19 @@ public class WxMaLiveServiceImpl implements WxMaLiveService { @Override public WxMaLiveResult getLiveInfo(Integer start, Integer limit) throws WxErrorException { - JsonObject jsonObject = getJsonObject(start, limit, null); + JsonObject jsonObject = getLiveInfo(start, limit, null); return WxMaLiveResult.fromJson(jsonObject.toString()); } @Override - public List getLiveinfos() throws WxErrorException { + public List getLiveInfos() throws WxErrorException { List results = new ArrayList<>(); - Integer start = 0; + int start = 0; Integer limit = 80; - Integer tatal = 0; - WxMaLiveResult liveInfo = null; + Integer total = 0; + WxMaLiveResult liveInfo; do { - if (tatal != 0 && tatal <= start) { + if (total != 0 && total <= start) { break; } liveInfo = getLiveInfo(start, limit); @@ -61,29 +63,30 @@ public class WxMaLiveServiceImpl implements WxMaLiveService { return null; } results.addAll(liveInfo.getRoomInfos()); - tatal = liveInfo.getTotal(); + total = liveInfo.getTotal(); start = results.size(); try { Thread.sleep(100); } catch (InterruptedException e) { - e.printStackTrace(); + log.error("InterruptedException", e); } - } while (results.size() <= tatal); + } while (results.size() <= total); + return results; } @Override - public WxMaLiveResult getLiveReplay(String action, Integer room_id, Integer start, Integer limit) throws WxErrorException { - Map map = new HashMap(4); + public WxMaLiveResult getLiveReplay(String action, Integer roomId, Integer start, Integer limit) throws WxErrorException { + Map map = new HashMap<>(4); map.put("action", action); - map.put("room_id", room_id); - JsonObject jsonObject = getJsonObject(start, limit, map); + map.put("room_id", roomId); + JsonObject jsonObject = getLiveInfo(start, limit, map); return WxMaLiveResult.fromJson(jsonObject.toString()); } @Override - public WxMaLiveResult getLiveReplay(Integer room_id, Integer start, Integer limit) throws WxErrorException { - return getLiveReplay("get_replay", room_id, start, limit); + public WxMaLiveResult getLiveReplay(Integer roomId, Integer start, Integer limit) throws WxErrorException { + return getLiveReplay("get_replay", roomId, start, limit); } @Override @@ -99,18 +102,9 @@ public class WxMaLiveServiceImpl implements WxMaLiveService { return true; } - /** - * 包装一下 - * - * @param start - * @param limit - * @param map - * @return - * @throws WxErrorException - */ - private JsonObject getJsonObject(Integer start, Integer limit, Map map) throws WxErrorException { + private JsonObject getLiveInfo(Integer start, Integer limit, Map map) throws WxErrorException { if (map == null) { - map = new HashMap(2); + map = new HashMap<>(2); } map.put("start", start); map.put("limit", limit); diff --git a/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaLiveServiceImplTest.java b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaLiveServiceImplTest.java index b6e5c9be6..39d107a34 100644 --- a/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaLiveServiceImplTest.java +++ b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaLiveServiceImplTest.java @@ -70,7 +70,7 @@ public class WxMaLiveServiceImplTest { @Test public void getLiveinfos() throws Exception { - List list = this.wxService.getLiveService().getLiveinfos(); + List list = this.wxService.getLiveService().getLiveInfos(); assertNotNull(list); System.out.println(list.toString()); }