EasyDSS流媒體服務器軟件,提供一站式的轉碼、點播、直播、時移回放服務,極大地簡化了開發和集成的工做。其中,點播版本主要包含:上傳、轉碼、分發。直播版本主要包含:直播、錄像,直播支持RTMP輸入,RTMP/HLS/HTTP-FLV的分發輸出;錄像支持自定義保存時長、檢索及下載;提供豐富的二次開發接口、基於JSON的封裝及HTTP調用;提供播放鑑權、推流鑑權等安全保證;提供用戶及相關權限管理配置。html
【官網】java
【點播版本在線演示】web
【旗艦版本在線演示】api
【在線接口】安全
這篇博文主要介紹如何利用軟件提供的接口快速接入開發。服務器
注:路徑中不能包含中文微信
二次開發中,方式是在本身業務系統後端登陸接口中,調用流媒體的登陸接口,獲取所需的sid或是tokencookie
在業務使用,若是隻是使用EasyDSS提供視頻分發能力,且不會對外公開接口端口10080(默認端口),能夠直接將接口鑑權關閉,具體服務器登陸 http://demo.easydss.com:10080/login.html 默認用戶名/密碼 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<String, List<String>> headerFields = conn.getHeaderFields(); Set<String> headerFieldsSet = headerFields.keySet(); Iterator<String> hearerFieldsIter = headerFieldsSet.iterator(); while (hearerFieldsIter.hasNext()) { String headerFieldKey = hearerFieldsIter.next(); if ("Set-Cookie".equalsIgnoreCase(headerFieldKey)) { List<String> 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()); } }
EasyDSS(http://www.easydss.com)流媒體解決方案採用業界優秀的流媒體框架模式設計,服務運行輕量、高效、穩定、可靠、易維護,支持RTMP直播、RTMP推送、HTTP點播、HTTP-FLV直播、HLS直播,並支持關鍵幀緩衝,畫面秒開等多種特性,可以接入Web、Android、iOS、H五、微信等全平臺客戶端,是移動互聯網時代貼近企業點播/直播需求的一款接地氣的流媒體服務器,配套OBS、EasyRTMP等直播推流工具以及EasyPlayer等網絡播放器,能夠造成一套完整的視頻直播、錄播解決方案,知足用戶在各類行業場景的流媒體業務需求。