萤石云第三方接口_流媒体服务器、海康威视 大华摄像头实现视频监控、直播解决方案(转)...

1 usingNewtonsoft.Json;2 usingSystem;3 usingSystem.Collections.Generic;4 usingSystem.Linq;5 usingSystem.Net.Http;6 usingSystem.Net.Http.Headers;7 usingSystem.Text;8 usingSystem.Threading.Tasks;9 usingYJT.Common;10

11 /*20190819 by suzong*/

12 namespaceYJT.Wisdom.Api.lib13{14 ///

15 ///萤石云请求封装

16 ///

17 public classYsClient18{19 private static readonly string requestUrl = "https://open.ys7.com/";20 private static readonly string appKey = "";//官网注册获得

21 private static readonly string appSecret = "";//官网注册获得

22

23 ///

24 ///获得token

25 ///

26 /// {code:200,data:{accessToken:"",expireTime:精确到毫秒}}

27 public static async TaskGetToken()28{29 string key = ConfigHelper.GetSetting("CacheKey:YsToken") ?? "YsAccessToken";30 string tokenStr = MemoryCacheHelper.Get(key)?.ToString();31 if (string.IsNullOrEmpty(tokenStr))32{33 string str = await HttpHelper.HttpPostAsync($"{requestUrl}api/lapp/token/get?appKey={appKey}&appSecret={appSecret}");34 YsResult result = JsonConvert.DeserializeObject(str);35 //缓存token 缓存时间为5天

36 tokenStr = result?.data?.accessToken;37 MemoryCacheHelper.Set(key, tokenStr, TimeSpan.FromDays(5));38}39 returntokenStr;40}41

42 ///

43 ///添加设备

44 ///

45 /// 设备序列号

46 /// 设备验证码

47 ///

48 public static async Task SaveDevice(string deviceSerial, stringvalidateCode)49{50 if (string.IsNullOrEmpty(deviceSerial) || string.IsNullOrEmpty(validateCode))51 return new YsResult() { code = "-1", msg = "缺少验证码或序列号"};52

53 string str = await HttpHelper.HttpPostAsync($"{requestUrl}api/lapp/device/add?accessToken={GetToken().Result}&deviceSerial={deviceSerial.ToUpper()}&validateCode={validateCode.ToUpper()}");54 return JsonConvert.DeserializeObject(str);55}56

57 /

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值