获取直播间列表接口
https://api.weixin.qq.com/wxa/business/getliveinfo?access_token=
为什么有时候获取不到直播间列表
List liveStatusDTOS = null;
try {
//获取access_token
JSONObject accessToken = getAccessToken();
String access_token = (String) accessToken.get("access_token");
String httpurl = "https://api.weixin.qq.com/wxa/business/getliveinfo?access_token=" + access_token;
liveStatusDTOS = null;
//参数封装
Map mapParam = new HashMap<>();
mapParam.put("start", 0);
mapParam.put("limit", 500);
JSONObject jsonData = restTemplate.postForObject(httpurl, mapParam, JSONObject.class);
if (null != jsonData) {
ArrayList statusDTOS = (ArrayList) jsonData.get("room_info");
if (CollectionUtils.isNotEmpty(statusDTOS)) {
String jsonString = JSONObject.toJSONString(statusDTOS);
liveStatusDTOS = JSONArray.parseArray(jsonString, LiveStatusDTO.class);
}
}
} catch (RestClientException e) {
logger.info(String.format("获取微信小程序直播列表异常,e = %s", e));
}
return liveStatusDTOS;
}
可以了,access_token被别人搞无效了