php和腾讯直播的实现代码

来自:互联网
时间:2021-01-07
阅读:

戏说前文
不要想太多,直播和你(php)没啥关系、帮忙配置一下推拉流地址和License、然后生成一下推拉流地址详细链接就好了
但是,像是送礼物,弹幕自己写长连接或调用im。家族,充币等都是逻辑问题,这里就不说了
下面

第一步 配置推拉流地址

php和腾讯直播的实现代码

bizid

php和腾讯直播的实现代码

appkey

php和腾讯直播的实现代码

第二步:生成地址

php和腾讯直播的实现代码

像这样生成

if (!function_exists('create_live')) {

   function create_live($user_id = 0) {

    $live_bizid = Config::get("site.live_bizid");//直播bizid
    $live_sdkapp_id = Config::get("site.live_sdkapp_id");//直播sdkapp_id
    $push_domain = Config::get("site.push_domain");//推流域名
    $play_domain = Config::get("site.play_domain");//播放域名
    $live_key = Config::get("site.live_key");//直播key
    $live_expiry_time = Config::get("site.live_expiry_time");//直播过期时间
    

    $livecode = $live_sdkapp_id.'_'.$user_id;
    //默认名// 推荐用随机数字或者用户 ID
    if ($live_key && $live_expiry_time) {

      $time = time()+$live_expiry_time;
      //过期时间
      //strtoupper把所有字符转换为大写 base_convert把进制数转换:
      $txTime = strtoupper(base_convert($time,10,16));
      //加密
      $txSecret = md5($live_key.$livecode.$txTime);
      //StreamName(流 ID):推荐用随机数字或者用户 ID。
      //bizid 直播bizid
      //txTime(地址有效期):何时该 URL 会过期,格式支持十六进制的 UNIX 时间戳。
      //txSecret(防盗链签名):防止攻击者伪造您的后台生成推流 URL 
      $ext_str = '?'.http_build_query(array(
        "bizid" => $live_bizid,
        "txSecret" => $txSecret,
        "txTime" => $txTime
      ));
    }

    $url = [
      "push_url" => "rtmp://".$push_domain."/live/".$livecode.(isset($ext_str) ? $ext_str : ""),
      "rtmp_play_url" => "rtmp://".$play_domain."/live/".$livecode,
      "flv_play_url" => "http://".$play_domain."/live/$livecode.flv",
      "m3u8_play_url" => "http://".$play_domain."/live/$livecode.m3u8",
    ];
    return $url;
  }
}

给安卓ios配置许可证

php和腾讯直播的实现代码

返回顶部
顶部