/// <summary>
/// 为避免频繁的对数据库检索,提高获取账号信息的速度
/// 我们把账号信息根据ID缓存起来,方便快速使用,提高效率。
/// </summary>
public static AccountInfo GetAccountByID(string accountId)
{
AccountInfo accountInfo = null;
#region 使用.NET CacheManager缓存
//正常情况下access_token有效期为7200秒,这里使用缓存设置短于这个时间即可
var key = "GetAccountByID_" + accountId;
accountInfo = CacheManagerHelper.GetCacheItem<AccountInfo>(key, () =>
{
return BLLFactory<Account>.Instance.FindByID(accountId);
}, TimeSpan.FromMinutes(TimeOut_Minutes));
return accountInfo;
}
/// <summary>
/// 根据微信小程序平台提供的解密算法解密数据
/// </summary>
[HttpGet]
public SmallAppUserInfo Decrypt(string encryptedData, string iv, string thirdkey)
{
SmallAppUserInfo userInfo = null;
//通过AutoFac工厂获取对应的接口实现
var cache = AutoFactory.Instatnce.Container.Resolve<ICacheManager>();
if (cache != null)
{
//从缓存里面,获取对应的SessionKey
var sessionkey = cache.Manager.Get(thirdkey);
if (sessionkey != null)
{
//对用户身份加密数据进行解析,获取包含openid等属性的完整对象
IBasicApi api = new BasicApi();
userInfo = api.Decrypt(encryptedData, iv, sessionkey.ToString());
}
}
return userInfo;
}