因为离职,没有登录阿里账号查看,只在代码记录的一些

测试地址:https://player.alicdn.com/aliplayer/index.html

代码 工具类 LiveUtils

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;

public class LiveUtils {

    /**
     * 计算md5
     * @param param
     * @return
     */
    public static String md5(String param) {
        if(param == null || param.length() == 0) {
            return null;
        }
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            md5.update(param.getBytes());
            byte[] byteArray = md5.digest();

            BigInteger bigInt = new BigInteger(1, byteArray);
            // 参数16表示16进制
            String result = bigInt.toString(16);
            // 不足32位高位补零
            while(result.length() < 32) {
                result = "0" + result;
            }
            return result;
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 生成推流地址
     * @param pushDomain 推流域名
     * @param pushKey 推流域名配置的鉴权Key
     * @param appName 推流AppName
     * @param streamName 推流StreamName
     * @param expireTime 过期时间(单位是秒)
     */
    public static String generate_push_url(String pushDomain,String pushKey,String appName,String streamName,long expireTime) {
        String pushUrl = "";
        //推流域名未开启鉴权功能的情况下
        if(pushKey=="") {
            pushUrl = "rtmp://"+pushDomain+"/"+appName+"/"+streamName;
        }else {
            long timeStamp = System.currentTimeMillis()/1000L + expireTime;
            String stringToMd5 = "/"+appName+"/"+streamName+"-"+Long.toString(timeStamp)+"-0-0-"+pushKey;
            String authKey = md5(stringToMd5);
            pushUrl = "rtmp://"+pushDomain+"/"+appName+"/"+streamName+"?auth_key="+Long.toString(timeStamp)+"-0-0-"+authKey;
        }
        //System.out.println("推流地址是: "+pushUrl);
        return pushUrl;
    }

    /**
     * 生成播放地址
     * @param pullDomain 播放域名
     * @param pullKey 播放鉴权Key
     * @param appName 播放appName(同推流appName)
     * @param streamName 播放streamName (同推流streamName)
     * @param expireTime 过期时间(单位是秒
     */
    public static HashMap general_pull_url(String pullDomain, String pullKey, String appName, String streamName, long expireTime) {
        String rtmpUrl = ""; //rtmp的拉流地址
        String hlsUrl = "";  //m3u8的拉流地址
        String flvUrl = "";  //flv的拉流地址
        //播放域名未配置鉴权Key的情况下
        if(pullKey == "") {
            rtmpUrl = "rtmp://"+pullDomain+"/"+appName+"/"+streamName;
            hlsUrl = "http://"+pullDomain+"/"+appName+"/"+streamName+".m3u8";
            flvUrl = "http://"+pullDomain+"/"+appName+"/"+streamName+".flv";
        }else {
            long timeStamp = System.currentTimeMillis()/1000L + expireTime;
            String rtmpToMd5 = "/"+appName+"/"+streamName+"-"+Long.toString(timeStamp)+"-0-0-"+pullKey;
            String rtmpAuthKey = md5(rtmpToMd5);
            rtmpUrl = "rtmp://"+pullDomain+"/"+appName+"/"+streamName+"?auth_key="+Long.toString(timeStamp)+"-0-0-"+rtmpAuthKey;

            String hlsToMd5 = "/"+appName+"/"+streamName+".m3u8-"+Long.toString(timeStamp)+"-0-0-"+pullKey;
            String hlsAuthKey = md5(hlsToMd5);
            hlsUrl = "http://"+pullDomain+"/"+appName+"/"+streamName+".m3u8"+"?auth_key="+Long.toString(timeStamp)+"-0-0-"+hlsAuthKey;

            String flvToMd5 = "/"+appName+"/"+streamName+".flv-"+Long.toString(timeStamp)+"-0-0-"+pullKey;
            String flvAuthKey = md5(flvToMd5);
            flvUrl = "http://"+pullDomain+"/"+appName+"/"+streamName+".flv"+"?auth_key="+Long.toString(timeStamp)+"-0-0-"+flvAuthKey;
        }
        //System.out.println("RTMP播放地址为: "+rtmpUrl);
        //System.out.println("m3u8播放地址为: "+hlsUrl);
        //System.out.println("flv播放地址为: "+flvUrl);
        HashMap<String,String> map = new HashMap<>();
        map.put("RTMP",rtmpUrl);
        map.put("m3u8",hlsUrl);
        map.put("flv",flvUrl);
        return map;

    }

    public static HashMap GetPushAndPullUrl(String AppName, String StreamName, Long ExpireTime) {
        //直播最长时长
        long expireTime = 3600L;
        //播流域名
        String pullDomain = "live.governmentbuy.com";
        //播流鉴权
        String pullKey = "2020GovBuyZhiBo0413";
        //推流域名
        String pushDomain = "zhibo.governmentbuy.com";
        //推流鉴权
        String pushKey = "GovBuy2020ZhiBo";
        //调用方法生成播流地址
        HashMap hashMap = general_pull_url(pullDomain, pullKey, AppName, StreamName, expireTime);
        //调用方法生成推流地址
        String s = generate_push_url(pushDomain, pushKey, AppName, StreamName, expireTime);
        hashMap.put("tuiliu",s);
        return hashMap;
    }

    public static void main(String[] args) {
        //使用方法,所有流地址都在hashMap中 自己通过键值(flv、boliu、RTMP、m3u8) 获得值就行
        HashMap<String,String> hashMap = LiveUtils.GetPushAndPullUrl("a", "b", 3600l);
        for (String o : hashMap.keySet()) {
            System.out.println(o+":"+hashMap.get(o));
        }
    }
}
特殊说明:
上述文章均是作者实际操作后产出。烦请各位,请勿直接盗用!转载记得标注原文链接:www.zanglikun.com
第三方平台不会及时更新本文最新内容。如果发现本文资料不全,可访问本人的Java博客搜索:标题关键字。以获取最新全部资料 ❤