/// <summary> /// 生成对应的描述文件 /// </summary> /// <param name="path"></param> /// <param name="name">描述的名字字符串,逗号分割</param> /// <param name="typeid"></param> /// <returns></returns> private void CreateShowNameFile_Pro(string path, string name, int typeid) { try { string from = Path.GetDirectoryName(System.Web.Hosting.HostingEnvironment.MapPath(path)); if (!Directory.Exists(from)) { Alert("表情包不存在"); return; } DirectoryInfo root = new DirectoryInfo(from); FileInfo[] files = root.GetFiles(); List <string> file3 = new List <string>(); foreach (var item in files) { if (item.Extension == ".gif") { file3.Add(item.Name.Replace(item.Extension, "")); } } var dic = new Dictionary <string, string>(); var ss = name.Split(','); int i = 0; if (typeid == 0) { file3 = file3.OrderBy(c => c).ToList(); } else if (typeid == 1) { file3 = file3.OrderBy(c => int.Parse(c.Split('_')[0])).ToList(); } else { file3 = file3.OrderBy(c => int.Parse(c.Split('_')[1])).ToList(); } foreach (var item in file3) { dic.Add(item, ss[i]); i++; } var data = JsonWinner.SerializeObject(dic); WriteFileEmoction(from + "/ShowNameJson.txt", data); } catch (Exception e) { log.Info(e.ToString()); return; } }
private void AuthSignature(HttpActionContext actionContext) { if (actionContext.ActionDescriptor.GetCustomAttributes <AnonymousAttribute>().Count() > 0 || actionContext.ActionDescriptor.ControllerDescriptor.GetCustomAttributes <AnonymousAttribute>().Count() > 0) { return; } //log.Info("===============ReqUrl=" + HttpContext.Current.Request.Url.ToString()); //log.Info("===============ReqContent=" + Helper.GetRequestContent()); //#pragma warning disable IDE0019 // 使用模式匹配 Reqbase req = actionContext.ActionArguments.First().Value as Reqbase; //#pragma warning restore IDE0019 // 使用模式匹配 if (req == null) { WriteErrLog("参数匹配失败", ""); actionContext.Response = new HttpResponseMessage { StatusCode = HttpStatusCode.BadRequest, Content = new StringContent(JsonWinner.SerializeObjectPropertyNameLower(new Respbase { Result = -1, Message = "参数匹配错误" })) }; return; } if (!actionContext.ModelState.IsValid) { string modelStateMsg = GetModelError(actionContext.ModelState.Values.SelectMany(c => c.Errors)); WriteErrLog("参数验证错误", modelStateMsg); actionContext.Response = new HttpResponseMessage { StatusCode = HttpStatusCode.BadRequest, Content = new StringContent(JsonWinner.SerializeObjectPropertyNameLower(new Respbase { Result = -1, Message = "参数验证错误" })) }; return; } var unLogin = actionContext.ActionDescriptor.GetCustomAttributes <UnLoginAttribute>().FirstOrDefault();//如果没有UnLoginAttribute特性标记则校验用户 TnetReginfo regInfo = null; if (unLogin == null) { regInfo = CommonApiTransfer.Instance.GetTnetReginfo(new GetRegInfoReq { RegInfoKey = req.Nodeid.ToString() }); if (regInfo == null) { WriteErrLog("用户不存在", $"nodeid={req.Nodeid}"); actionContext.Response = new HttpResponseMessage { StatusCode = HttpStatusCode.BadRequest, Content = new StringContent(JsonWinner.SerializeObjectPropertyNameLower(new Respbase { Result = -1, Message = "用户不存在" })) }; return; } } if (!CommonConfig.SignValidationDisabled) { //DvUZIrmKXs if (!req.Sign.Equals(Helper.GetSign(req.Nodeid, req.Sid, req.Tm, CommonConfig.ApiAuthString), StringComparison.OrdinalIgnoreCase) && !req.Sign.Equals(Helper.GetSign(req.Nodeid, req.Sid, req.Tm, "DvUZIrmKXs"), StringComparison.OrdinalIgnoreCase) && !req.Sign.Equals(Helper.GetSign(req.Nodeid, req.Sid, req.Tm, CommonConfig.CasAuthString), StringComparison.OrdinalIgnoreCase) && !req.Sign.Equals(Helper.GetSign(req.Nodeid, req.Sid, req.Tm, ConfigurationManager.AppSettings["PcnAuthString"]), StringComparison.OrdinalIgnoreCase)) { WriteErrLog("参数签名错误", JsonConvert.SerializeObject(req)); actionContext.Response = new HttpResponseMessage { StatusCode = HttpStatusCode.Unauthorized, Content = new StringContent(JsonWinner.SerializeObjectPropertyNameLower(new Respbase { Result = -1, Message = "参数签名错误" })) }; return; } } if (regInfo != null) { HttpContext.Current.Items.Add("CurrentUser", regInfo); } }
/// <summary> /// /// </summary> /// <param name="actionExecutedContext"></param> public override void OnException(HttpActionExecutedContext actionExecutedContext) { log.Error("Excetion ReqUrl=" + actionExecutedContext.Request.RequestUri.ToString()); //log.Error("Excetion ReqContent=" + Helper.GetRequestContent()); log.Error("Excetion Info=" + actionExecutedContext.Exception.ToString()); Helper.ClearDbAndTransfer(); if (actionExecutedContext.Exception is ArgumentException) { actionExecutedContext.Response = new HttpResponseMessage { StatusCode = HttpStatusCode.InternalServerError, Content = new StringContent(JsonWinner.SerializeObjectPropertyNameLower(new Respbase { Result = 0, Message = actionExecutedContext.Exception.Message })) }; } else { actionExecutedContext.Response = new HttpResponseMessage { StatusCode = HttpStatusCode.InternalServerError, Content = new StringContent(JsonWinner.SerializeObjectPropertyNameLower(new Respbase { Result = 0, Message = "网络繁忙,请稍后重试" })) }; } base.OnException(actionExecutedContext); }