阿里雲openapi接口使用,PHP,視頻直播


1.下載sdk放入項目文件夾中

核心就是aliyun-php-sdk-core,它的配置文件會自動加載相應的類

2.引入文件

include_once LIB_PATH . 'ORG/aliyun-openapi/aliyun-php-sdk-core/Config.php';

3.配置客戶端對象,需要Access Key ID,Access Key Secret

$iClientProfile = DefaultProfile::getProfile("cn-hangzhou", "xxxx", "xxxx");  // Access Key ID,Access Key Secret
$client = new DefaultAcsClient($iClientProfile);

4.調用請求類,並配置參數,就拿直播推流歷史為例

$request = new live\Request\V20161101\DescribeLiveStreamsPublishListRequest();
$request ->setDomainName('live.yunlutong.com');
$request ->setAppName('yunlutong');
$request ->setStreamName('demo');
$request ->setStartTime('2017-03-01T19:00:00Z');
$request ->setEndTime('2017-03-29T19:00:00Z');

5.發起請求

//針對阿里雲進行請求
$response = $client->getAcsResponse($request);
exit(json_encode($response));

完整代碼如下

<?php

/**
 * 直播相關接口
 */
class LiveAction extends ApiAction
{
    protected function _initialize()
    {
        parent::_initialize();
    }

    // 獲取推流歷史
    public function DescribeLiveStreamsPublishList() {
        include_once LIB_PATH . 'ORG/aliyun-openapi/aliyun-php-sdk-core/Config.php';

        $iClientProfile = DefaultProfile::getProfile("cn-hangzhou", "xxxx", "xxxx");  // Access Key ID,Access Key Secret
        $client = new DefaultAcsClient($iClientProfile);

        $request = new live\Request\V20161101\DescribeLiveStreamsPublishListRequest();
        $request ->setDomainName('live.yunlutong.com');
        $request ->setAppName('yunlutong');
        $request ->setStreamName('demo');
        $request ->setStartTime('2017-03-01T19:00:00Z');
        $request ->setEndTime('2017-03-29T19:00:00Z');

        //針對阿里雲進行請求
        $response = $client->getAcsResponse($request);
        exit(json_encode($response));
    }

}

獲取數據如下

其他的接口數據,類似。

這是官方的接口調用文檔,


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM