PHP code example of jimchen / aliyun-php-sdk-core
1. Go to this page and download the library: Download jimchen/aliyun-php-sdk-core library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
jimchen / aliyun-php-sdk-core example snippets
// 1. 初始化客户端
// 官方中需要`.php 中通过 composer 进行了自动加载
use JimChen\AliyunCore\DefaultAcsClient;
function init_vod_client($accessKeyId, $accessKeySecret) {
$regionId = 'cn-shanghai'; // 点播服务所在的Region,国内请填cn-shanghai,不要填写别的区域
$profile = DefaultProfile::getProfile($regionId, $accessKeyId, $accessKeySecret);
return new DefaultAcsClient($profile);
}
// 2. 获取视频上传地址和凭证
function create_upload_video($client) {
$request = new CreateUploadVideoRequest();
$request->setTitle("视频标题"); // 视频标题(必填参数)
$request->setFileName("文件名称.mov"); // 视频源文件名称,必须包含扩展名(必填参数)
$request->setDescription("视频描述"); // 视频源文件描述(可选)
$request->setCoverURL("http://img.alicdn.com/tps/TB1qnJ1PVXXXXXCXXXXXXXXXXXX-700-700.png"); // 自定义视频封面(可选)
$request->setTags("标签1,标签2"); // 视频标签,多个用逗号分隔(可选)
$request->setAcceptFormat('JSON');
return $client->getAcsResponse($request);
}
try {
$client = init_vod_client('<您的AccessKeyId>', '<您的AccessKeySecret>');
$uploadInfo = create_upload_video($client);
var_dump($uploadInfo);
} catch (Exception $e) {
print $e->getMessage()."\n";
}
// 3. 刷新视频上传凭证
function refresh_upload_video($client, $videoId) {
$request = new RefreshUploadVideoRequest();
$request->setVideoId($videoId);
$request->setAcceptFormat('JSON');
return $client->getAcsResponse($request);
}
try {
$client = init_vod_client('<您的AccessKeyId>', '<您的AccessKeySecret>');
$refreshInfo = refresh_upload_video($client, '您的videoId');
var_dump($refreshInfo);
} catch (Exception $e) {
print $e->getMessage()."\n";
}
// 4. 获取图片上传地址和凭证
function create_upload_image($client, $imageType, $imageExt) {
$request = new CreateUploadImageRequest();
$request->setImageType($imageType);
$request->setImageExt($imageExt);
$request->setAcceptFormat('JSON');
return $client->getAcsResponse($request);
}
try {
$client = init_vod_client('<您的AccessKeyId>', '<您的AccessKeySecret>');
$imageInfo = create_upload_image($client, 'cover', 'jpg');
var_dump($imageInfo);
} catch (Exception $e) {
print $e->getMessage()."\n";
}
shell
$ composer