You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.3 KiB
48 lines
1.3 KiB
3 years ago
|
using BBWY.Common.Models;
|
||
|
using BBWY.Server.Model.Db;
|
||
|
using Microsoft.Extensions.Caching.Memory;
|
||
|
using System;
|
||
|
|
||
|
namespace BBWY.Server.Business
|
||
|
{
|
||
|
public class YunDingBusiness : IDenpendency
|
||
|
{
|
||
|
private IMemoryCache memoryCache;
|
||
|
private IFreeSql fsql;
|
||
|
private TimeSpan expirationTimeSpan = TimeSpan.FromDays(2);
|
||
|
public YunDingBusiness(IMemoryCache memoryCache, IFreeSql fsql)
|
||
|
{
|
||
|
this.memoryCache = memoryCache;
|
||
|
this.fsql = fsql;
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 创建云鼎Key
|
||
|
/// </summary>
|
||
|
public void CreateKey()
|
||
|
{
|
||
|
var key = Guid.NewGuid().ToString();
|
||
|
memoryCache.Set("YunDingKey", key, expirationTimeSpan);
|
||
|
fsql.Update<JDYunDingAPIKey>(1).Set(k => k.YunDingKey, key).ExecuteAffrows();
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 刷新云鼎Key
|
||
|
/// </summary>
|
||
|
public void RefreshKey()
|
||
|
{
|
||
|
var yundingKey = fsql.Select<JDYunDingAPIKey>(1).ToOne();
|
||
|
memoryCache.Set("YunDingKey", yundingKey.YunDingKey, expirationTimeSpan);
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 读取云鼎Key
|
||
|
/// </summary>
|
||
|
/// <returns></returns>
|
||
|
public string GetKey()
|
||
|
{
|
||
|
return memoryCache.Get<string>("YunDingKey");
|
||
|
}
|
||
|
}
|
||
|
}
|