全部
常见问题
产品动态
精选推荐
功能建议

分析中 已回复 待规划 {{opt.name}}
分析中 已回复 待规划
知识付费开源版本直播地址处理

管理 管理 编辑 删除

问题说明:知识付费开源版本直播地址没有自动适配

修改文件:extend/Api/AliyunLive.php

修改方法:getPullSteam()

public function getPullSteam($site_url, $streamName, $vhost = '', $time = 1800, $type = 'm3u8')
    {
        $time = time() + $time;
        $vhost = $vhost ? $vhost : $this->playLike;
        $appName = $this->appName;
        $privateKey = $this->payKey;
        if ($site_url) {
            $arr = parse_url($site_url);
            if ($arr['scheme']) {
                $scheme = $arr['scheme'];
            } else {
                $scheme = 'http';
            }
        } else {
            $scheme = 'http';
        }
        $url = '';
        switch ($type) {
            case 'rtmp':
                $host = 'rtmp://' . $vhost;
                $url = "/{$appName}/{$streamName}";
                break;
            case 'flv':
                $host = $scheme.'://' . $vhost;
                $url = "/{$appName}/{$streamName}.flv";
                break;
            case 'm3u8':
                $host = $scheme.'://' . $vhost;
                $url = "/{$appName}/{$streamName}.m3u8";
                break;
        }
        if ($privateKey) {
            $auth_key = md5($url . '-' . $time . '-0-0-' . $privateKey);
            $url = $host . $url . "?auth_key={$time}-0-0-{$auth_key}";
        } else {
            $url = $host . $url;
        }
        return $url;
    }

修改文件:application/wap/controller/Live.php

修改方法:index()

public function index($stream_name = '', $special_id = 0, $live_id = 0, $record_id = 0)
    {

        if ($special_id && $special_id != 0 && $live_id && $live_id != 0) {
            $special_task = SpecialTask::where(['special_id' => $special_id, 'live_id' => $live_id])->value('live_id');
            if (!$special_task) {
                $this->failed('直播间不存在', Url::build('index/index'));
            }
            $stream_name = LiveStudio::where('id', $live_id)->value('stream_name');
        }
        if (!$stream_name) return $this->failed('缺少在直播间号!', Url::build('index/index'));
        $liveInfo = LiveStudio::where('stream_name', $stream_name)->find();
        if (!$liveInfo) return $this->failed('直播间不存在', Url::build('index/index'));
        if ($liveInfo->is_del) return $this->failed('直播间已被删除', Url::build('index/index'));
        $userInfo = LiveUser::setLiveUser($this->uid, $liveInfo->id);
        if ($userInfo === false) return $this->failed(LiveUser::getErrorInfo('用户写入不成功'), Url::build('index/index'));
        $specialLive = Special::where(['is_show' => 1, 'is_del' => 0, 'id' => $liveInfo->special_id])->find();
        if (!$specialLive) return $this->failed('专题不存在或者已被删除', Url::build('index/index'));
        $user_level = !$this->uid ? 0 : User::where('uid', $this->uid)->find();
        if ($specialLive->pay_type == 1 && !SpecialBuy::PaySpecial($specialLive->id, $this->uid)) {
            if ($specialLive->member_pay_type == 1 || ($user_level['level'] <= 0 && $specialLive->member_pay_type == 0)) {
                return $this->failed('您还没有支付请支付后再进行观看', Url::build('special/details', ['id' => $liveInfo->special_id]));
            }
        }
        if ($specialLive->pay_type == 2) {
            $cookie_value = Cookie::get($stream_name . "studio_pwd");
            if (!$cookie_value || $cookie_value != $liveInfo['studio_pwd']) {
                return $this->failed('您需要先获得密码后再进行观看', Url::build('special/details', ['id' => $liveInfo->special_id]));
            }
        }
        $AliyunLive = $this->aliyunLive;
        if ($liveInfo->is_play){
            $site_url = SystemConfigService::get('site_url');
            $PullUrl = $AliyunLive->getPullSteam($site_url, $liveInfo->stream_name);
        } else {
            $record_id = $record_id ? $record_id : $liveInfo->playback_record_id;
            if ($liveInfo->is_playback && $record_id) {
                $livePlayBack = LivePlayback::where(['RecordId' => $record_id, 'stream_name' => $liveInfo->stream_name])->find();
                $PullUrl = $livePlayBack ? $livePlayBack->playback_url : false;
            } else
                $PullUrl = false;
        }
        $live_status = 0;
        $datatime = strtotime($liveInfo->start_play_time);
        $endTime = strtotime($liveInfo->stop_play_time);
        if ($datatime < time() && $endTime > time())
            $live_status = 1;//正在直播
        else if ($datatime < time() && $endTime < time())
            $live_status = 2;//直播结束
        else if ($datatime > time())
            $live_status = 0;//尚未直播
        $user_type = LiveHonouredGuest::where(['uid' => $this->uid, 'live_id' => $liveInfo->id])->value('type');
        if (is_null($user_type)) $user_type = 2;
        $uids = LiveHonouredGuest::where(['live_id' => $liveInfo->id])->column('uid');
        $liveInfo['abstract'] = $specialLive->abstract;
        $this->assign([
            'goldInfo' => json_encode(SystemConfigService::more("gold_name,gold_rate,gold_image")),
            'liveInfo' => json_encode($liveInfo),
            'UserSum' => bcadd(LiveUser::where(['live_id' => $liveInfo->id, 'is_open_ben' => 0, 'is_online' => 1])->sum('visit_num'), $liveInfo->online_num, 0),
            'live_title' => $liveInfo->live_title,
            'PullUrl' => $PullUrl,
            //'requirejs' => true,
            'is_ban' => $userInfo->is_ban,
            'room' => $liveInfo->id,
            'datatime' => $datatime,
            'workerman' => json_encode(Config::get('workerman.chat', [])),
            'phone_type' => UtilService::getDeviceType(),
            'live_status' => $live_status,
            'user_type' => $user_type,
            'OpenCommentCount' => LiveBarrage::where(['live_id' => $liveInfo->id, 'is_show' => 1])->count(),
            'OpenCommentTime' => LiveBarrage::where(['live_id' => $liveInfo->id, 'is_show' => 1])->order('add_time asc')->value('add_time'),
            'CommentCount' => LiveBarrage::where(['live_id' => $liveInfo->id, 'is_show' => 1])->where('uid', 'in', $uids)->count(),
            'CommentTime' => LiveBarrage::where(['live_id' => $liveInfo->id, 'is_show' => 1])->where('uid', 'in', $uids)->order('add_time asc')->value('add_time'),
        ]);
        return $this->fetch();
    }


