70 lines
2.4 KiB
C#
70 lines
2.4 KiB
C#
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
|
|
{
|
|
/// <summary>
|
|
/// 视频监控帮助类
|
|
/// </summary>
|
|
public class VideoHelper
|
|
{
|
|
/// <summary>
|
|
/// 萤石云AppKey
|
|
/// </summary>
|
|
protected const string AppKey = "15f528214d934ee4b048c772c8f8f3b0";
|
|
/// <summary>
|
|
/// 萤石云Secret
|
|
/// </summary>
|
|
protected const string Secret = "2d71a68d0dc4a2aa680c49639bd8f29a";
|
|
/// <summary>
|
|
/// 萤石云通讯地址
|
|
/// </summary>
|
|
protected const string ReqUrl = "https://open.ys7.com";
|
|
|
|
/// <summary>
|
|
/// 获取萤石云通道密钥
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static string GetVideoToken()
|
|
{
|
|
RedisHelper redisHelper = new RedisHelper(9);
|
|
string VideoToken = "";
|
|
if (redisHelper.KeyExists("VideoToken"))
|
|
{
|
|
Model.VideoTokenModel _VideoTokenModel = new Model.VideoTokenModel();
|
|
_VideoTokenModel = redisHelper.StringGet<Model.VideoTokenModel>("VideoToken");
|
|
if (_VideoTokenModel.expireTime > DateTime.Now)
|
|
{
|
|
return _VideoTokenModel.accessToken;
|
|
}
|
|
}
|
|
|
|
Dictionary<string, string> _Dictionary = new Dictionary<string, string>();
|
|
_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<Model.VideoTokenModel>("VideoToken", _VideoTokenModel);
|
|
//设置超时时间
|
|
//redisHelper.KeyExpire("VideoToken", new TimeSpan(7 * 24, 0, 0));
|
|
}
|
|
|
|
return VideoToken;
|
|
}
|
|
}
|
|
}
|