VODWorker.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using Aliyun.Acs.Core;
  2. using Aliyun.Acs.Core.Exceptions;
  3. using Aliyun.Acs.Core.Profile;
  4. using Aliyun.Acs.vod.Model.V20170321;
  5. using CZFW.Core;
  6. using CZFW.Framework.Model;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Text;
  10. namespace CZFW.Framework.VOD
  11. {
  12. public class VODWorker
  13. {
  14. /// <summary>
  15. /// 获取播放权限
  16. /// </summary>
  17. /// <param name="videoId"></param>
  18. /// <returns></returns>
  19. public static string GetPlayAuthStr(string videoId)
  20. {
  21. if (string.IsNullOrWhiteSpace(videoId))
  22. {
  23. return videoId;
  24. }
  25. var video = GetPlayAuth(videoId);
  26. if (video == null)
  27. {
  28. return "";
  29. }
  30. return video.PlayAuth;
  31. }
  32. private static IClientProfile getProfile()
  33. {
  34. var region = ConfigHelper.GetValue<string>("AliyunVOD:AliVODRegion");
  35. var key = ConfigHelper.GetValue<string>("AliyunVOD:AccessKeyId");
  36. var secret = ConfigHelper.GetValue<string>("AliyunVOD:AccessKeySecret");
  37. IClientProfile clientProfile = DefaultProfile.GetProfile(region, key, secret);
  38. return clientProfile;
  39. }
  40. private static GetVideoPlayAuthResponse GetPlayAuth(string vid)
  41. {
  42. var clientProfile = getProfile();
  43. DefaultAcsClient client = new DefaultAcsClient(clientProfile);
  44. GetVideoPlayAuthRequest request = new GetVideoPlayAuthRequest();
  45. request.AcceptFormat = Aliyun.Acs.Core.Http.FormatType.JSON;
  46. request.VideoId = vid;
  47. try
  48. {
  49. GetVideoPlayAuthResponse response = client.GetAcsResponse(request);
  50. return response;
  51. }
  52. catch (ServerException e)
  53. {
  54. Console.WriteLine(e.ErrorCode);
  55. Console.WriteLine(e.ErrorMessage);
  56. }
  57. catch (ClientException e)
  58. {
  59. Console.WriteLine(e.ErrorCode);
  60. Console.WriteLine(e.ErrorMessage);
  61. }
  62. return null;
  63. }
  64. }
  65. }