using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Newtonsoft.Json.Linq; using HZQR.Common; using RedisHelp; namespace EShang.Common { /// /// 视频监控帮助类 /// public class VideoHelper { /// /// 萤石云AppKey /// protected const string AppKey = "15f528214d934ee4b048c772c8f8f3b0"; /// /// 萤石云Secret /// protected const string Secret = "2d71a68d0dc4a2aa680c49639bd8f29a"; /// /// 萤石云通讯地址 /// protected const string ReqUrl = "https://open.ys7.com"; /// /// 获取萤石云通道密钥 /// /// public static string GetVideoToken() { RedisHelper redisHelper = new RedisHelper(9); string VideoToken = ""; if (redisHelper.KeyExists("VideoToken")) { Model.VideoTokenModel _VideoTokenModel = new Model.VideoTokenModel(); _VideoTokenModel = redisHelper.StringGet("VideoToken"); if (_VideoTokenModel.expireTime > DateTime.Now) { return _VideoTokenModel.accessToken; } } Dictionary _Dictionary = new Dictionary(); _Dictionary.Add("appKey", AppKey); _Dictionary.Add("appSecret", Secret); string Parameter = PayHelper.paramsToString(_Dictionary); string Result = HttpUtil.HttpUrlPost(Parameter, ReqUrl + "/api/lapp/token/get"); JObject _JObject = JObject.Parse(Result); if (_JObject["code"].ToString() == "200") { Model.VideoTokenModel _VideoTokenModel = new Model.VideoTokenModel(); _VideoTokenModel.accessToken = _JObject["data"]["accessToken"].ToString(); _VideoTokenModel.expireTime = CommonHelper.TicksToDate(_JObject["data"]["expireTime"].ToString()); redisHelper.StringSet("VideoToken", _VideoTokenModel); //设置超时时间 //redisHelper.KeyExpire("VideoToken", new TimeSpan(7 * 24, 0, 0)); } return VideoToken; } } }