修改文件:application/admin/model/live/LiveStudio.php

修改方法:setLivePalyStatus()

public static function setLivePalyStatus($StreamName, $is_play, $action)
    {
        $liveInfo = self::where('stream_name', $StreamName)->find();
        if (!$liveInfo) return self::setErrorInfo('暂未查到直播间');
        live_log('log', ['title'=>'开始','liveInfo'=>$liveInfo->toArray(),'streamName'=>$StreamName,'is_play'=>$is_play]);
        if ($liveInfo->is_play == 1 && $action == 'publish') {
            return true;
        } else if ($liveInfo->is_play == 0 && $action == 'publish_done') {
            return true;
        }
        $liveInfo->is_play = $is_play;
        try {
            $aliyunLive = \Api\AliyunLive::instance([
                'AccessKey' => SystemConfigService::get('accessKeyId'),
                'AccessKeySecret' => SystemConfigService::get('accessKeySecret'),
                'OssEndpoint' => SystemConfigService::get('aliyun_live_end_point'),
                'OssBucket' => SystemConfigService::get('aliyun_live_oss_bucket'),
                'appName' => SystemConfigService::get('aliyun_live_appName'),
                'payKey' => SystemConfigService::get('aliyun_live_play_key'),
                'key' => SystemConfigService::get('aliyun_live_push_key'),
                'playLike' => SystemConfigService::get('aliyun_live_playLike'),
                'rtmpLink' => SystemConfigService::get('aliyun_live_rtmpLink'),
            ]);
            if ($liveInfo->is_play) {
                //开启自动录制,进行手开启动录制直播间
                if ($liveInfo->is_recording) {
                    $res = $aliyunLive->liveRecording($liveInfo->stream_name)->executeResponse();
                    live_log('log', ['title'=>'直播录制开启','res'=>$res,'error'=>$aliyunLive->getErrorInfo()]);
                    if ($res) $liveInfo->recording = 1;
                }
                //向所有在线用户广播直播地址
                $workerman = \think\Config::get('workerman.channel', []);
                Gateway::$registerAddress = $workerman['ip'] . ':' . $workerman['port'];
                if (Gateway::getClientIdCountByGroup($liveInfo->id)) {
                    $site_url = SystemConfigService::get('site_url');
                    Gateway::sendToGroup($liveInfo->id, json_encode([
                        'type' => 'live_ing',
                        'pull_url' => $aliyunLive->getPullSteam($site_url, $liveInfo->stream_name),
                    ]));
                }
            } else {
                //开启自动录制,进行手动停止录制直播间
                if ($liveInfo->recording) {
                    $res = $aliyunLive->liveRecording($liveInfo->stream_name, false)->executeResponse();
                    live_log('log', ['title'=>'直播录制关闭','res'=>$res,'error'=>$aliyunLive->getErrorInfo()]);
                    $liveInfo->recording = 0;
                }
                //向所有在线用户广播直播地址
                $workerman = \think\Config::get('workerman.channel', []);
                Gateway::$registerAddress = $workerman['ip'] . ':' . $workerman['port'];
                if (Gateway::getClientIdCountByGroup($liveInfo->id)) {
                    Gateway::sendToGroup($liveInfo->id, json_encode([
                        'type' => 'live_end',
                        'pull_url' => false,
                    ]));
                }
            }
        } catch (\Exception $e) {
            live_log('error', ['code' => $e->getCode(), 'line' => $e->getLine(), 'msg' => $e->getMessage()]);
            if ($liveInfo->recording) $liveInfo->recording = 0;
            self::setErrorInfo($e->getMessage());
        }
        return $liveInfo->save();
    }


