GlobalActionFilter.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Library;
  5. using LitJson;
  6. using Microsoft.AspNetCore.Mvc;
  7. using Microsoft.AspNetCore.Mvc.Filters;
  8. namespace MySystem
  9. {
  10. public class GlobalActionFilter : IActionFilter
  11. {
  12. public void OnActionExecuted(ActionExecutedContext context)
  13. {
  14. //执行方法后执行这
  15. }
  16. public void OnActionExecuting(ActionExecutingContext context)
  17. {
  18. //执行方法前先执行这
  19. // var stringArgs = context.ActionArguments.ToList();
  20. // foreach (var keyValue in stringArgs)
  21. // {
  22. // string path = context.ActionDescriptor.AttributeRouteInfo.Template.ToLower();
  23. // function.WriteLog(path, "拦截器日志");
  24. // if(keyValue.Key == "value" && AllowApiList().Contains(path))
  25. // {
  26. // function.WriteLog(keyValue.Value.ToString(), "拦截器日志");
  27. // string result = function.PostWebRequest(AppConfig.Base.Host2 + path, "value=" + keyValue.Value.ToString());
  28. // function.WriteLog(result, "拦截器日志");
  29. // result = result.Replace("null", "\"\"");
  30. // result = result.Replace("\"status\"", "\"Status\"");
  31. // result = result.Replace("\"data\"", "\"Data\"");
  32. // result = result.Replace("\"other\"", "\"Other\"");
  33. // result = result.Replace("\"timestamp\"", "\"Timestamp\"");
  34. // result = result.Replace("\"info\"", "\"Info\"");
  35. // JsonResult obj = new JsonResult(Newtonsoft.Json.JsonConvert.DeserializeObject<AppResultJson>(result));
  36. // context.Result = obj;
  37. // return;
  38. // }
  39. // }
  40. }
  41. private List<string> AllowApiList()
  42. {
  43. List<string> result = new List<string>();
  44. result.Add("api/v1/merchantaddinfo/add");
  45. result.Add("api/v1/merchantaddinfo/options");
  46. result.Add("api/v1/merchantaddinfo/businessscope");
  47. result.Add("api/v1/merchantaddinfo/detail");
  48. result.Add("api/v1/merchantinfo/merchantbystatus");
  49. result.Add("api/v1/merchantinfo/merchantdetailbystatus");
  50. result.Add("api/v1/consumerorders/pay");
  51. result.Add("api/v1/openbanktable/list");
  52. return result;
  53. }
  54. }
  55. }