123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- 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
- {
- /// <summary>
- /// 获取播放权限
- /// </summary>
- /// <param name="videoId"></param>
- /// <returns></returns>
- 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<string>("AliyunVOD:AliVODRegion");
- var key = ConfigHelper.GetValue<string>("AliyunVOD:AccessKeyId");
- var secret = ConfigHelper.GetValue<string>("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;
- }
- }
- }
|