/// <summary> /// 获取实体信息 /// </summary> /// <returns></returns> public static EntityInfo GetEntityInfo <T>() where T : BaseEntity { var t = typeof(T); if (!MemoryCacheHelper.Exists(t.FullName)) { var entityInfo = new EntityInfo(); var tableName = t.Name; var obs = t.GetTypeInfo().GetCustomAttribute <TableAttribute>(); if (obs != null) { tableName = obs.Name; } var fields = new List <string>(); var properties = t.GetProperties(BindingFlags.Public | BindingFlags.Instance); var dbProps = new List <PropertyInfo>(); foreach (var p in properties) { if (p.CanWrite && p.CanRead && p.GetCustomAttribute <NotMappedAttribute>() == null) { fields.Add(p.Name); dbProps.Add(p); } } entityInfo.TableName = tableName; entityInfo.Properties = dbProps.ToArray(); entityInfo.Columns = fields; MemoryCacheHelper.SetCache(t.FullName, entityInfo, TimeSpan.FromDays(1)); } return(MemoryCacheHelper.GetCache <EntityInfo>(t.FullName)); }
public IActionResult QueryCsds() { string toekn = ""; //string url1 = ""; //var result1 = HttpClient.HttpPostWeChatApi(url1, ""); //LogOperation.WriteLog(result1); if (MemoryCacheHelper.Exists("access_token")) { toekn = MemoryCacheHelper.Get("access_token").ToString(); } else { var tokenUrl = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx878696657f714582&secret=313ed037bf4e927a6d225317e775d1b9"; var bupo = HttpClient.HttpPostWeChatApi(tokenUrl, JsonConvert.SerializeObject(new { })); TokenDto info = JsonConvert.DeserializeObject <TokenDto>(bupo); toekn = info.access_token; MemoryCacheHelper.Set("access_token", toekn, TimeSpan.FromMinutes(60)); } //参数 string postdata = JsonConvert.SerializeObject(new { }); string url = "https://api.weixin.qq.com/cgi-bin/customservice/getkflist?access_token=" + toekn; var result = HttpClient.HttpPostWeChatApi(url, postdata); return(Ok(result)); }
/// <summary> /// 验证授权 /// </summary> /// <param name="httpContext"></param> /// <returns></returns> public Task Invoke(HttpContext httpContext) { var headers = httpContext.Request.Headers; //检测是否包含'Authorization'请求头,如果不包含返回context进行下一个中间件,用于访问不需要认证的API if (!headers.ContainsKey("Authorization")) { return(_next(httpContext)); } var tokenStr = headers["Authorization"]; try { string jwtStr = tokenStr.ToString().Substring("Bearer ".Length).Trim(); //验证缓存中是否存在该jwt字符串 if (!MemoryCacheHelper.Exists(jwtStr)) { return(httpContext.Response.WriteAsync("非法请求")); } JwtToken tm = ((JwtToken)MemoryCacheHelper.GetCache(jwtStr)); //提取JwtToken中的Sub属性进行authorize认证 List <Claim> lc = new List <Claim>(); Claim c = new Claim(tm.Sub + "Type", tm.Sub); lc.Add(c); ClaimsIdentity identity = new ClaimsIdentity(lc); ClaimsPrincipal principal = new ClaimsPrincipal(identity); httpContext.User = principal; return(_next(httpContext)); } catch (Exception) { return(httpContext.Response.WriteAsync("token验证异常")); } }
private object RuleCaches() { string key = MemoryCacheHelper.GetRuleCaches; if (MemoryCacheHelper.Exists(key)) { return(MemoryCacheHelper.Get(key)); } else { var result = DC.Set <VOS_Rule>().ToList(); MemoryCacheHelper.Set(key, result, new TimeSpan(7, 0, 0, 0)); return(result); } }
public async Task <List <GetStudentByIdDto> > QuerysByClassNo(GetStudentByIdInput input) { var key = "QuerysByClassNo-" + input.ClassNo; if (MemoryCacheHelper.Exists(key)) { var list = MemoryCacheHelper.Get(key); return((List <GetStudentByIdDto>)list); } else { var students = await _studentService.QueryStudentsByClassNo(input); MemoryCacheHelper.Set(key, students, TimeSpan.FromMinutes(1)); return(students); } }
/// <summary> /// 获取模型属性列表 /// </summary> /// <param name="t"></param> /// <returns></returns> public static PropertyInfo[] GetModelProperties(Type t) { if (!MemoryCacheHelper.Exists(t.FullName)) { var properies = t.GetProperties(BindingFlags.Instance | BindingFlags.Public); var list = new List <PropertyInfo>(); foreach (var p in properies) { if (p.CanWrite && p.GetCustomAttribute <NotMappedAttribute>() == null) { list.Add(p); } } MemoryCacheHelper.SetCache(t.FullName, list.ToArray(), TimeSpan.FromDays(1)); } return(MemoryCacheHelper.GetCache <PropertyInfo[]>(t.FullName)); }
public IActionResult GetUserInfo(string openId) { //参数 string postdata = JsonConvert.SerializeObject(new { }); //---------第一步------------ //appid=wx878696657f714582 //secret=313ed037bf4e927a6d225317e775d1b9 //---------第二步------------ //获取access_token值 string toekn = ""; if (MemoryCacheHelper.Exists("access_token")) { toekn = MemoryCacheHelper.Get("access_token").ToString(); } else { var tokenUrl = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx878696657f714582&secret=313ed037bf4e927a6d225317e775d1b9"; var bupo = HttpClient.HttpPostWeChatApi(tokenUrl, postdata); TokenDto info = JsonConvert.DeserializeObject <TokenDto>(bupo); toekn = info.access_token; MemoryCacheHelper.Set("access_token", toekn, TimeSpan.FromMinutes(60)); } //---------第三步------------ //获取openId值 if (string.IsNullOrEmpty(openId)) { openId = "oXriy6Dh8McEmYtZJx4xr6GABuvU"; } //---------第四步------------ //获取用户基本信息 string url = " https://api.weixin.qq.com/cgi-bin/user/info?access_token=" + toekn + "&openid=" + openId + "&lang=zh_CN"; var user = HttpClient.HttpPostWeChatApi(url, postdata); return(Ok(user)); }
/// <summary> /// 获取用户权限 /// </summary> /// <param name="user"></param> /// <returns></returns> public async Task <List <InterfaceOperationModel> > GetUserAuthoritiesAsync(AspNetUser user) { var key = $"{user.Id}_UserAuthorities"; if (!MemoryCacheHelper.Exists(key)) { var list = new List <InterfaceOperationModel>(); var b = (await _context.QueryNumberBySqlAsync($"SELECT COUNT(b.Id) FROM AspNetRole a,AspNetUserRole b WHERE a.Id=b.RoleId AND b.UserId={user.Id} AND a.Name='{nameof(RoleTypes.Admin)}'")) > 0; string sql = GET_ALL_OPERATION_SQL; if (!b) { sql = $@"SELECT t2.InterfaceName,t2.OperationName FROM ({GET_ALL_OPERATION_SQL}) t2,DDomainAuthority t3,`aspnetusers` t4 WHERE t3.`OperationId`=t2.`Id` AND t4.`Id`= '{user.Id}' AND(t3.`AuthorityId`= t4.`AuthorityId` OR t3.`AuthorityId` IN(SELECT a.AuthorityId FROM `aspnetroles` a,`aspnetuserroles` b WHERE a.`Id`= b.`RoleId` AND b.`UserId`= '{user.Id}'))"; } list = await _context.QueryListBySqlAsync <InterfaceOperationModel>(sql); MemoryCacheHelper.SetCache(key, list); } return(MemoryCacheHelper.GetCache <List <InterfaceOperationModel> >(key)); }
public IActionResult GetUserInfos() { //参数 string postdata = JsonConvert.SerializeObject(new { }); string token = ""; if (MemoryCacheHelper.Exists("access_token")) { token = MemoryCacheHelper.Get("access_token").ToString(); } else { var tokenUrl = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx878696657f714582&secret=313ed037bf4e927a6d225317e775d1b9"; var bupo = HttpClient.HttpPostWeChatApi(tokenUrl, postdata); TokenDto tokenInfo = JsonConvert.DeserializeObject <TokenDto>(bupo); token = tokenInfo.access_token; MemoryCacheHelper.Set("access_token", token, TimeSpan.FromMinutes(60)); } string url = "https://api.weixin.qq.com/cgi-bin/user/get?access_token=" + token + "&next_openid="; var user = HttpClient.HttpPostWeChatApi(url, postdata); return(Ok(user)); }
public IActionResult InsertCsd() { string toekn = ""; if (MemoryCacheHelper.Exists("access_token")) { toekn = MemoryCacheHelper.Get("access_token").ToString(); } else { var tokenUrl = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx878696657f714582&secret=313ed037bf4e927a6d225317e775d1b9"; var bupo = HttpClient.HttpPostWeChatApi(tokenUrl, JsonConvert.SerializeObject(new { })); TokenDto info = JsonConvert.DeserializeObject <TokenDto>(bupo); toekn = info.access_token; MemoryCacheHelper.Set("access_token", toekn, TimeSpan.FromMinutes(60)); } //参数 string postdata = JsonConvert.SerializeObject(new { kf_account = "test1@test", nickname = "客服1", password = "******" }); string url = " https://api.weixin.qq.com/customservice/kfaccount/add?access_token=" + toekn; var result = HttpClient.HttpPostWeChatApi(url, postdata); return(Ok(result)); }
private void RemoteInvokeThread() { while (true) { if (_remoteInvokeExit) { break; } try { if (_workList.Count > 0) { if (_masterCacheList.Count > 0) { int taskNum = _masterCacheList.Count; int workerNum = _workList.Count; int parallelNum = 0; if (taskNum >= workerNum) { parallelNum = workerNum; } else { parallelNum = taskNum % workerNum; } if (GlobalConfig.Config.WorkerPower > 1) { parallelNum *= GlobalConfig.Config.WorkerPower; } if (parallelNum > 0) { List <byte[]> parallelTasks = new List <byte[]>(); #region foreach (KeyValuePair <string, byte[]> kv in _masterCacheList) { if (kv.Value != null && kv.Value.Length > 0) { if (!MemoryCacheHelper.Exists(kv.Key)) { parallelTasks.Add(kv.Value); MemoryCacheHelper.Set(kv.Key, DateTime.Now, TimeSpan.FromMilliseconds(GlobalConfig.Config.RepeatRemoteInvokeInterval), false); } if (parallelTasks.Count >= parallelNum) { break; } } else { Logger.Log.Info(false, "发送任务,为空:" + kv.Key); } } #endregion #region if (parallelTasks.Count > 0) { Parallel.ForEach(parallelTasks, (data) => { IWorker worker = GetPollWorker(); if (worker == null) { return; } lock (((Worker.Worker)worker).SyncLock) { if (data != null && data.Length > 0) { string remoteInfo = String.Empty; _channelMessageHandler.Send(worker.Id, data, out remoteInfo); data = null; Logger.Log.Info(false, "发送任务到:" + remoteInfo + ",子节点编号:" + worker.Id); } else { Logger.Log.Info(false, "发送任务,为空"); } } }); } #endregion parallelTasks.Clear(); parallelTasks = null; } } } } catch (ThreadInterruptedException) { break; } catch (Exception ex) { Logger.Log.Error(true, "远程调用子节点:", ex); } Thread.Sleep(GlobalConfig.Config.RemoteInvokeInterval); } }