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));}}
獲取數據如下
其他的接口數據,類似。
這是官方的接口調用文檔,
本文轉自TBHacker博客園博客,原文鏈接:http://www.cnblogs.com/jiqing9006/p/6599492.html,如需轉載請自行聯系原作者