/// <summary> /// 对外接口通用加密方法 /// </summary> /// <param name="appKey"></param> /// <param name="secret"></param> /// <param name="timeStamp"></param> /// <param name="body"></param> /// <returns></returns> public static string InterfaceEncrypt(string appKey, string secret, string timeStamp, string body) { var signStr = appKey + secret + timeStamp + body; var res = ComHelper.MD5Sign(signStr).ToUpper(); return(res); }
/// <summary> /// 设置 /// </summary> /// <param name="key"></param> /// <param name="value"></param> /// <param name="cacheTime"></param> public void Set(string key, object value, TimeSpan cacheTime) { if (value != null) { //序列化,将object值生成RedisValue redisConnection.GetDatabase().StringSet(key, ComHelper.ByteSerialize(value), cacheTime); } }
/// <summary> /// 对外接口通用加密方法 /// </summary> /// <param name="appKey"></param> /// <param name="timeStamp"></param> /// <param name="body"></param> /// <returns></returns> public static string InterfaceEncrypt(string appKey, string timeStamp, string body) { if (DicSecret.ContainsKey(appKey)) { var secret = DicSecret[appKey]; var signStr = appKey + secret + timeStamp + body; var res = ComHelper.MD5Sign(signStr).ToUpper(); return(res); } return(string.Empty); }
/// <summary> /// 根据上传目录字典获取绝对路径 /// </summary> /// <param name="key"></param> /// <param name="dt"></param> /// <returns></returns> public static string GetUploadAbsPath(string key, DateTime dt) { key = key.ToLower(); if (DicUpPath.ContainsKey(key)) { var virPath = DicUpPath[key]; var path = ComHelper.GetAbsPath(virPath); var fullPath = Path.Combine(path, dt.ToString("yyyyMMdd")); return(fullPath); } return(string.Empty); }
/// <summary> /// 构造方法 /// </summary> public RedisCacheManager() { string redisConfiguration = ComHelper.GetConf("AppSettings:RedisCachingAOP:ConnectionString");//获取连接字符串 if (string.IsNullOrWhiteSpace(redisConfiguration)) { throw new ArgumentException("redis config is empty", nameof(redisConfiguration)); } this.redisConnenctionString = redisConfiguration; this.redisConnection = GetRedisConnection(); }
/// <summary> /// 获取 /// </summary> /// <typeparam name="TEntity"></typeparam> /// <param name="key"></param> /// <returns></returns> public TEntity Get <TEntity>(string key) { var value = redisConnection.GetDatabase().StringGet(key); if (value.HasValue) { //需要用的反序列化,将Redis存储的Byte[],进行反序列化 return(ComHelper.ByteDeserialize <TEntity>(value)); } else { return(default(TEntity)); } }
/// <summary> /// 初始化数据库上下文 /// </summary> /// <param name="isAutoClose"></param> private void InitDbContext(bool isAutoClose) { if (string.IsNullOrEmpty(ConnectionString)) { throw new ArgumentNullException("数据库连接字符串为空"); } Db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = ConnectionString, DbType = DbType, IsAutoCloseConnection = isAutoClose, IsShardSameThread = false, InitKeyType = InitKeyType.Attribute, ConfigureExternalServices = new ConfigureExternalServices() { //DataInfoCacheService = new HttpRuntimeCache() }, MoreSettings = new ConnMoreSettings() { //IsWithNoLockQuery = true, IsAutoRemoveDataCache = true }, }); if (ComHelper.GetConf("AppSettings:SqlAOP:Enabled").ObjToBool()) { Db.Aop.OnLogExecuting = (sql, pars) => //SQL执行中事件 { Parallel.For(0, 1, e => { var paras = GetParas(pars); var msg = $"执行SQL:{paras} 【SQL语句】:{sql}"; MiniProfiler.Current.CustomTiming("SQL", msg); //LogLock.OutSql2Log("SqlLog", new string[] { GetParas(pars), "【SQL语句】:" + sql }); _loggerHelper.SqlLog(msg); }); }; } }