LiveQing流媒體服務器軟件,包含雲平臺服務,雲直播服務等,支持與LiveGBS的對接,支持設備RTMP推流,視頻文件轉碼等功能java
二次開發中,方式是在本身業務系統後端登陸接口中,調用流媒體的登陸接口,獲取所需的sid或是token後端
在業務使用,提供視頻分發能力時,且不會對外公開接口端口10080(默認端口),能夠直接將接口鑑權關閉,具體服務器登陸 http://localhost:10080 默認用戶名/密碼 admin/admin, 在 基礎配置 頁面,【接口鑑權】開關。服務器
注: HttpOnly = true 客戶端API(例如JavaScript)沒法訪問僅限http的cookie。 此限制經過跨站點腳本(XSS)消除了cookie被盜的威脅。cookie
在後端業務代碼中對接,如Java/PHP/Node.js 等app
調用LiveDSS登陸接口,接口調用成功後會在請求Headers的cookie中寫入sid加密
取出cookie裏的sidurl
其它接口調用時在請求頭cookies中傳遞sid.net
Content-Type:application/x-www-form-urlencoded3d
接口請求路徑示例:http://localhost:10080/logincode
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://dss.liveqing.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://dss.liveqing.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()); } }
運行以下
調用登陸接口獲取token,調用時傳遞 onlytoken=true
如: http://dss.liveqing.com:10080/login?username=admin&password=21232f29757a5a&onlytoken=true
Content-Type:application/x-www-form-urlencoded
其它接口調用時傳遞附加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 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()); } }
運行以下