Video.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace app\common\library;
  3. use AlibabaCloud\Client\AlibabaCloud;
  4. use AlibabaCloud\Vod\Vod;
  5. use AlibabaCloud\Client\Exception\ClientException;
  6. use AlibabaCloud\Client\Exception\ServerException;
  7. class Video
  8. {
  9. protected $accessKeyId = '';
  10. protected $accessKeySecret = '';
  11. public function __construct(){
  12. define("VOD_CLIENT_NAME", 'AliyunVodClientDemo');
  13. $config = config('vod');
  14. $this->accessKeyId = $config['accessKeyId'];
  15. $this->accessKeySecret = $config['accessKeySecret'];
  16. $this->initVodClient();
  17. }
  18. //初始化
  19. public function initVodClient() {
  20. $regionId = 'cn-beijing';
  21. //填入AccessKey信息
  22. AlibabaCloud::accessKeyClient($this->accessKeyId, $this->accessKeySecret)
  23. ->regionId($regionId)
  24. ->connectTimeout(1)
  25. ->timeout(3)
  26. ->name(VOD_CLIENT_NAME);
  27. }
  28. //GetPlayInfo
  29. public function getPlayInfo($videoId) {
  30. return Vod::v20170321()->getPlayInfo()->client(VOD_CLIENT_NAME)
  31. ->withVideoId($videoId) // 指定接口参数
  32. ->withAuthTimeout(3600*24)
  33. ->format('JSON') // 指定返回格式
  34. ->request(); // 执行请求
  35. }
  36. /**
  37. * @throws ClientException
  38. * @throws ServerException
  39. */
  40. public function getVideoPlayAuth($videoId) {
  41. return Vod::v20170321()->getVideoPlayAuth()->client(VOD_CLIENT_NAME)
  42. ->withVideoId($videoId) // 指定音/视频ID
  43. ->withAuthInfoTimeout(3600)
  44. ->format('JSON') // 指定返回格式
  45. ->request(); // 执行请求
  46. }
  47. }