using Aliyun.Acs.Core; using Aliyun.Acs.Core.Exceptions; using Aliyun.Acs.Core.Profile; using Aliyun.Acs.vod.Model.V20170321; using CZFW.Core; using CZFW.Framework.Model; using System; using System.Collections.Generic; using System.Text; namespace CZFW.Framework.VOD { public class VODWorker { /// /// 获取播放权限 /// /// /// public static string GetPlayAuthStr(string videoId) { if (string.IsNullOrWhiteSpace(videoId)) { return videoId; } var video = GetPlayAuth(videoId); if (video == null) { return ""; } return video.PlayAuth; } private static IClientProfile getProfile() { var region = ConfigHelper.GetValue("AliyunVOD:AliVODRegion"); var key = ConfigHelper.GetValue("AliyunVOD:AccessKeyId"); var secret = ConfigHelper.GetValue("AliyunVOD:AccessKeySecret"); IClientProfile clientProfile = DefaultProfile.GetProfile(region, key, secret); return clientProfile; } private static GetVideoPlayAuthResponse GetPlayAuth(string vid) { var clientProfile = getProfile(); DefaultAcsClient client = new DefaultAcsClient(clientProfile); GetVideoPlayAuthRequest request = new GetVideoPlayAuthRequest(); request.AcceptFormat = Aliyun.Acs.Core.Http.FormatType.JSON; request.VideoId = vid; try { GetVideoPlayAuthResponse response = client.GetAcsResponse(request); return response; } catch (ServerException e) { Console.WriteLine(e.ErrorCode); Console.WriteLine(e.ErrorMessage); } catch (ClientException e) { Console.WriteLine(e.ErrorCode); Console.WriteLine(e.ErrorMessage); } return null; } } }