{{voteData.voteSum}} 人已参与
支持
反对
请登录后查看

全 最后编辑于2025-11-24 11:28:31

快捷回复
回复
回复
回复({{post_count}}) {{!is_user ? '我的回复' :'全部回复'}}
排序 默认正序 回复倒序 点赞倒序

{{item.user_info.nickname ? item.user_info.nickname : item.user_name}} LV.{{ item.user_info.bbs_level || item.bbs_level }}

作者 管理员 企业

{{item.floor}}# 同步到gitee 已同步到gitee {{item.is_suggest == 1? '取消推荐': '推荐'}}
{{item.is_suggest == 1? '取消推荐': '推荐'}} 【已收集】
{{item.floor}}# 沙发 板凳 地板 {{item.floor}}# 【已收集】
{{item.user_info.title || '暂无简介'}}
附件

{{itemf.name}}

{{item.created_at}}  {{item.ip_address}}
打赏
已打赏¥{{item.reward_price}}
{{item.like_count}}
分享
{{item.showReply ? '取消回复' : '回复'}}
删除
回复
回复

{{itemc.user_info.nickname}}

{{itemc.user_name}}

回复 {{itemc.comment_user_info.nickname}}

附件

{{itemf.name}}

{{itemc.created_at}}
打赏
已打赏¥{{itemc.reward_price}}
{{itemc.like_count}}
{{itemc.showReply ? '取消回复' : '回复'}}
删除
回复
回复
收起 展开更多
查看更多
打赏
已打赏¥{{reward_price}}
76
{{like_count}}
{{collect_count}}
添加回复 ({{post_count}})

相关推荐

快速安全登录

使用微信扫码登录
回复
回复
问题:
问题自动获取的帖子内容,不准确时需要手动修改. [获取答案]
答案:
提交
bug 需求 取 消 确 定
打赏金额
当前余额:¥{{rewardUserInfo.reward_price}}
{{item.price}}元
请输入 0.1-{{reward_max_price}} 范围内的数值
打赏成功
¥{{price}}
完成 确认打赏

微信登录/注册

切换手机号登录

{{ bind_phone ? '绑定手机' : '手机登录'}}

{{codeText}}
切换微信登录/注册
暂不绑定
CRMEB客服

CRMEB咨询热线 咨询热线

400-8888-794

微信扫码咨询

CRMEB开源商城下载 源码下载 CRMEB帮助文档 帮助文档
返回顶部 返回顶部
CRMEB客服