<?php
/**
* Notes: 视频点播
* User : zzy
* Date : 2019/10/31
* Time : 8:52
*/
defined('BASEPATH') OR exit('No direct script access allowed');
require_once APPPATH.'/vendor/aliyuncs/aliyun-php-sdk/aliyun-php-sdk-core/Config.php';
require_once APPPATH."/vendor/aliyuncs/oss-sdk-php/autoload.php";
use vod\Request\V20170321 as vod;
use OSS\OssClient;
use OSS\Core\OssException;
class AliyunDemand{
private $accessKeyId = '';
private $accessKeySecret = '';
private $callback = '';
private $connection;
/**
* 构造函数初始化配置
*/
public function __construct()
{
$CI = &get_instance();
$CI->config->load('aliyundemand',TRUE);
$config = $CI->config->item('demand','aliyundemand');
$this->accessKeyId = $config['accessKeyId'];
$this->accessKeySecret = $config['accessKeySecret'];
$this->callback = $config['callback'];
$this->connection = $this->initVodClient($this->accessKeyId,$this->accessKeySecret);
}
/**
* Notes: 初始化点播服务
* User: zzy
* Date: 2019/10/31
* Time: 8:56
* Version:
* @param $accessKeyId
* @param $accessKeySecret
* @return DefaultAcsClient
*/
private function initVodClient($accessKeyId, $accessKeySecret) {
$regionId = 'cn-shanghai'; // 点播服务接入区域
$profile = DefaultProfile::getProfile($regionId, $accessKeyId, $accessKeySecret);
return new DefaultAcsClient($profile);
}
/**
* Notes:刷新上传凭证
* User: zzy
* Date: 2019/10/31
* Time: 15:25
* Version:
* @param $vodClient
* @param $videoId
* @return mixed|SimpleXMLElement
* @throws ClientException
* @throws ServerException
*/
public function refresh_upload_video($vodClient, $videoId) {
$request = new vod\RefreshUploadVideoRequest();
$request->setVideoId($videoId);
return $this->connection->getAcsResponse($request);
}
/**
* Notes: 初始化点播oss
* User: zzy
* Date: 2019/10/31
* Time: 18:34
* Version:
* @param $uploadAuth
* @param $uploadAddress
* @return OssClient
* @throws OssException
*/
public function init_oss_client($uploadAuth, $uploadAddress) {
$ossClient = new OssClient($uploadAuth['AccessKeyId'], $uploadAuth['AccessKeySecret'], $uploadAddress['Endpoint'],
false, $uploadAuth['SecurityToken']);
$ossClient->setTimeout(86400*7); // 设置请求超时时间,单位秒,默认是5184000秒, 建议不要设置太小,如果上传文件很大,消耗的时间会比较长
$ossClient->setConnectTimeout(10); // 设置连接超时时间,单位秒,默认是10秒
return $ossClient;
}
/**
* Notes:大文件分片上传,支持断点续传;最大支持48.8TB
* User: zzy
* Date: 2019/10/31
* Time: 15:28
* Version:
* @param $ossClient
* @param $uploadAddress
* @param $localFile
* @return mixed
*/
public function multipart_upload_file($ossClient, $uploadAddress, $localFile) {
return $ossClie
阿里云视频点播实例旧版
最新推荐文章于 2022-06-21 13:14:02 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)