|
|
@@ -0,0 +1,182 @@
|
|
|
+package com.cnd3b.restcontroller.enterprise.live;
|
|
|
+
|
|
|
+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.Random;
|
|
|
+
|
|
|
+public class live extends Controller {
|
|
|
+ public live(JSONObject content) {
|
|
|
+ super(content);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取频道分类列表
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String getLiveCategory() {
|
|
|
+ Polyv polyv = new Polyv();
|
|
|
+ List<LiveCategory> categoryList = polyv.listCategory();
|
|
|
+ return getSucReturnObject().setData(categoryList).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_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();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建直播
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String createLive() throws P2Exception {
|
|
|
+ String channelName = content.getString("channelName");
|
|
|
+ String channelPasswd = createPassWord();
|
|
|
+
|
|
|
+ int categoryid = content.getInteger("categoryid");
|
|
|
+ Polyv polyv = new Polyv();
|
|
|
+ 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("channelid", liveChannelResponse.getChannelId());//频道ID
|
|
|
+ tlive.setValue("channelname", liveChannelResponse.getName());//频道名称
|
|
|
+ tlive.setValue("channelpasswd", channelPasswd);//开播密码
|
|
|
+ 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("createby", username);
|
|
|
+ tlive.setValue("createdate", sysdate);
|
|
|
+ content.put("tliveid", tlive.getUniqueIDValue());
|
|
|
+ tliveSet.save();
|
|
|
+
|
|
|
+ } else {
|
|
|
+ return getErrReturnObject().toString();
|
|
|
+ }
|
|
|
+ return queryChannelMain();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 直播间外部授权设置
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String setChannelAuth() {
|
|
|
+ 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();
|
|
|
+ String secretKey = polyv.updateChannelAuthExternal(channelid);
|
|
|
+ if (secretKey == null) {
|
|
|
+ return getErrReturnObject().toString();
|
|
|
+ } else {
|
|
|
+ dbConnect.runSqlUpdate("update tlive set fisneedauth=1,secretkey='" + secretKey + "' where siteid='" + siteid + "' and tliveid='" + tliveid + "'");
|
|
|
+ return queryChannelMain();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 直播间删除
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ 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 + "'");
|
|
|
+ }
|
|
|
+ return getSucReturnObject().toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 直播授权
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ 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();
|
|
|
+ }
|
|
|
+ return getSucReturnObject().setData(new Polyv().getSignUrl(rows.get(0).getString("channelId"), rows.get(0).getString("secretkey"), userid)).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private String createPassWord() {
|
|
|
+ String allChar = "1234567890";
|
|
|
+ StringBuffer sb = new StringBuffer();
|
|
|
+ Random random = new Random();
|
|
|
+ for (int i = 0; i < 6; i++) {
|
|
|
+ sb.append(allChar.charAt(random.nextInt(allChar.length())));
|
|
|
+ }
|
|
|
+ return sb.toString();
|
|
|
+ }
|
|
|
+}
|