VideoHls.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace app\api\controller;
  3. require __DIR__ . '/vendor/autoload.php';
  4. require_once __DIR__ .'/aliyunmail/aliyun-php-sdk-core/Config.php'; // 假定您的源码文件和aliyun-php-sdk处于同一目录
  5. use AlibabaCloud\Client\AlibabaCloud;
  6. use AlibabaCloud\Vod\Vod;
  7. use AlibabaCloud\Client\Exception\ClientException;
  8. use AlibabaCloud\Client\Exception\ServerException;
  9. use AlibabaCloud\Vod\V20170321;
  10. define("VOD_CLIENT_NAME", 'AliyunVodClientDemo');
  11. class VideoHls extends Base
  12. {
  13. function initVodClient($accessKeyId, $accessKeySecret) {
  14. $regionId = 'cn-shanghai';
  15. AlibabaCloud::accessKeyClient($accessKeyId, $accessKeySecret)
  16. ->regionId($regionId)
  17. ->connectTimeout(1)
  18. ->timeout(3)
  19. ->name(VOD_CLIENT_NAME);
  20. }
  21. function initStsClient($accessKeyId, $accessKeySecret, $securityToken) {
  22. $regionId = 'cn-shanghai';
  23. //填入STS信息
  24. AlibabaCloud::stsClient($accessKeyId, $accessKeySecret, $securityToken)
  25. ->regionId($regionId)
  26. ->connectTimeout(1)
  27. ->timeout(3)
  28. ->name(VOD_CLIENT_NAME);
  29. }
  30. function getPlayInfo($videoId) {
  31. return Vod::v20170321()->getPlayInfo()->client(VOD_CLIENT_NAME)
  32. ->withVideoId($videoId) // 指定接口参数
  33. ->withAuthTimeout(3600*24)
  34. ->format('JSON') // 指定返回格式
  35. ->request(); // 执行请求
  36. }
  37. function index()
  38. {
  39. try {
  40. $this->initVodClient('<AccessKeyId>', '<AccessKeySecret>');
  41. $playInfo =$this->getPlayInfo('<MediaId>');
  42. print_r($playInfo->PlayInfoList->PlayInfo);
  43. print_r(VOD_CLIENT_NAME);
  44. } catch (\Exception $e) {
  45. print $e->getMessage()."\n";
  46. }
  47. }
  48. /**
  49. * 获取音/视频上传地址和凭证
  50. * @param client 发送请求客户端
  51. * @return CreateUploadVideoResponse 获取音/视频上传地址和凭证响应数据
  52. */
  53. function createUploadVideo($client) {
  54. $request = new V20170321\CreateUploadVideoRequest();
  55. $request->setTitle("Sample Title");
  56. $request->setFileName("videoFile.mov");
  57. $request->setDescription("Video Description");
  58. $request->setCoverURL("http://192.168.0.0/16/tps/TB1qnJ1PVXXXXXCXXXXXXXXXXXX-700-700.png");
  59. $request->setTags("tag1,tag2");
  60. $request->setAcceptFormat('JSON');
  61. return $client->getAcsResponse($request);
  62. }
  63. }