沈静伟 4 лет назад
Родитель
Сommit
34758436c2

+ 57 - 2
src/dsb/com/cnd3b/common/restful/WebClientRest.java

@@ -1,7 +1,5 @@
 package com.cnd3b.common.restful;
 
-import com.cnd3b.restcontroller.publicmethod.users.Users;
-import com.cnd3b.utility.Encryption;
 import com.alibaba.fastjson.JSONException;
 import com.alibaba.fastjson.JSONObject;
 import com.cnd3b.common.D3BReturnObject_Err;
@@ -11,7 +9,9 @@ import com.cnd3b.common.data.SQLFactory;
 import com.cnd3b.common.data.db.DBConnect;
 import com.cnd3b.common.data.db.DataPool;
 import com.cnd3b.common.parameter.parameter;
+import com.cnd3b.restcontroller.publicmethod.users.Users;
 import com.cnd3b.restcontroller.system.system.uploadExcelData;
+import com.cnd3b.utility.Encryption;
 import com.cnd3b.utility.Sms;
 import com.cnd3b.utility.sysmsg;
 import com.cnd3b.utility.wechatpay.apppay.POJO.APPQueryOrderRequest;
@@ -21,6 +21,7 @@ import com.cnd3b.utility.wechatpay.jsapipay.POJO.JSQueryOrderRequest;
 import com.cnd3b.utility.wechatpay.jsapipay.POJO.JSWechatOrder;
 import com.cnd3b.utility.wechatpay.jsapipay.jsapipay;
 import com.cnd3b.utility.wechatpay.nativepay.nativepay;
+import net.polyv.live.v1.util.LiveSignUtil;
 import org.dom4j.dom.DOMElement;
 import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
 import org.glassfish.jersey.media.multipart.FormDataParam;
