LiveQing云端流媒体服务软件,支持视频视频转码、RTMP推流直播、RTMP/HLS/HTTP-FLV直播分发、服务端录像、录像检索、时移回放;支持与LiveGBS对接,即将支持内网数据穿透及远程服务配置。
注:路径中不能包含中文
二次开发中,方式是在自己业务系统后端登录接口中,调用流媒体的登录接口,获取所需的sid或是token
在业务使用,如果只是使用EasyDSS提供视频分发能力,且不会对外公开接口端口10080(默认端口),可以直接将接口鉴权关闭,具体服务器登录 http://localhost:10080 默认用户名/密码 admin/admin, 在 基础配置 页面,【接口鉴权】开关。
注: HttpOnly = true 客户端API(例如JavaScript)无法访问仅限http的cookie。 此限制通过跨站点脚本(XSS)消除了cookie被盗的威胁。
import java.io.DataOutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class GetLoginSid {
public static void main(String[] args) throws Exception {
URL url = new URL("http://demo.easydss.com:10080/login");
//发起POST请求,并传递username,password参数(需要md5加密)
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
DataOutputStream out = new DataOutputStream(conn.getOutputStream());
String content = "username=admin&password=21232f297a57a5a743894a0e4a801fc3";
out.writeBytes(content);
out.flush();
out.close();
Map> headerFields = conn.getHeaderFields();
Set headerFieldsSet = headerFields.keySet();
Iterator hearerFieldsIter = headerFieldsSet.iterator();
while (hearerFieldsIter.hasNext()) {
String headerFieldKey = hearerFieldsIter.next();
if ("Set-Cookie".equalsIgnoreCase(headerFieldKey)) {
List headerFieldValue = headerFields.get(headerFieldKey);
for (String headerValue : headerFieldValue) {
String[] fields = headerValue.split(";\\s*");
for (int j = 0; j < fields.length; j++) {
if (fields[j].indexOf('=') > 0) {
String[] f = fields[j].split("=");
if ("Expires".equalsIgnoreCase(f[0])) {
System.out.println("Expires:" + f[1]);
}
else if ("Max-Age".equalsIgnoreCase(f[0])) {
System.out.println("Max-Age:" + f[1]);
}else if ("sid".equalsIgnoreCase(f[0])) { //获取sid
System.out.println("sid:" + f[1]);
}
}
}
}
}
}
}
}
运行如下
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class RequestOtherAPI {
public static void main(String[] args) throws Exception {
URL url = new URL("http://demo.easydss.com:10080/live/list");
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
//这里传递上一步获得sid
conn.setRequestProperty("Cookie","sid=s%3Ark-TEuVtm.WnWoXuDY%2FldJuEc64I6TXjd0Fq1eqByEd4ng1UwNb2I;");
DataOutputStream out = new DataOutputStream(conn.getOutputStream());
String content = "start=0&limit=10";
out.writeBytes(content);
out.flush();
out.close();
conn.connect();
StringBuffer sbf = new StringBuffer();
InputStream is = conn.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
String strRead = null;
while ((strRead = reader.readLine()) != null) {
sbf.append(strRead);
sbf.append("\r\n");
}
reader.close();
System.out.println(sbf.toString());
}
}
运行如下
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class GetLoginToken {
public static void main(String[] args) throws Exception {
URL url = new URL("http://localhost:10080/login");
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
DataOutputStream out = new DataOutputStream(conn.getOutputStream());
String content = "username=admin&password=21232f297a57a5a743894a0e4a801fc3";
out.writeBytes(content);
out.flush();
out.close();
conn.connect();
StringBuffer sbf = new StringBuffer();
InputStream is = conn.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
String strRead = null;
while ((strRead = reader.readLine()) != null) {
sbf.append(strRead);
sbf.append("\r\n");
}
reader.close();
System.out.println(sbf.toString());
}
}
运行如下
其他接口调用时,附加token入参
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class RequestOtherAPIByToken {
public static void main(String[] args) throws Exception {
URL url = new URL("http://localhost:10080/live/list");
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
DataOutputStream out = new DataOutputStream(conn.getOutputStream());
String content = "start=0&limit=10&token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1Mzc3NzExNTAsInB3IjoiMjEyMzJmMjk3YTU3YTVhNzQzODk0YTBlNGE4MDFmYzMiLCJ0bSI6MTUzNzY4NDc1MCwidW4iOiJhZG1pbiJ9.b1U-R-_HVKV9reWRD50327B1ztUqs3gowUGi_lDzlmU";
out.writeBytes(content);
out.flush();
out.close();
conn.connect();
StringBuffer sbf = new StringBuffer();
InputStream is = conn.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
String strRead = null;
while ((strRead = reader.readLine()) != null) {
sbf.append(strRead);
sbf.append("\r\n");
}
reader.close();
System.out.println(sbf.toString());
}
}
运行如下
安防流媒体互联直播-QQ交流群:615081503
国标GB28181无插件LiveGBS-QQ交流群:947137753
WEB:www.liveqing.com
Copyright © LiveQing.com 2016-2019