GlobalActionFilter.cs 2.5 KB

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