日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問(wèn)題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
php怎么實(shí)現(xiàn)在線直播功能

本文操作環(huán)境:Windows7系統(tǒng),php7.1版,Dell G3電腦。

在富寧等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場(chǎng)前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供成都網(wǎng)站制作、成都網(wǎng)站設(shè)計(jì) 網(wǎng)站設(shè)計(jì)制作定制網(wǎng)站開發(fā),公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),品牌網(wǎng)站設(shè)計(jì),全網(wǎng)整合營(yíng)銷推廣,外貿(mào)網(wǎng)站建設(shè),富寧網(wǎng)站建設(shè)費(fèi)用合理。

php怎么實(shí)現(xiàn)在線直播功能?

php 七牛云實(shí)現(xiàn)直播功能:

一:最近在做一個(gè)直播賣貨的項(xiàng)目,后臺(tái)搭建好了準(zhǔn)備接入直播,搜了幾家阿里,TX和七牛,結(jié)果阿里的直播php只有代碼沒(méi)有文檔,TX的我朋友說(shuō)代碼比較亂就不考慮了,上了七牛注冊(cè)了一個(gè)賬戶,申請(qǐng)直播空間的時(shí)候被域名卡主了,已經(jīng)備案的域名還要再網(wǎng)站公安備案一次

https://developer.qiniu.com/af/kb/3987/how-to-make-website-and-inquires-the-police-put-on-record-information?ref=support.qiniu.com

又搜了搜發(fā)現(xiàn)涉及網(wǎng)絡(luò)表演業(yè)務(wù)的,需辦理《網(wǎng)絡(luò)文化經(jīng)營(yíng)許可證》,請(qǐng)咨詢當(dāng)?shù)厝嗣裾幕姓块T,等待申請(qǐng)完以后在進(jìn)行下一步。

二:域名備案終于好了,開始搞第二步,實(shí)現(xiàn)直播功能,移動(dòng)端可以參考七牛云SDK,下面是服務(wù)端推流案例,本次使用的是rtmp流實(shí)現(xiàn)直播,在控制臺(tái)找到直播云服務(wù),創(chuàng)建直播云空間

創(chuàng)建好直播空間后會(huì)生成幾個(gè)二級(jí)域名,按需要將域名解析出來(lái),然后就到了下面的樣子

代碼運(yùn)行起來(lái)后會(huì)在直播流中看到你說(shuō)創(chuàng)建的直播流播放歷史等信息

安裝composer包

php composer.phar require qiniu/php-sdk

再vendor/pili-engineering/pili-sdk-php.v2里能找到兩個(gè)案例,一個(gè)是直播的,一個(gè)是連麥的,這次先實(shí)現(xiàn)直播,下一篇再更新一下連麥

accessKey = config("qiniu.accessKey");
        $this->secretKey = config("qiniu.secretKey");
        $this->hubName = config("qiniu.bucket");
        parent::__construct();
    }
    /**
     *開啟直播
     */
    public function liveStart(Request $request)
    {
        $userInfo = parent::getAuthenticatedUser($msg);
        if (isset($userInfo['user']) && !empty($userInfo['user'])) {
            $request->offsetSet('user_id', $userInfo['user']['id']);
        } else {
            return $this->sendResponse($msg, 'error', '', 401);
        }
        $data = $request->all();
        $broadcast = app(BroadcastRepositoryEloquent::class)->findWhere(['type' => $data['type'], 'user_id' => $data['user_id']])->first();
        if (empty($broadcast)) {
            return $this->sendResponse(trans('admin.operate_failed') . '未找到直播間');
        }
        $broadcast['name'] = $data['name'];
        //創(chuàng)建hub
        $mac = new Mac($this->accessKey, $this->secretKey);
        $client = new Client($mac);
        $hub = $client->hub($this->hubName);
        //獲取stream
        $streamKey = $broadcast['show_id'];
        $stream = $hub->stream($streamKey);
        $list = $hub->listStreams($streamKey, 1, "");
        //如果沒(méi)找到對(duì)應(yīng)的直播流創(chuàng)建新直播流
        if (count($list['keys']) == 0) {
            //獲取stream
            $hub->create($streamKey);
        }
        if ($data['type'] == 0) {
            $result = $this->updateShop($broadcast, $streamKey, $msg);
            if ($result == false) {
                return $this->sendResponse(trans('admin.operate_failed') . $msg);
            }
        } else {
            $result = $this->updateCurriculum($broadcast, $streamKey, $msg);
            if ($result == false) {
                return $this->sendResponse(trans('admin.operate_failed') . $msg);
            }
        }
        return $this->sendResponse(trans('admin.operate_succeeded'), 'succ', ['p_href' => $broadcast['p_href']]);
    }

    //更新商城直播間
    public function updateShop($broadcast, $streamKey, &$msg = '')
    {
        //獲取推流地址
        $p_href = RTMPPublishURL("pili-publish.chengdulihong.com", $this->hubName, $streamKey, 3600, $this->accessKey, $this->secretKey);
        //獲取播放地址
        $g_href = RTMPPlayURL("pili-publish.chengdulihong.com", $this->hubName, $streamKey);
        //截圖直播地址
        $pic = SnapshotPlayURL("pili-publish.chengdulihong.com", $this->hubName, $streamKey);
        //更新直播間狀態(tài)
        $u_broadcast = $broadcast->fill(['name' => $broadcast['name'], 'chatroom_status' => 0, 'p_href' => $p_href, 'g_href' => $g_href, 'pic' => $pic])->save();
        if ($u_broadcast == false) {
            return $this->sendResponse(trans('admin.operate_failed') . '更新直播間出錯(cuò)');
        }
        return true;
    }


新聞標(biāo)題:php怎么實(shí)現(xiàn)在線直播功能
網(wǎng)站URL:http://www.5511xx.com/article/dhjchoc.html