Преглед изворни кода

保利威直播内容更新

沈静伟 пре 4 година
родитељ
комит
5942649993

+ 0 - 3
src/dsb/com/cnd3b/common/restful/WebClientRest.java

@@ -542,9 +542,6 @@ public class WebClientRest {
     @GET
     @Path("polyvAuth")
     public String polyvAuth(@QueryParam("channelId") String channelId, @QueryParam("userid") String userid, @QueryParam("ts") Long ts, @QueryParam("token") String token) {
-
-        System.err.println(channelId);
-        System.err.println(userid);
         JSONObject result = new JSONObject();
         long timeMillis = System.currentTimeMillis();
         long diffTime = Math.abs(timeMillis - ts);

+ 3 - 0
src/dsb/com/cnd3b/restcontroller/customer/live/SQL/直播列表查询.sql

@@ -0,0 +1,3 @@
+select t1.tliveid, t1.createby, t1.createdate, t1.tagentsid,t2.fagentname, t1.categoryid,t1.categoryname,t1.channelid, t1.channelname,t1.livestatus,t1.channelcoverimageurl from tlive t1
+inner join tagents t2 on t1.siteid=t2.siteid and t1.tagentsid=t2.tagentsid
+where t1.siteid=$siteid$ and t1.tagentsid=$tagentsid$ and $where$

+ 5 - 0
src/dsb/com/cnd3b/restcontroller/customer/live/SQL/直播详情查询.sql

@@ -0,0 +1,5 @@
+select t1.tliveid, t1.siteid, t1.createby, t1.changeby, t1.createdate, t1.changedate,
+       t1.tactivityid, t1.tliveapplyid, t1.tagentsid, t1.fliveurl_web,t1.fliveurl_client, t1.fliveshowurl,
+       t1.categoryid,t1.categoryname, t1.channelname, t1.channelpasswd, t1.channelid,t1.fassistanturl,t1.fisneedauth,t1.secretkey,t1.livestatus,t1.channelcoverimageurl from tlive t1
+inner join tagents t2 on t1.siteid=t2.siteid and t1.tagentsid=t2.tagentsid
+where t1.siteid=$siteid$ and t1.tliveid=$tliveid$

+ 82 - 0
src/dsb/com/cnd3b/restcontroller/customer/live/live.java

@@ -0,0 +1,82 @@
+package com.cnd3b.restcontroller.customer.live;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.cnd3b.common.Controller;
+import com.cnd3b.common.data.Rows;
+import com.cnd3b.common.data.SQLFactory;
+import com.cnd3b.common.data.db.DataPool;
+import com.cnd3b.utility.polyv.Polyv;
+
+import java.util.HashMap;
+
+public class live extends Controller {
+    public live(JSONObject content) {
+        super(content);
+    }
+
+    /**
+     * 获取频道分类列表
+     *
+     * @return
+     */
+    public String getLiveCategory() {
+        Polyv polyv = new Polyv();
+        HashMap<Integer, String> map = polyv.listCategory();
+        JSONArray array = new JSONArray();
+        for (int id : map.keySet()) {
+            JSONObject object = new JSONObject();
+            object.put("categoryId", id);
+            object.put("categoryName", map.get(id));
+            array.add(object);
+        }
+        return getSucReturnObject().setData(array).toString();
+    }
+
+    /**
+     * 直播列表查询
+     *
+     * @return
+     */
+    public String queryChannelList() {
+        /**
+         *排序条件设置
+         */
+        String[] sortfield = {"t1.createdate desc"};
+        String sort = getSort(sortfield, "t1.createdate desc");
+        /**
+         * 过滤条件设置
+         */
+        StringBuffer where = new StringBuffer(" 1=1 ");
+        if (content.containsKey("where")) {
+            JSONObject whereObject = content.getJSONObject("where");
+            if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
+                where.append(" and(");
+                where.append("t1.channelname like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t2.fagentname like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append(")");
+            }
+        }
+
+        SQLFactory costhead = new SQLFactory(this, "直播列表查询", pageSize, pageNumber, sort);
+        costhead.addParameter("siteid", siteid);
+        costhead.addParameter("tagentsid", tagentsid);
+        costhead.addParameter_SQL("where", where);
+        Rows rows = dbConnect.runSqlQuery(costhead.getSQL());
+        return getSucReturnObject().setDataByPaging(rows, sortfield).setFinalDo(DataPool.defaultdatalife, 1);
+    }
+
+    /**
+     * 直播详情查询
+     *
+     * @return
+     */
+    public String queryChannelMain() {
+        long tliveid = content.getLong("tliveid");
+        SQLFactory sqlFactory = new SQLFactory(this, "直播详情查询");
+        sqlFactory.addParameter("siteid", siteid);
+        sqlFactory.addParameter("tliveid", tliveid);
+        Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
+        return getSucReturnObject().setData(rows).toString();
+    }
+}

+ 1 - 1
src/dsb/com/cnd3b/restcontroller/enterprise/live/SQL/直播列表查询.sql

@@ -1,3 +1,3 @@
-select t1.tliveid, t1.createby, t1.createdate, t1.tagentsid,t2.fagentname, t1.categoryid, t1.channelname from tlive t1
+select t1.tliveid, t1.createby, t1.createdate, t1.tagentsid,t2.fagentname, t1.categoryid,t1.channelid,t1.categoryname, t1.channelname,t1.livestatus,t1.channelcoverimageurl from tlive t1
 inner join tagents t2 on t1.siteid=t2.siteid and t1.tagentsid=t2.tagentsid
 where t1.siteid=$siteid$ and $where$

+ 1 - 1
src/dsb/com/cnd3b/restcontroller/enterprise/live/SQL/直播详情查询.sql

@@ -1,5 +1,5 @@
 select t1.tliveid, t1.siteid, t1.createby, t1.changeby, t1.createdate, t1.changedate,
        t1.tactivityid, t1.tliveapplyid, t1.tagentsid, t1.fliveurl_web,t1.fliveurl_client, t1.fliveshowurl,
-       t1.categoryid, t1.channelname, t1.channelpasswd, t1.channelid,t1.fassistanturl,t1.fisneedauth,t1.secretkey from tlive t1
+       t1.categoryid,t1.categoryname, t1.channelname, t1.channelpasswd, t1.channelid,t1.fassistanturl,t1.fisneedauth,t1.secretkey,t1.livestatus,t1.channelcoverimageurl from tlive t1
 inner join tagents t2 on t1.siteid=t2.siteid and t1.tagentsid=t2.tagentsid
 where t1.siteid=$siteid$ and t1.tliveid=$tliveid$

+ 69 - 11
src/dsb/com/cnd3b/restcontroller/enterprise/live/live.java

@@ -1,18 +1,18 @@
 package com.cnd3b.restcontroller.enterprise.live;
 
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.cnd3b.common.Controller;
 import com.cnd3b.common.data.Rows;
 import com.cnd3b.common.data.SQLFactory;
 import com.cnd3b.common.data.db.DataPool;
 import com.cnd3b.utility.polyv.Polyv;
-import net.polyv.live.v1.entity.account.LiveListCategoryResponse.LiveCategory;
 import net.polyv.live.v1.entity.channel.operate.LiveChannelResponse;
 import p2.pao.PaoRemote;
 import p2.pao.PaoSetRemote;
 import p2.util.P2Exception;
 
-import java.util.List;
+import java.util.HashMap;
 import java.util.Random;
 
 public class live extends Controller {
@@ -27,8 +27,15 @@ public class live extends Controller {
      */
     public String getLiveCategory() {
         Polyv polyv = new Polyv();
-        List<LiveCategory> categoryList = polyv.listCategory();
-        return getSucReturnObject().setData(categoryList).toString();
+        HashMap<Integer, String> map = polyv.listCategory();
+        JSONArray array = new JSONArray();
+        for (int id : map.keySet()) {
+            JSONObject object = new JSONObject();
+            object.put("categoryId", id);
+            object.put("categoryName", map.get(id));
+            array.add(object);
+        }
+        return getSucReturnObject().setData(array).toString();
     }
 
     /**
@@ -82,26 +89,28 @@ public class live extends Controller {
      * @return
      */
     public String createLive() throws P2Exception {
-        String channelName = content.getString("channelName");
-        String channelPasswd = createPassWord();
-
+        long tagentsid = content.getLong("tagentsid");
+        String channelname = content.getString("channelname");
         int categoryid = content.getInteger("categoryid");
+        String channelPasswd = createPassWord();
         Polyv polyv = new Polyv();
-        LiveChannelResponse liveChannelResponse = polyv.createChannel(channelName, channelPasswd, categoryid);
+        LiveChannelResponse liveChannelResponse = polyv.createChannel(channelname, channelPasswd, categoryid);
         if (liveChannelResponse != null) {
             PaoSetRemote tliveSet = getP2ServerSystemPaoSet("tlive");
             PaoRemote tlive = tliveSet.addAtEnd();
             tlive.setValue("siteid", siteid);
             tlive.setValue("tagentsid", tagentsid);
             tlive.setValue("categoryid", categoryid);//分类ID
+            tlive.setValue("categoryname", polyv.listCategory().get(categoryid));//分类名称
             tlive.setValue("channelid", liveChannelResponse.getChannelId());//频道ID
             tlive.setValue("channelname", liveChannelResponse.getName());//频道名称
             tlive.setValue("channelpasswd", channelPasswd);//开播密码
+            tlive.setValue("livestatus", "unStart");//直播间状态
             tlive.setValue("fliveshowurl", "https://live.polyv.cn/watch/" + liveChannelResponse.getChannelId());//观看地址
             tlive.setValue("fliveurl_web", "https://live.polyv.net/web-start/login?channelId=" + liveChannelResponse.getChannelId());//网页开播地址
             tlive.setValue("fliveurl_client", "https://console.polyv.net/live/start-client.html?channelId=" + liveChannelResponse.getChannelId());//客户端开播地址
             tlive.setValue("fassistanturl", "https://console.polyv.net/live_v2/teacher.html");//助教地址
-
+            tlive.setValue("channelcoverimageurl", polyv.getChannelImage(liveChannelResponse.getChannelId(), "unStart"));//封面图地址
             tlive.setValue("createby", username);
             tlive.setValue("createdate", sysdate);
             content.put("tliveid", tlive.getUniqueIDValue());
@@ -114,7 +123,33 @@ public class live extends Controller {
     }
 
     /**
-     * 直播间外部授权设置
+     * 修改直播
+     *
+     * @return
+     */
+    public String modifyLive() throws P2Exception {
+        long tliveid = content.getLong("tliveid");
+        String channelname = content.getString("channelname");
+        int categoryid = content.getInteger("categoryid");
+        PaoSetRemote tliveSet = getP2ServerSystemPaoSet("tlive", "siteid='" + siteid + "' and tliveid='" + tliveid + "'");
+        if (tliveSet.isEmpty()) {
+            return getErrReturnObject().setErrMsg("找不到当前直播信息").toString();
+        }
+        PaoRemote tlive = tliveSet.getPao(0);
+        Polyv polyv = new Polyv();
+        boolean liveChannelResponse = polyv.updateChannelSetting(tlive.getString("channelid"), channelname, categoryid);
+        if (liveChannelResponse) {
+            tlive.setValue("categoryid", categoryid);//分类ID
+            tlive.setValue("categoryname", polyv.listCategory().get(categoryid));//分类名称
+            tlive.setValue("channelname", channelname);//频道名称
+            tliveSet.save();
+        }
+        return queryChannelMain();
+    }
+
+
+    /**
+     * 开启直播间外部授权设置
      *
      * @return
      */
@@ -136,6 +171,28 @@ public class live extends Controller {
         }
     }
 
+    /**
+     * 关闭直播间外部授权设置
+     *
+     * @return
+     */
+    public String closeChannelAuth() {
+        long tliveid = content.getLong("tliveid");
+        Rows rows = dbConnect.runSqlQuery("select channelid from tlive where siteid='" + siteid + "' and tliveid=" + tliveid);
+        if (rows.isEmpty()) {
+            return getErrReturnObject().setErrMsg("找不到当前直播间").toString();
+        }
+        String channelid = rows.get(0).getString("channelid");
+        Polyv polyv = new Polyv();
+        if (polyv.closeChannelAuthExternal(channelid)) {
+            dbConnect.runSqlUpdate("update tlive set fisneedauth=0,secretkey=null where siteid='" + siteid + "' and tliveid='" + tliveid + "'");
+            //需将改为新的直播观看地址
+            return queryChannelMain();
+        } else {
+            return getErrReturnObject().toString();
+        }
+    }
+
     /**
      * 直播间删除
      *
@@ -143,12 +200,12 @@ public class live extends Controller {
      */
     public String deleteLive() {
         String tliveid = content.getString("tliveid");
+
         Rows rows = dbConnect.runSqlQuery("select channelid from tlive where siteid='" + siteid + "' and tliveid=" + tliveid);
         if (rows.isEmpty()) {
             return getErrReturnObject().setErrMsg("找不到当前直播间").toString();
         }
         String channelid = rows.get(0).getString("channelid");
-
         Polyv polyv = new Polyv();
         if (polyv.deleteChannel(channelid)) {
             dbConnect.runSqlUpdate("delete from tlive where siteid='" + siteid + "' and tliveid='" + tliveid + "'");
@@ -163,6 +220,7 @@ public class live extends Controller {
      */
     public String liveauthorization() {
         String tliveid = content.getString("tliveid");//直播ID
+
         Rows rows = dbConnect.runSqlQuery("select channelId,secretkey from tlive where siteid='" + siteid + "' and tliveid='" + tliveid + "'");
         if (rows.isEmpty()) {
             return getErrReturnObject().toString();

+ 6 - 0
src/dsb/com/cnd3b/restcontroller/publicmethod/live/SQL/当前线上观众人数查询.sql

@@ -0,0 +1,6 @@
+select sum(t1.count)as fcount from tlive_usercount t1
+inner join (
+                select t1.channelid, max(time) as time from tlive t1
+                inner join tlive_usercount t2 on t1.channelid = t2.channelid
+                where t1.livestatus = 'live'
+            ) t2 on t1.channelid = t2.channelid and t1.time = t2.time

+ 31 - 0
src/dsb/com/cnd3b/restcontroller/publicmethod/live/live.java

@@ -0,0 +1,31 @@
+package com.cnd3b.restcontroller.publicmethod.live;
+
+import com.alibaba.fastjson.JSONObject;
+import com.cnd3b.common.Controller;
+import com.cnd3b.common.data.Rows;
+import com.cnd3b.common.data.SQLFactory;
+
+public class live extends Controller {
+    public live(JSONObject content) {
+        super(content);
+    }
+
+    /**
+     * 获取当前直播商户数
+     *
+     * @return
+     */
+    public String getLiveChannelData() {
+        Rows liveCountRows = dbConnect.runSqlQuery("select count(0)fcount from tlive where livestatus='live'");
+        Rows custCountrows = dbConnect.runSqlQuery(new SQLFactory(this, "当前线上观众人数查询").getSQL());
+        Rows totalcustCountrows = dbConnect.runSqlQuery("select count(0)fcount from TLIVE_VIEWLOG");
+
+        JSONObject resultObject = new JSONObject();
+        resultObject.put("flivecount", liveCountRows.isEmpty() ? 0 : liveCountRows.get(0).getInteger("fcount"));
+        resultObject.put("fcustcount", custCountrows.isEmpty() ? 0 : custCountrows.get(0).getInteger("fcount"));
+        resultObject.put("ftotallivetime", 1000);
+        resultObject.put("ftotalcustcount", totalcustCountrows.isEmpty() ? 0 : totalcustCountrows.get(0).getInteger("fcount"));
+        return getSucReturnObject().setData(resultObject).toString();
+    }
+    
+}

+ 258 - 0
src/dsb/com/cnd3b/service/GetPolyvAnalysisBigData.java

@@ -0,0 +1,258 @@
+package com.cnd3b.service;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.cnd3b.common.BaseClass;
+import com.cnd3b.common.data.Rows;
+import com.cnd3b.common.data.SQLFactory;
+import com.cnd3b.common.data.db.DBConnect;
+import com.cnd3b.common.data.db.SQLiteJDBC;
+import com.cnd3b.utility.polyv.Polyv;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.HashMap;
+
+/**
+ * 保利威统计数据查询,频率5分钟一次
+ */
+public class GetPolyvAnalysisBigData extends BaseClass implements Runnable {
+    @Override
+    public void run() {
+        try {
+            if (new SQLiteJDBC().checkServicesUsed("GetPolyvAnalysisBigData", false)) {
+                getLiveData();
+                getLiveviewLog();
+                getLiveMessageList();
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 获取频道直播概览统计数据表
+     */
+    public void getLiveData() {
+        DBConnect dbConnect = new DBConnect();
+        String[] channelids = dbConnect.runSqlQuery("select channelid from tlive where livestatus in('live','waiting') and convert(varchar(10),lastlivedate,120)=convert(varchar(10),getDate(),120) ").toArray("channelid");
+        Polyv polyv = new Polyv();
+        ArrayList<String> sqllist = new ArrayList<>();
+        JSONArray dataArray = polyv.getChannelSummary(channelids, getDate_Str());
+        if (dataArray == null) {
+            return;
+        }
+        for (Object o : dataArray) {
+            JSONObject contentsObject = (JSONObject) o;
+            String userId = contentsObject.getString("userId");
+            String channelId = contentsObject.getString("channelId");
+            String name = contentsObject.getString("name");
+            int pcPlayDuration = contentsObject.getInteger("pcPlayDuration");
+            long pcFlowSize = contentsObject.getLong("pcFlowSize");
+            int pcVideoView = contentsObject.getInteger("pcVideoView");
+            int pcUniqueViewer = contentsObject.getInteger("pcUniqueViewer");
+            int mobilePlayDuration = contentsObject.getInteger("mobilePlayDuration");
+            long mobileFlowSize = contentsObject.getLong("mobileFlowSize");
+            int mobileVideoView = contentsObject.getInteger("mobileVideoView");
+            int mobileUniqueViewer = contentsObject.getInteger("mobileUniqueViewer");
+            int livePcPlayDuration = contentsObject.getInteger("livePcPlayDuration");
+            int playbackPcPlayDuration = contentsObject.getInteger("playbackPcPlayDuration");
+            int liveMobilePlayDuration = contentsObject.getInteger("liveMobilePlayDuration");
+            int playbackMobilePlayDuration = contentsObject.getInteger("playbackMobilePlayDuration");
+            int unknownPcPlayDuration = contentsObject.getInteger("unknownPcPlayDuration");
+            int unknownMobilePlayDuration = contentsObject.getInteger("unknownMobilePlayDuration");
+            String creatorName = contentsObject.getString("creatorName");//
+
+            SQLFactory sqlFactory = new SQLFactory(this, "频道直播概览统计数据插入");
+            sqlFactory.addParameter("date", getDate_Str());
+            sqlFactory.addParameter("userid", userId);
+            sqlFactory.addParameter("channelid", channelId);
+            sqlFactory.addParameter("name", name);
+            sqlFactory.addParameter("pcplayduration", pcPlayDuration);
+            sqlFactory.addParameter("pcflowsize", pcFlowSize);
+            sqlFactory.addParameter("pcvideoview", pcVideoView);
+            sqlFactory.addParameter("pcuniqueviewer", pcUniqueViewer);
+            sqlFactory.addParameter("mobileplayduration", mobilePlayDuration);
+            sqlFactory.addParameter("mobileflowsize", mobileFlowSize);
+            sqlFactory.addParameter("mobilevideoview", mobileVideoView);
+            sqlFactory.addParameter("mobileuniqueviewer", mobileUniqueViewer);
+            sqlFactory.addParameter("livepcplayduration", livePcPlayDuration);
+            sqlFactory.addParameter("playbackpcplayduration", playbackPcPlayDuration);
+            sqlFactory.addParameter("livemobileplayduration", liveMobilePlayDuration);
+            sqlFactory.addParameter("playbackmobileplayduratio", playbackMobilePlayDuration);
+            sqlFactory.addParameter("unknownpcplayduration", unknownPcPlayDuration);
+            sqlFactory.addParameter("unknownmobileplayduration", unknownMobilePlayDuration);
+            sqlFactory.addParameter("creatorname", creatorName);
+            sqllist.add(sqlFactory.getSQL());
+        }
+        dbConnect.runSqlUpdate(sqllist);
+    }
+
+
+    /**
+     * 获取频道直播观看详情数据
+     */
+    public void getLiveviewLog() {
+        DBConnect dbConnect = new DBConnect();
+        String[] channelids = dbConnect.runSqlQuery("select channelid from tlive where livestatus in('live','waiting') and convert(varchar(10),lastlivedate,120)=convert(varchar(10),getDate(),120) ").toArray("channelid");
+        Polyv polyv = new Polyv();
+        out:
+        for (String channelid : channelids) {
+            ArrayList<String> sqllist = new ArrayList<>();
+            boolean islastpage;
+            int pageNumber = 1;
+            do {
+                JSONObject object = polyv.getPageViewlog(channelid, getDate_Str(), "200", String.valueOf(pageNumber++));
+                if (object == null) {
+                    continue out;
+                }
+                islastpage = object.getBoolean("lastPage");
+                JSONArray contentsarray = object.getJSONArray("contents");
+                for (Object o : contentsarray) {
+                    JSONObject contentsObject = (JSONObject) o;
+                    String playId = contentsObject.getString("playId");
+                    String userId = contentsObject.getString("userId");
+                    String channelId = contentsObject.getString("channelId");
+                    int playDuration = contentsObject.getInteger("playDuration");
+                    int stayDuration = contentsObject.getInteger("stayDuration");
+                    long flowSize = contentsObject.getLong("flowSize");
+                    String sessionId = contentsObject.getString("sessionId");
+                    String param1 = contentsObject.getString("param1");
+                    String param2 = contentsObject.getString("param2");
+                    String param3 = contentsObject.getString("param3");
+                    String param4 = contentsObject.getString("param4");
+                    String param5 = contentsObject.getString("param5");
+                    String ipAddress = contentsObject.getString("ipAddress");
+                    String country = contentsObject.getString("country");
+                    String province = contentsObject.getString("province");
+                    String city = contentsObject.getString("city");
+                    String isp = contentsObject.getString("isp");
+                    String referer = contentsObject.getString("referer");
+                    String userAgent = contentsObject.getString("userAgent");
+                    String operatingSystem = contentsObject.getString("operatingSystem");
+                    String browser = contentsObject.getString("browser");
+                    String isMobile = contentsObject.getString("isMobile");
+                    String currentDay = contentsObject.getString("currentDay");
+                    long createdTime = contentsObject.getLong("createdTime");
+                    long lastModified = contentsObject.getLong("lastModified");
+                    int ptype = contentsObject.getInteger("ptype");
+
+                    SQLFactory sqlFactory = new SQLFactory(this, "频道直播观看详情数据插入");
+                    sqlFactory.addParameter("ptype", ptype);
+                    sqlFactory.addParameter("playid", playId);
+                    sqlFactory.addParameter("userid", userId);
+                    sqlFactory.addParameter("channelid", channelId);
+                    sqlFactory.addParameter("playduration", playDuration);
+                    sqlFactory.addParameter("stayduration", stayDuration);
+                    sqlFactory.addParameter("flowsize", flowSize);
+                    sqlFactory.addParameter("sessionid", sessionId);
+                    sqlFactory.addParameter("param1", param1);
+                    sqlFactory.addParameter("param2", param2);
+                    sqlFactory.addParameter("param3", param3);
+                    sqlFactory.addParameter("param4", param4);
+                    sqlFactory.addParameter("param5", param5);
+                    sqlFactory.addParameter("ipaddress", ipAddress);
+                    sqlFactory.addParameter("country", country);
+                    sqlFactory.addParameter("province", province);
+                    sqlFactory.addParameter("city", city);
+                    sqlFactory.addParameter("isp", isp);
+                    sqlFactory.addParameter("referer", referer);
+                    sqlFactory.addParameter("useragent", userAgent);
+                    sqlFactory.addParameter("operatingsystem", operatingSystem);
+                    sqlFactory.addParameter("browser", browser);
+                    sqlFactory.addParameter("ismobile", isMobile);
+                    sqlFactory.addParameter("currentday", currentDay);
+                    sqlFactory.addParameter("createdtime", createdTime);
+                    sqlFactory.addParameter("lastmodified", lastModified);
+                    sqllist.add(sqlFactory.getSQL());
+                }
+            } while (!islastpage);
+            dbConnect.runSqlUpdate(sqllist);
+        }
+    }
+
+
+    /**
+     * 获取频道直播观众聊天记录
+     */
+    public void getLiveMessageList() {
+        DBConnect dbConnect = new DBConnect();
+        String[] channelids = dbConnect.runSqlQuery("select channelid from tlive where livestatus in('live','waiting') and convert(varchar(10),lastlivedate,120)=convert(varchar(10),getDate(),120) ").toArray("channelid");
+        Polyv polyv = new Polyv();
+        out:
+        for (String channelid : channelids) {
+            String fdate = getDate_Str();
+            Rows maxtimerows = dbConnect.runSqlQuery("select isnull(max(time),0) as ftime from tlive_usermessages where channelid='" + channelid + "' having isnull(max(time),0)>0");
+            if (!maxtimerows.isEmpty()) {
+                Calendar calendar = Calendar.getInstance();
+                calendar.setTimeInMillis(Long.parseLong(maxtimerows.get(0).getString("ftime")) + 1000);
+                fdate = getDateTime_Str(calendar.getTime());
+            }
+            ArrayList<String> sqllist = new ArrayList<>();
+            boolean islastpage;
+            int pageNumber = 1;
+            do {
+                JSONObject object = polyv.getPageMessageList(channelid, fdate, "200", String.valueOf(pageNumber++));
+                if (object == null) {
+                    continue out;
+                }
+                JSONArray contentsarray = object.getJSONArray("contents");
+                islastpage = contentsarray.size() == 0;
+                for (Object o : contentsarray) {
+                    JSONObject contentsObject = (JSONObject) o;
+                    String id = contentsObject.getString("id");
+                    String accountId = contentsObject.getString("accountId");
+                    String clientIP = contentsObject.getString("clientIP");
+                    String content = contentsObject.getString("content");
+                    String event = contentsObject.getString("event");
+                    String image = contentsObject.getString("image");
+                    String msgType = contentsObject.getString("msgType");
+                    String quote = contentsObject.getString("quote");
+                    String sessionId = contentsObject.getString("sessionId");
+                    String roomId = contentsObject.getString("roomId");
+                    String channelId = contentsObject.getString("channelId");
+                    String time = contentsObject.getString("time");
+                    String userType = contentsObject.getString("userType");
+                    String status = contentsObject.getString("status");
+                    String sourceType = contentsObject.getString("sourceType");
+
+                    JSONObject userObject = contentsObject.getJSONObject("user");
+
+                    String actor = userObject.getString("actor");
+                    boolean banned = userObject.getBoolean("banned");
+                    String nickname = userObject.getString("nickname");
+                    String pic = userObject.getString("pic");
+                    String uid = userObject.getString("uid");
+                    String userId = userObject.getString("userId");
+                    String userSource = userObject.getString("userSource");
+
+                    SQLFactory sqlFactory = new SQLFactory(this, "频道直播观众聊天记录数据插入");
+                    sqlFactory.addParameter("id", id);
+                    sqlFactory.addParameter("accountid", accountId);
+                    sqlFactory.addParameter("clientip", clientIP);
+                    sqlFactory.addParameter("content", content);
+                    sqlFactory.addParameter("event", event);
+                    sqlFactory.addParameter("imageurl", image);
+                    sqlFactory.addParameter("msgtype", msgType);
+                    sqlFactory.addParameter("quote", quote);
+                    sqlFactory.addParameter("sessionid", sessionId);
+                    sqlFactory.addParameter("roomid", roomId);
+                    sqlFactory.addParameter("channelid", channelId);
+                    sqlFactory.addParameter("time", time);
+                    sqlFactory.addParameter("usertype", userType);
+                    sqlFactory.addParameter("status", status);
+                    sqlFactory.addParameter("sourcetype", sourceType);
+                    sqlFactory.addParameter("actor", actor);
+                    sqlFactory.addParameter("banned", banned ? 1 : 0);
+                    sqlFactory.addParameter("nickname", nickname);
+                    sqlFactory.addParameter("pic", pic);
+                    sqlFactory.addParameter("uid", uid);
+                    sqlFactory.addParameter("userid", userId);
+                    sqlFactory.addParameter("usersource", userSource);
+                    sqllist.add(sqlFactory.getSQL());
+                }
+            } while (!islastpage);
+            dbConnect.runSqlUpdate(sqllist);
+        }
+    }
+}

+ 74 - 0
src/dsb/com/cnd3b/service/GetPolyvAnalysisData.java

@@ -0,0 +1,74 @@
+package com.cnd3b.service;
+
+import com.alibaba.fastjson.JSONObject;
+import com.cnd3b.common.BaseClass;
+import com.cnd3b.common.data.SQLFactory;
+import com.cnd3b.common.data.db.DBConnect;
+import com.cnd3b.common.data.db.SQLiteJDBC;
+import com.cnd3b.utility.polyv.Polyv;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+
+/**
+ * 保利威统计数据查询,频率30秒一次
+ */
+public class GetPolyvAnalysisData extends BaseClass implements Runnable {
+    @Override
+    public void run() {
+        try {
+            if (new SQLiteJDBC().checkServicesUsed("GetPolyvAnalysisData", false)) {
+                getLiveStatusAndCoverImageUrl();
+                getLiveUserCount();
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 同步频道直播状态,及获取直播封面图
+     */
+    public void getLiveStatusAndCoverImageUrl() {
+        DBConnect dbConnect = new DBConnect();
+        String[] channelids = dbConnect.runSqlQuery("select channelid from tlive").toArray("channelid");
+        Polyv polyv = new Polyv();
+        HashMap<String, String> livestatusMap = polyv.getLiveStatuses(channelids);
+        ArrayList<String> sqllist = new ArrayList<>();
+        for (String channelid : livestatusMap.keySet()) {
+            String livestatus = livestatusMap.get(channelid);
+            if (livestatus.equalsIgnoreCase("live")) {
+                sqllist.add("update tlive set livestatus='" + livestatus + "',lastlivedate='" + getDate_Str() + "' ,channelcoverimageurl='" + polyv.getChannelImage(channelid, livestatus) + "' where channelid='" + channelid + "'");
+            } else if (livestatus.equalsIgnoreCase("waiting")) {
+                sqllist.add("update tlive set livestatus='" + livestatus + "',channelcoverimageurl='" + polyv.getChannelImage(channelid, livestatus) + "' where channelid='" + channelid + "'");
+            } else {
+                sqllist.add("update tlive set livestatus='" + livestatus + "' where channelid='" + channelid + "'");
+            }
+        }
+        dbConnect.runSqlUpdate(sqllist);
+    }
+
+    /**
+     * 获取频道实时在线人数
+     */
+    public void getLiveUserCount() {
+        DBConnect dbConnect = new DBConnect();
+        ArrayList<String> sqllist = new ArrayList<>();
+        String[] channelids = dbConnect.runSqlQuery("select channelid from tlive where livestatus='live'").toArray("channelid");
+        Polyv polyv = new Polyv();
+        for (String channelid : channelids) {
+            JSONObject object = polyv.getRealtimeViewers(channelid);
+            String channelId = object.getString("channelId");
+            String time = object.getString("time");
+            String count = object.getString("count");
+
+            SQLFactory sqlFactory = new SQLFactory(this, "直播频道在线用户数插入");
+            sqlFactory.addParameter("channelid", channelId);
+            sqlFactory.addParameter("time", getDate_Str() + " " + time);
+            sqlFactory.addParameter("count", count);
+            sqllist.add(sqlFactory.getSQL());
+        }
+        dbConnect.runSqlUpdate(sqllist);
+    }
+
+}

+ 2 - 0
src/dsb/com/cnd3b/service/SQL/直播频道在线用户数插入.sql

@@ -0,0 +1,2 @@
+insert into tlive_usercount( rmkenable, channelid, time, count)
+select 0,$channelid$,$time$,$count$ where not exists(select * from tlive_usercount where channelid=$channelid$ and time=$time$)

+ 33 - 0
src/dsb/com/cnd3b/service/SQL/频道直播概览统计数据插入.sql

@@ -0,0 +1,33 @@
+update tlive_data set
+pcplayduration=$pcplayduration$,
+pcflowsize=$pcflowsize$,
+pcvideoview=$pcvideoview$,
+pcuniqueviewer=$pcuniqueviewer$,
+mobileplayduration=$mobileplayduration$,
+mobileflowsize=$mobileflowsize$,
+mobilevideoview=$mobilevideoview$,
+mobileuniqueviewer=$mobileuniqueviewer$,
+livepcplayduration=$livepcplayduration$,
+playbackpcplayduration=$playbackpcplayduration$,
+livemobileplayduration=$livemobileplayduration$,
+unknownpcplayduration=$unknownpcplayduration$,
+creatorname=$creatorname$,
+unknownmobileplayduration=$unknownmobileplayduration$,
+playbackmobileplayduratio=$playbackmobileplayduratio$,
+changedate=getdate()
+where channelid =$channelid$ and date =$date$
+
+insert into tlive_data(date, rmkenable, channelid,
+                       name, userid, pcplayduration, pcflowsize, pcvideoview,
+                       pcuniqueviewer, mobileplayduration, mobileflowsize, mobilevideoview, mobileuniqueviewer,
+                       livepcplayduration, playbackpcplayduration, livemobileplayduration, unknownpcplayduration,
+                       creatorname,
+                       unknownmobileplayduration, playbackmobileplayduratio, createdate, changedate)
+select $date$,0,$channelid$,
+    $name$,$userid$,$pcplayduration$,$pcflowsize$,$pcvideoview$,
+    $pcuniqueviewer$,$mobileplayduration$,$mobileflowsize$,$mobilevideoview$,$mobileuniqueviewer$,
+    $livepcplayduration$,$playbackpcplayduration$,$livemobileplayduration$,$unknownpcplayduration$,
+    $creatorname$,
+    $unknownmobileplayduration$,$playbackmobileplayduratio$,getdate(),getdate()
+where not exists (select * from tlive_data where channelid =$channelid$ and date =$date$)
+

+ 10 - 0
src/dsb/com/cnd3b/service/SQL/频道直播观众聊天记录数据插入.sql

@@ -0,0 +1,10 @@
+insert into tlive_usermessages(rmkenable, id, accountid, clientip,
+                               content, event, imageurl, msgtype, quote,
+                               sessionid, roomid, channelid, time, usertype,
+                               status, sourcetype, actor, banned, pic,
+                               nickname, uid, userid,usersource)
+select 0, $id$, $accountid$, $clientip$,
+       $content$, $event$, $imageurl$, $msgtype$, $quote$,
+       $sessionid$, $roomid$, $channelid$, $time$, $usertype$,
+       $status$, $sourcetype$, $actor$, $banned$, $pic$,
+       $nickname$, $uid$, $userid$,$usersource$

+ 20 - 0
src/dsb/com/cnd3b/service/SQL/频道直播观看详情数据插入.sql

@@ -0,0 +1,20 @@
+update tlive_viewlog set
+playDuration=$playduration$,
+stayDuration=$stayduration$,
+flowSize=$flowsize$,
+lastModified=$lastmodified$
+where channelid =$channelid$ and playid=$playid$
+
+insert into tlive_viewlog(ptype, rmkenable, playid, userid, channelid,
+                          playduration, stayduration, flowsize, sessionid, param1,
+                          param2, param3, param4, param5, ipaddress,
+                          country, province, city, isp, referer,
+                          useragent, operatingsystem, browser, ismobile, currentday,
+                          createdtime, lastmodified)
+select $ptype$, 0, $playid$, $userid$, $channelid$,
+    $playduration$, $stayduration$, $flowsize$, $sessionid$, $param1$,
+    $param2$, $param3$, $param4$, $param5$, $ipaddress$,
+    $country$, $province$, $city$, $isp$, $referer$,
+    $useragent$, $operatingsystem$, $browser$, $ismobile$, $currentday$,
+    $createdtime$, $lastmodified$
+where not exists (select * from tlive_viewlog where channelid =$channelid$ and playid=$playid$)

+ 364 - 64
src/dsb/com/cnd3b/utility/polyv/Polyv.java

@@ -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;
     }
+
 }