1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- <?php
- namespace app\api\controller;
- require __DIR__ . '/vendor/autoload.php';
- require_once __DIR__ .'/aliyunmail/aliyun-php-sdk-core/Config.php'; // 假定您的源码文件和aliyun-php-sdk处于同一目录
- use AlibabaCloud\Client\AlibabaCloud;
- use AlibabaCloud\Vod\Vod;
- use AlibabaCloud\Client\Exception\ClientException;
- use AlibabaCloud\Client\Exception\ServerException;
- use AlibabaCloud\Vod\V20170321;
- define("VOD_CLIENT_NAME", 'AliyunVodClientDemo');
- class VideoHls extends Base
- {
- function initVodClient($accessKeyId, $accessKeySecret) {
- $regionId = 'cn-shanghai';
- AlibabaCloud::accessKeyClient($accessKeyId, $accessKeySecret)
- ->regionId($regionId)
- ->connectTimeout(1)
- ->timeout(3)
- ->name(VOD_CLIENT_NAME);
- }
- function initStsClient($accessKeyId, $accessKeySecret, $securityToken) {
- $regionId = 'cn-shanghai';
- //填入STS信息
- AlibabaCloud::stsClient($accessKeyId, $accessKeySecret, $securityToken)
- ->regionId($regionId)
- ->connectTimeout(1)
- ->timeout(3)
- ->name(VOD_CLIENT_NAME);
- }
- function getPlayInfo($videoId) {
- return Vod::v20170321()->getPlayInfo()->client(VOD_CLIENT_NAME)
- ->withVideoId($videoId) // 指定接口参数
- ->withAuthTimeout(3600*24)
- ->format('JSON') // 指定返回格式
- ->request(); // 执行请求
- }
- function index()
- {
- try {
- $this->initVodClient('<AccessKeyId>', '<AccessKeySecret>');
- $playInfo =$this->getPlayInfo('<MediaId>');
- print_r($playInfo->PlayInfoList->PlayInfo);
- print_r(VOD_CLIENT_NAME);
- } catch (\Exception $e) {
- print $e->getMessage()."\n";
- }
- }
- /**
- * 获取音/视频上传地址和凭证
- * @param client 发送请求客户端
- * @return CreateUploadVideoResponse 获取音/视频上传地址和凭证响应数据
- */
- function createUploadVideo($client) {
- $request = new V20170321\CreateUploadVideoRequest();
- $request->setTitle("Sample Title");
- $request->setFileName("videoFile.mov");
- $request->setDescription("Video Description");
- $request->setCoverURL("http://192.168.0.0/16/tps/TB1qnJ1PVXXXXXCXXXXXXXXXXXX-700-700.png");
- $request->setTags("tag1,tag2");
- $request->setAcceptFormat('JSON');
- return $client->getAcsResponse($request);
- }
- }
|