@@ -276,6 +277,7 @@ public class WebClientRest {
             JSONObject object = new JSONObject();
             object.put("code", 1);
             object.put("msg", "手机验证码为:" + password);
+            System.err.println("手机验证码为:" + password);
             return object.toString();
         } else {
             JSONObject object = new JSONObject();
@@ -535,4 +537,57 @@ public class WebClientRest {
     public String sysmsg() throws JSONException {
         return new sysmsg().getCustMsg();
     }
+
+    @POST
+    @Path("polyvAuth")
+    public String polyvAuth(@FormParam("channelId") String channelId, @FormParam("userid") String userid, @FormParam("ts") Long ts, @FormParam("token") String token) {
+
+        JSONObject result = new JSONObject();
+        long timeMillis = System.currentTimeMillis();
+        long diffTime = Math.abs(timeMillis - ts);
+        //1、时间戳判断
+        if (diffTime > 5 * 60 * 1000) {
+            result.put("status", "0");
+            //抛出异常时,如果设置errorUrl,则会跳转到 errorUrl ,如果未返回 errorUrl,则先查询 外部授权参数
+            // externalRedirectUri,externalRedirectUri不为空则跳转externalRedirectUri地址,externalRedirectUri为空则跳转保利威默认页面
+            result.put("errorUrl", "https://www.polyv.net");
+            return result.toJSONString();
+        }
+
+        //2、签名判断
+        DBConnect dbConnect = new DBConnect();
+        Rows rows = dbConnect.runSqlQuery("select secretkey from tlive where channelId='" + channelId + "'");
+        if (rows.isEmpty()) {
+            result.put("errorUrl", "https://www.polyv.net");
+            return result.toJSONString();
+        }
+        String signText = rows.get(0).getString("secretkey") + userid + rows.get(0).getString("secretkey") + ts;
+        String sign = null;
+        try {
+            sign = LiveSignUtil.md5Hex(signText);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        if (sign == null || !sign.equals(token)) {
+            result.put("status", "0");
+            //抛出异常时,如果设置errorUrl,则会跳转到 errorUrl ,如果未返回 errorUrl,则先查询 外部授权参数
+            // externalRedirectUri,externalRedirectUri不为空则跳转externalRedirectUri地址,externalRedirectUri为空则跳转保利威默认页面
+            result.put("errorUrl", "https://www.polyv.net");
+            return result.toJSONString();
+        }
+        // 业务逻辑处理,后续需根据具体需求进行数据库操作
+        //3、正常返回
+        Row userrow = parameter.userIdList.get(userid);
+        result.put("status", "1");
+        result.put("userid", userid);
+        result.put("nickname", userrow.getString("fname"));
+        result.put("marqueeName", "保利威测试跑马灯");
+        // result.put("actor", "学生");
+        result.put("actorFColor", "#2469f3");
+        result.put("actorBgColor", null);
+        result.put("param4", null);
+        result.put("param5", null);
+        result.put("avatar", "http://dev.polyv.net/favicon.ico");
+        return result.toJSONString();
+    }
 }

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

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

+ 5 - 0
src/dsb/com/cnd3b/restcontroller/enterprise/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.channelname, t1.channelpasswd, t1.channelid,t1.fassistanturl,t1.fisneedauth,t1.secretkey 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$

+ 254 - 0
src/dsb/com/cnd3b/utility/polyv/Polyv.java

@@ -0,0 +1,254 @@
+package com.cnd3b.utility.polyv;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import junit.framework.Assert;
+import net.polyv.common.v1.exception.PloyvSdkException;
+import net.polyv.live.v1.config.LiveGlobalConfig;
+import net.polyv.live.v1.constant.LiveConstant;
+import net.polyv.live.v1.entity.account.LiveCreateCategoryRequest;
+import net.polyv.live.v1.entity.account.LiveCreateCategoryResponse;
+import net.polyv.live.v1.entity.account.LiveListCategoryRequest;
+import net.polyv.live.v1.entity.account.LiveListCategoryResponse;
+import net.polyv.live.v1.entity.channel.operate.*;
+import net.polyv.live.v1.entity.web.auth.LiveChannelAuthExternalRequest;
+import net.polyv.live.v1.entity.web.auth.LiveChannelAuthExternalResponse;
+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 java.io.IOException;
+import java.security.NoSuchAlgorithmException;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.List;
+
+public class Polyv {
+    String appid = "g3mt33nllk";
+    String userid = "8c1720a694";
+    String appSecret = "97363458f676438280c22b1d05185031";
+
+    public Polyv() {
+        /**
+         * 全局设置
+         */
+        LiveGlobalConfig.init(appid, userid, appSecret);
+    }
+
+    public static void main(String[] args) {
+//        Polyv polyv = new Polyv();
+//        polyv.listCategory();
+    }
+
+    /**
+     * 生成授权播放地址
+     *
+     * @return
+     */
+    public String getSignUrl(String channelId, String secretKey, long userid) {
+        String ts = String.valueOf(System.currentTimeMillis());
+        String url = "https://live.polyv.cn/watch/" + channelId;
+        String signText = secretKey + userid + secretKey + ts;
+        try {
+            String sign = LiveSignUtil.md5Hex(signText);
+            url += "?userid=" + userid + "&ts=" + ts + "&sign=" + sign;
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return url;
+    }
+
+    /**
+     * 创建频道
+     *
+     * @throws Exception
+     * @throws NoSuchAlgorithmException
+     */
+    public LiveChannelResponse createChannel(String channelName, String channelPasswd, int categoryId) {
+        LiveChannelRequest liveChannelRequest = new LiveChannelRequest();
+        LiveChannelResponse liveChannelResponse = null;
+        try {
+            liveChannelRequest.setName(channelName);//频道名称
+            liveChannelRequest.setChannelPasswd(channelPasswd);//频道密码,长度不能超过16位
+            liveChannelRequest.setAutoPlay(LiveConstant.AutoPlay.AOTU_PLAY.getFlag());//是否自动播放标识,0:关闭自动播放;1:开启,默认取值 1
+            //liveChannelRequest.setPlayerColor("#666666");//播放器控制栏颜色,默认:#666666
+            //liveChannelRequest.setScene(LiveConstant.SceneType.ALONE.getDesc());//直播场景:alone 活动拍摄; ppt 三分屏; topclass 大班课; seminar 研讨会; 默认:alone
+            liveChannelRequest.setCategoryId(categoryId);//分类ID ,新建频道的所属分类,如果不提交,则为默认分类(分类ID可通过“获取直播分类”接口得到)
+            //liveChannelRequest.setMaxViewer(100);//频道的最大在线人数观看限制的人数
+            //liveChannelRequest.setWatchLayout(LiveConstant.WatchLayout.PPT.getFlag());//三分屏频道的观看布局,ppt:文档为主;video:视频为主;不设置会使用账号的通用设置
+            //liveChannelRequest.setLinkMicLimit(-1);//连麦人数,-1=<取值范围<=账号级的连麦人数,-1:表示使用账号默认的连麦人数,最大16人(注:账号级连麦人数需通知平台管理员设置才生效)
+            //liveChannelRequest.setPureRtcEnabled(LiveConstant.Flag.NO.getFlag());//是否为无延时直播,Y 表示开启,默认为N
+            //liveChannelRequest.setReceive(LiveConstant.Flag.YES.getFlag());//是否为接收转播频道,Y表示是,不填或者填其他值为发起转播频道(注:需要开启频道转播功能该参数才生效)
+            //liveChannelRequest.setReceiveChannelIds("");//接收转播频道号,多个频道号用半角逗号,隔开,如果receive参数值为Y时,此参数无效(注:需要开启频道转播功能该参数才生效)
+            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) {
+            //参数校验不合格 或者 请求服务器端500错误,错误信息见PloyvSdkException.getMessage(),B
+            //log.error(e.getMessage(), e);
+            // 异常返回做B端异常的业务逻辑,记录log 或者 上报到ETL 或者回滚事务
+            throw e;
+        } catch (Exception e) {
+            // log.error("SDK调用异常", e);
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    /**
+     * 设置频道外部授权
+     *
+     * @throws Exception
+     * @throws NoSuchAlgorithmException
+     */
+    public String updateChannelAuthExternal(String channelId) {
+        LiveChannelAuthExternalRequest liveChannelAuthExternalRequest = new LiveChannelAuthExternalRequest();
+        LiveChannelAuthExternalResponse liveChannelAuthExternalResponse;
+        try {
+            liveChannelAuthExternalRequest.setChannelId(channelId);
+            liveChannelAuthExternalRequest.setExternalUri("http://123.60.111.36:8080/bwj/rest/webclientrest/polyvAuth");
+            liveChannelAuthExternalResponse = new LiveWebAuthServiceImpl().updateChannelAuthExternal(
+                    liveChannelAuthExternalRequest);
+            Assert.assertNotNull(liveChannelAuthExternalResponse);
+            if (liveChannelAuthExternalResponse != null && !liveChannelAuthExternalResponse.getChannelAuthExternals().isEmpty()) {
+                return liveChannelAuthExternalResponse.getChannelAuthExternals().get(0).getSecretKey();
+                //to do something ......
+                //log.debug("测试通过接口设置外部授权成功,{}", JSON.toJSONString(liveChannelAuthExternalResponse));
+            }
+        } catch (Exception e) {
+            //参数校验不合格 或者 请求服务器端500错误,错误信息见PloyvSdkException.getMessage()
+            //log.error(e.getMessage(), e);
+            // 异常返回做B端异常的业务逻辑,记录log 或者 上报到ETL 或者回滚事务
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    /**
+     * 频道删除
+     *
+     * @throws Exception
+     * @throws NoSuchAlgorithmException
+     */
+    public boolean deleteChannel(String channelId) {
+        LiveDeleteChannelRequest liveDeleteChannelRequest = new LiveDeleteChannelRequest();
+        Boolean liveDeleteChannelResponse;
+        try {
+            liveDeleteChannelRequest.setChannelId(channelId);
+            liveDeleteChannelResponse = new LiveChannelOperateServiceImpl().deleteChannel(liveDeleteChannelRequest);
+            Assert.assertNotNull(liveDeleteChannelResponse);
+            return liveDeleteChannelResponse;
+        } catch (PloyvSdkException e) {
+            e.printStackTrace();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return false;
+    }
+
+
+    public JSONObject testGetChannelInfo() throws Exception, NoSuchAlgorithmException {
+        LiveChannelInfoRequest liveChannelInfoRequest = new LiveChannelInfoRequest();
+        LiveChannelInfoResponse liveChannelInfoResponse;
+        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) {
+            e.printStackTrace();
+        }
+        return new JSONObject();
+    }
+
+    public JSONObject testGetChannelBasicInfo() throws Exception, NoSuchAlgorithmException {
+        LiveChannelBasicInfoRequest liveChannelBasicInfoRequest = new LiveChannelBasicInfoRequest();
+        LiveChannelBasicInfoResponse liveChannelBasicInfoResponse;
+        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) {
+            e.printStackTrace();
+        }
+        return new JSONObject();
+    }
+
+    /**
+     * 查询频道直播截图
+     *
+     * @return
+     */
+    public String getChannelCapture() {
+        LiveChannelCaptureRequest liveChannelCaptureRequest = new LiveChannelCaptureRequest();
+        String liveChannelCaptureResponse;
+        try {
+            //准备测试数据
+            String channelId = "2636984";
+            liveChannelCaptureRequest.setChannelId(channelId);
+            liveChannelCaptureResponse = new LiveChannelOperateServiceImpl().getChannelCapture(
+                    liveChannelCaptureRequest);
+            Assert.assertNotNull(liveChannelCaptureResponse);
+            return JSON.toJSONString(liveChannelCaptureResponse);
+        } catch (PloyvSdkException | IOException | NoSuchAlgorithmException e) {
+            e.printStackTrace();
+        }
+        return "";
+    }
+
+    /**
+     * 创建直播分类
+     *
+     * @throws Exception
+     */
+    public LiveCreateCategoryResponse createCategory(String categoryname) {
+        LiveCreateCategoryRequest liveCreateCategoryRequest = new LiveCreateCategoryRequest();
+        LiveCreateCategoryResponse liveCreateCategoryResponse;
+        try {
+            liveCreateCategoryRequest.setCategoryName(categoryname);
+            liveCreateCategoryResponse = new LiveAccountServiceImpl().createCategory(liveCreateCategoryRequest);
+            Assert.assertNotNull(liveCreateCategoryResponse);
+            return liveCreateCategoryResponse;
+        } catch (PloyvSdkException | IOException | NoSuchAlgorithmException e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    /**
+     * 获取直播分类列表
+     *
+     * @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();
+        }
+        return new ArrayList<>();
+    }
+}