|
|
@@ -1,8 +1,12 @@
|
|
|
package com.cnd3b.utility.polyv;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.cnd3b.common.data.Rows;
|
|
|
+import com.cnd3b.common.data.db.DBConnect;
|
|
|
import junit.framework.Assert;
|
|
|
+import net.polyv.common.v1.base.HttpUtil;
|
|
|
import net.polyv.common.v1.exception.PloyvSdkException;
|
|
|
import net.polyv.live.v1.config.LiveGlobalConfig;
|
|
|
import net.polyv.live.v1.constant.LiveConstant;
|
|
|
@@ -17,12 +21,11 @@ import net.polyv.live.v1.service.account.impl.LiveAccountServiceImpl;
|
|
|
import net.polyv.live.v1.service.channel.impl.LiveChannelOperateServiceImpl;
|
|
|
import net.polyv.live.v1.service.web.impl.LiveWebAuthServiceImpl;
|
|
|
import net.polyv.live.v1.util.LiveSignUtil;
|
|
|
+import p2.common.parse.J;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Calendar;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
|
|
|
public class Polyv {
|
|
|
String appid = "g3mt33nllk";
|
|
|
@@ -36,11 +39,6 @@ public class Polyv {
|
|
|
LiveGlobalConfig.init(appid, userid, appSecret);
|
|
|
}
|
|
|
|
|
|
- public static void main(String[] args) {
|
|
|
-// Polyv polyv = new Polyv();
|
|
|
-// polyv.listCategory();
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 生成授权播放地址
|
|
|
*
|
|
|
@@ -84,16 +82,8 @@ public class Polyv {
|
|
|
liveChannelResponse = new LiveChannelOperateServiceImpl().createChannel(liveChannelRequest);
|
|
|
Assert.assertNotNull(liveChannelResponse);
|
|
|
if (liveChannelResponse != null) {
|
|
|
- System.out.println(JSON.toJSONString(liveChannelResponse));
|
|
|
- //to do something ......
|
|
|
- // log.debug("频道创建成功{}", JSON.toJSONString(liveChannelResponse));
|
|
|
- //log.debug("网页开播地址:https://live.polyv.net/web-start/login?channelId={} , 登录密码: {}",
|
|
|
liveChannelResponse.getChannelId();
|
|
|
liveChannelRequest.getChannelPasswd();
|
|
|
- //log.debug("网页观看地址:https://live.polyv.cn/watch/{} ", liveChannelResponse.getChannelId());
|
|
|
- System.out.println("网页开播地址:https://live.polyv.net/web-start/login?channelId=" + liveChannelResponse.getChannelId());
|
|
|
- System.out.println("网页开播登陆密码:" + liveChannelRequest.getChannelPasswd());
|
|
|
- System.out.println("网页观看地址:https://live.polyv.cn/watch/" + liveChannelResponse.getChannelId());
|
|
|
}
|
|
|
return liveChannelResponse;
|
|
|
} catch (PloyvSdkException e) {
|
|
|
@@ -108,6 +98,59 @@ public class Polyv {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 修改频道分类及名称
|
|
|
+ *
|
|
|
+ * @throws Exception
|
|
|
+ * @throws NoSuchAlgorithmException
|
|
|
+ */
|
|
|
+ public boolean updateChannelSetting(String channelId, String channelName, int categoryId) {
|
|
|
+ LiveChannelSettingRequest liveChannelSettingRequest = new LiveChannelSettingRequest();
|
|
|
+ Boolean liveChannelSettingResponse;
|
|
|
+ try {
|
|
|
+ LiveChannelSettingRequest.BasicSetting basicSetting = new LiveChannelSettingRequest.BasicSetting();
|
|
|
+ basicSetting.setName(channelName);//频道名称
|
|
|
+ basicSetting.setCategoryId(categoryId);//修改频道分类
|
|
|
+ liveChannelSettingRequest.setChannelId(channelId)
|
|
|
+ .setBasicSetting(basicSetting);
|
|
|
+ liveChannelSettingResponse = new LiveChannelOperateServiceImpl().updateChannelSetting(
|
|
|
+ liveChannelSettingRequest);
|
|
|
+ Assert.assertTrue(liveChannelSettingResponse);
|
|
|
+ return liveChannelSettingResponse;
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 关闭频道外部授权
|
|
|
+ *
|
|
|
+ * @throws Exception
|
|
|
+ * @throws NoSuchAlgorithmException
|
|
|
+ */
|
|
|
+ public boolean closeChannelAuthExternal(String channelId) {
|
|
|
+ LiveChannelSettingRequest liveChannelSettingRequest = new LiveChannelSettingRequest();
|
|
|
+ Boolean liveChannelSettingResponse;
|
|
|
+ try {
|
|
|
+ LiveChannelSettingRequest.AuthSetting authSetting = new LiveChannelSettingRequest.AuthSetting()
|
|
|
+ .setRank(1)
|
|
|
+ .setEnabled("N");
|
|
|
+ List<LiveChannelSettingRequest.AuthSetting> authSettings =
|
|
|
+ new ArrayList<LiveChannelSettingRequest.AuthSetting>();
|
|
|
+ authSettings.add(authSetting);
|
|
|
+ liveChannelSettingRequest.setChannelId(channelId)
|
|
|
+ .setAuthSettings(authSettings);
|
|
|
+ liveChannelSettingResponse = new LiveChannelOperateServiceImpl().updateChannelSetting(
|
|
|
+ liveChannelSettingRequest);
|
|
|
+ Assert.assertTrue(liveChannelSettingResponse);
|
|
|
+ return liveChannelSettingResponse;
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 设置频道外部授权
|
|
|
*
|
|
|
@@ -159,60 +202,303 @@ public class Polyv {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 频道封面map
|
|
|
+ */
|
|
|
+ public static HashMap<String, String> splashimageMap = new HashMap<>();
|
|
|
+ public static HashMap<String, Long> splashimagetimeMap = new HashMap<>();
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取频道图片,频率5分钟一次
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String getChannelImage(String channelId, String livestatus) {
|
|
|
+ if (!splashimageMap.containsKey(channelId) || !splashimagetimeMap.containsKey(channelId) || splashimagetimeMap.get(channelId) <= Calendar.getInstance().getTimeInMillis()) {
|
|
|
+ splashimageMap.put(channelId, getChannelCapture(channelId, livestatus));
|
|
|
+ splashimagetimeMap.put(channelId, Calendar.getInstance().getTimeInMillis() + 1000 * 60 * 5);
|
|
|
+ }
|
|
|
+ return splashimageMap.get(channelId);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询频道显示图片,如果频道正在直播就显示直播截图,如果不再直播就显示封面图
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String getChannelCapture(String channelId, String livestatus) {
|
|
|
+ if ("live".equals(livestatus)) {
|
|
|
+ LiveChannelCaptureRequest liveChannelCaptureRequest = new LiveChannelCaptureRequest();
|
|
|
+ String liveChannelCaptureResponse;
|
|
|
+ try {
|
|
|
+ liveChannelCaptureRequest.setChannelId(channelId);
|
|
|
+ liveChannelCaptureResponse = new LiveChannelOperateServiceImpl().getChannelCapture(
|
|
|
+ liveChannelCaptureRequest);
|
|
|
+ Assert.assertNotNull(liveChannelCaptureResponse);
|
|
|
+ return "https:" + liveChannelCaptureResponse;
|
|
|
+ } catch (PloyvSdkException | IOException | NoSuchAlgorithmException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return getChannelSplash(channelId, livestatus);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询频道封面图(引导图)
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String getChannelSplash(String channelId, String livestatus) {
|
|
|
+ if ("waiting".equalsIgnoreCase(livestatus) || "end".equalsIgnoreCase(livestatus) || "playback".equalsIgnoreCase(livestatus)) {
|
|
|
+ //业务参数
|
|
|
+ String url = String.format("http://api.polyv.net/live/v2/channelSetting/%s/getSplash", channelId);
|
|
|
+ try {
|
|
|
+ Map<String, String> requestMap = new HashMap<>();
|
|
|
+ requestMap.put("appId", appid);
|
|
|
+ requestMap.put("timestamp", String.valueOf(System.currentTimeMillis()));
|
|
|
+ requestMap.put("sign", LiveSignUtil.getSign(requestMap, appSecret));
|
|
|
+ String response = HttpUtil.postFormBody(url, requestMap, null);
|
|
|
+ JSONObject object = JSONObject.parseObject(response);
|
|
|
+ if (object.containsKey("data") && object.getJSONObject("data").containsKey("splashImg") && object.getJSONObject("data").getString("splashImg") != null) {
|
|
|
+ return "https:" + object.getJSONObject("data").getString("splashImg");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return "https://help.polyv.net/skin/imgs/logo.svg";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 直播间状态map
|
|
|
+ */
|
|
|
+ public static HashMap<String, String> livestatusMap = new HashMap<>();
|
|
|
+ public static HashMap<String, Long> livestatustimeMap = new HashMap<>();
|
|
|
|
|
|
- public JSONObject testGetChannelInfo() throws Exception, NoSuchAlgorithmException {
|
|
|
- LiveChannelInfoRequest liveChannelInfoRequest = new LiveChannelInfoRequest();
|
|
|
- LiveChannelInfoResponse liveChannelInfoResponse;
|
|
|
+ /**
|
|
|
+ * 获取直播间状态,频率60秒一次
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String getLiveStatus(String channelId) {
|
|
|
+ if (!livestatusMap.containsKey(channelId) || !livestatustimeMap.containsKey(channelId) || livestatustimeMap.get(channelId) <= Calendar.getInstance().getTimeInMillis()) {
|
|
|
+ getLiveStatuses(new String[]{channelId});
|
|
|
+ }
|
|
|
+ return livestatusMap.getOrDefault(channelId, "unStart");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量获取直播间状态
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public HashMap<String, String> getLiveStatuses(String[] channelIdArray) {
|
|
|
+ String channelIds = "";
|
|
|
+ for (String channelId : channelIdArray) {
|
|
|
+ if ("".equals(channelIds)) {
|
|
|
+ channelIds = channelId;
|
|
|
+ } else {
|
|
|
+ channelIds = channelIds + "," + channelId;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //业务参数
|
|
|
+ String url = "http://api.polyv.net/live/v4/channel/live-status/list";
|
|
|
try {
|
|
|
- //准备测试数据
|
|
|
- String channelId = "2636984";
|
|
|
- liveChannelInfoRequest.setChannelId(channelId);
|
|
|
- liveChannelInfoResponse = new LiveChannelOperateServiceImpl().getChannelInfo(liveChannelInfoRequest);
|
|
|
- Assert.assertNotNull(liveChannelInfoResponse);
|
|
|
- return (JSONObject) JSON.toJSON(liveChannelInfoResponse);
|
|
|
- } catch (PloyvSdkException | IOException | NoSuchAlgorithmException e) {
|
|
|
+ //http 调用逻辑
|
|
|
+ Map<String, String> requestMap = new HashMap<>();
|
|
|
+ requestMap.put("appId", appid);
|
|
|
+ requestMap.put("timestamp", String.valueOf(System.currentTimeMillis()));
|
|
|
+ requestMap.put("channelIds", channelIds);
|
|
|
+ requestMap.put("sign", LiveSignUtil.getSign(requestMap, appSecret));
|
|
|
+ String response = HttpUtil.get(url, requestMap, null);
|
|
|
+ JSONObject object = JSONObject.parseObject(response);
|
|
|
+ if (object.getBooleanValue("success")) {
|
|
|
+ JSONArray dataArray = object.getJSONArray("data");
|
|
|
+ for (Object o : dataArray) {
|
|
|
+ JSONObject statusObject = (JSONObject) o;
|
|
|
+ livestatusMap.put(statusObject.getString("channelId"), statusObject.getString("liveStatus"));
|
|
|
+ livestatustimeMap.put(statusObject.getString("channelId"), Calendar.getInstance().getTimeInMillis() + 1000 * 60);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
- return new JSONObject();
|
|
|
+ return livestatusMap;
|
|
|
}
|
|
|
|
|
|
- public JSONObject testGetChannelBasicInfo() throws Exception, NoSuchAlgorithmException {
|
|
|
- LiveChannelBasicInfoRequest liveChannelBasicInfoRequest = new LiveChannelBasicInfoRequest();
|
|
|
- LiveChannelBasicInfoResponse liveChannelBasicInfoResponse;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 当前开播商户列表
|
|
|
+ */
|
|
|
+ public ArrayList<String> getLiveChannelList() {
|
|
|
+ DBConnect dbConnect = new DBConnect();
|
|
|
+ Rows rows = dbConnect.runSqlQuery("select channelid from tlive");
|
|
|
+ /**
|
|
|
+ * 获取所有直播间的开播状态
|
|
|
+ */
|
|
|
+ getLiveStatuses(rows.toArray("channelid"));
|
|
|
+ /**
|
|
|
+ * 将处于开播状态的频道存入缓存
|
|
|
+ */
|
|
|
+ ArrayList<String> livechannellist = new ArrayList<>();
|
|
|
+ for (String channelid : livestatusMap.keySet()) {
|
|
|
+ if ("live".equalsIgnoreCase(livestatusMap.get(channelid))) {
|
|
|
+ livechannellist.add(channelid);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return livechannellist;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取频道实时观众数
|
|
|
+ *
|
|
|
+ * @throws IOException
|
|
|
+ * @throws NoSuchAlgorithmException
|
|
|
+ */
|
|
|
+ public JSONObject getRealtimeViewers(String channelId) {
|
|
|
+ //业务参数
|
|
|
+ String url = "https://api.polyv.net/live/v2/statistics/get-realtime-viewers";
|
|
|
try {
|
|
|
- //准备测试数据
|
|
|
- String channelId = "2636984";
|
|
|
- liveChannelBasicInfoRequest.setChannelId(channelId);
|
|
|
- liveChannelBasicInfoResponse = new LiveChannelOperateServiceImpl().getChannelBasicInfo(
|
|
|
- liveChannelBasicInfoRequest);
|
|
|
- Assert.assertNotNull(liveChannelBasicInfoResponse);
|
|
|
- return (JSONObject) JSON.toJSON(liveChannelBasicInfoResponse);
|
|
|
- } catch (PloyvSdkException | IOException | NoSuchAlgorithmException e) {
|
|
|
+ //http 调用逻辑
|
|
|
+ Map<String, String> requestMap = new HashMap<>();
|
|
|
+ requestMap.put("appId", appid);
|
|
|
+ requestMap.put("timestamp", String.valueOf(System.currentTimeMillis()));
|
|
|
+ requestMap.put("userId", userid);
|
|
|
+ requestMap.put("channelIds", channelId);
|
|
|
+ requestMap.put("sign", LiveSignUtil.getSign(requestMap, appSecret));
|
|
|
+ String response = HttpUtil.get(url, requestMap, null);
|
|
|
+ JSONObject object = JSONObject.parseObject(response);
|
|
|
+ if ("success".equalsIgnoreCase(object.getString("status"))) {
|
|
|
+ JSONArray dataArray = object.getJSONArray("data");
|
|
|
+ for (Object o : dataArray) {
|
|
|
+ return (JSONObject) o;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
- return new JSONObject();
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
- * 查询频道直播截图
|
|
|
+ * 获取频道观众信息列表
|
|
|
*
|
|
|
- * @return
|
|
|
+ * @throws IOException
|
|
|
+ * @throws NoSuchAlgorithmException
|
|
|
*/
|
|
|
- public String getChannelCapture() {
|
|
|
- LiveChannelCaptureRequest liveChannelCaptureRequest = new LiveChannelCaptureRequest();
|
|
|
- String liveChannelCaptureResponse;
|
|
|
+ public JSONObject getPageViewlog(String channelId, String currentDay, String pageSize, String page) {
|
|
|
+ //业务参数
|
|
|
+ String url = String.format("http://api.polyv.net/live/v2/statistics/%s/viewlog", channelId);
|
|
|
try {
|
|
|
- //准备测试数据
|
|
|
- String channelId = "2636984";
|
|
|
- liveChannelCaptureRequest.setChannelId(channelId);
|
|
|
- liveChannelCaptureResponse = new LiveChannelOperateServiceImpl().getChannelCapture(
|
|
|
- liveChannelCaptureRequest);
|
|
|
- Assert.assertNotNull(liveChannelCaptureResponse);
|
|
|
- return JSON.toJSONString(liveChannelCaptureResponse);
|
|
|
- } catch (PloyvSdkException | IOException | NoSuchAlgorithmException e) {
|
|
|
+// String currentDay = "2021-1-20";
|
|
|
+// String page = "1";
|
|
|
+// String startTime = "1611072000000";
|
|
|
+// String endTime = "1611158400000";
|
|
|
+// String param1 = "1b448be323";
|
|
|
+// String param2 = "管理员";
|
|
|
+// String param3 = "live";
|
|
|
+ //http 调用逻辑
|
|
|
+ Map<String, String> requestMap = new HashMap<>();
|
|
|
+ requestMap.put("appId", appid);
|
|
|
+ requestMap.put("timestamp", String.valueOf(System.currentTimeMillis()));
|
|
|
+ requestMap.put("currentDay", currentDay);
|
|
|
+ requestMap.put("page", page);
|
|
|
+ requestMap.put("pageSize", pageSize);
|
|
|
+// requestMap.put("startTime", startTime);
|
|
|
+// requestMap.put("endTime", endTime);
|
|
|
+// requestMap.put("param1", param1);
|
|
|
+// requestMap.put("param2", param2);
|
|
|
+// requestMap.put("param3", param3);
|
|
|
+ requestMap.put("sign", LiveSignUtil.getSign(requestMap, appSecret));
|
|
|
+ String response = HttpUtil.get(url, requestMap, null);
|
|
|
+ JSONObject object = JSONObject.parseObject(response);
|
|
|
+ if ("success".equalsIgnoreCase(object.getString("status"))) {
|
|
|
+ return object.getJSONObject("data");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
- return "";
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取频道观众聊天记录列表
|
|
|
+ *
|
|
|
+ * @throws IOException
|
|
|
+ * @throws NoSuchAlgorithmException
|
|
|
+ */
|
|
|
+ public JSONObject getPageMessageList(String channelId, String currentDay, String pageSize, String page) {
|
|
|
+ //业务参数
|
|
|
+ String url = "http://api.polyv.net/live/v3/channel/chat/get-history-page";
|
|
|
+ try {
|
|
|
+ String userType = "";//用户类型,可以选择多个类型,用英文逗号隔开 slice:云课堂学员 teacher:讲师 guest:嘉宾 manager:管理员 assistant:助教 viewer:特邀观众 monitor:场监 attendee:研讨会参与者 student:普通直播观众
|
|
|
+ String status = "";//聊天记录审核状态,默认pass:已审核 pass:已审核 censor:审核中和删除
|
|
|
+ String source = "";//类型,不填默认公聊 extend:管理员私聊
|
|
|
+ String roomId = "";//如果有房间号,需要传入房间号,默认不传
|
|
|
+
|
|
|
+ //http 调用逻辑
|
|
|
+ Map<String, String> requestMap = new HashMap<>();
|
|
|
+ requestMap.put("appId", appid);
|
|
|
+ requestMap.put("timestamp", String.valueOf(System.currentTimeMillis()));
|
|
|
+ requestMap.put("startDay", currentDay);
|
|
|
+ requestMap.put("endDay", currentDay);
|
|
|
+ requestMap.put("channelId", channelId);
|
|
|
+ requestMap.put("page", page);
|
|
|
+ requestMap.put("pageSize", pageSize);
|
|
|
+ requestMap.put("userType", userType);
|
|
|
+ requestMap.put("status", status);
|
|
|
+ requestMap.put("source", source);
|
|
|
+ requestMap.put("roomId", roomId);
|
|
|
+ requestMap.put("sign", LiveSignUtil.getSign(requestMap, appSecret));
|
|
|
+ String response = HttpUtil.get(url, requestMap, null);
|
|
|
+ JSONObject object = JSONObject.parseObject(response);
|
|
|
+ if ("success".equalsIgnoreCase(object.getString("status"))) {
|
|
|
+ return object.getJSONObject("data");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取查询多个频道概览统计数据
|
|
|
+ *
|
|
|
+ * @throws IOException
|
|
|
+ * @throws NoSuchAlgorithmException
|
|
|
+ */
|
|
|
+ public JSONArray getChannelSummary(String[] channelIdArray, String currentDay) {
|
|
|
+ String channelIds = "";
|
|
|
+ for (String channelId : channelIdArray) {
|
|
|
+ if ("".equals(channelIds)) {
|
|
|
+ channelIds = channelId;
|
|
|
+ } else {
|
|
|
+ channelIds = channelIds + "," + channelId;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ //业务参数
|
|
|
+ String url = String.format("http://api.polyv.net/live/v2/statistics/%s/channel_summary", userid);
|
|
|
+ //http 调用逻辑
|
|
|
+ Map<String, String> requestMap = new HashMap<>();
|
|
|
+ requestMap.put("appId", appid);
|
|
|
+ requestMap.put("timestamp", String.valueOf(System.currentTimeMillis()));
|
|
|
+ requestMap.put("startDate", currentDay);
|
|
|
+ requestMap.put("endDate", currentDay);
|
|
|
+ requestMap.put("channelIds", channelIds);
|
|
|
+ requestMap.put("sign", LiveSignUtil.getSign(requestMap, appSecret));
|
|
|
+ String response = HttpUtil.postFormBody(url, requestMap, null);
|
|
|
+ JSONObject object = JSONObject.parseObject(response);
|
|
|
+ if ("success".equalsIgnoreCase(object.getString("status"))) {
|
|
|
+ return object.getJSONArray("data");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -234,21 +520,35 @@ public class Polyv {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
- * 获取直播分类列表
|
|
|
+ * 直播间状态map
|
|
|
+ */
|
|
|
+ public static HashMap<Integer, String> categoryMap = new HashMap<>();
|
|
|
+ public static long categorytime = 0L;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取直播分类列表频率30分钟一次
|
|
|
*
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
- public List<LiveListCategoryResponse.LiveCategory> listCategory() {
|
|
|
- LiveListCategoryRequest liveListCategoryRequest = new LiveListCategoryRequest();
|
|
|
- LiveListCategoryResponse liveListCategoryResponse;
|
|
|
- try {
|
|
|
- liveListCategoryResponse = new LiveAccountServiceImpl().listCategory(liveListCategoryRequest);
|
|
|
- Assert.assertNotNull(liveListCategoryResponse);
|
|
|
- return liveListCategoryResponse.getLiveCategories();
|
|
|
- } catch (PloyvSdkException | IOException | NoSuchAlgorithmException e) {
|
|
|
- e.printStackTrace();
|
|
|
+ public HashMap<Integer, String> listCategory() {
|
|
|
+ if (categoryMap.isEmpty() || categorytime <= Calendar.getInstance().getTimeInMillis()) {
|
|
|
+ LiveListCategoryRequest liveListCategoryRequest = new LiveListCategoryRequest();
|
|
|
+ LiveListCategoryResponse liveListCategoryResponse;
|
|
|
+ try {
|
|
|
+ liveListCategoryResponse = new LiveAccountServiceImpl().listCategory(liveListCategoryRequest);
|
|
|
+ Assert.assertNotNull(liveListCategoryResponse);
|
|
|
+ List<LiveListCategoryResponse.LiveCategory> categoryList = liveListCategoryResponse.getLiveCategories();
|
|
|
+ for (LiveListCategoryResponse.LiveCategory liveCategory : categoryList) {
|
|
|
+ categoryMap.put(liveCategory.getCategoryId(), liveCategory.getCategoryName());
|
|
|
+ }
|
|
|
+ categorytime = Calendar.getInstance().getTimeInMillis() + 1000 * 60 * 30;
|
|
|
+ } catch (PloyvSdkException | IOException | NoSuchAlgorithmException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
}
|
|
|
- return new ArrayList<>();
|
|
|
+ return categoryMap;
|
|
|
}
|
|
|
+
|
|
|
}
|