基础服务api
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

64 lines
2.0 KiB

  1. using BPA.SAAS.Manage.Application.AExternalPlatform.Enum;
  2. using BPA.SAAS.Manage.Core;
  3. using BPA.SAAS.Manage.Core.DataBase;
  4. using BPA.SAAS.Manage.Core.Org;
  5. using Furion.JsonSerialization;
  6. using Newtonsoft.Json;
  7. using NPOI.Util.ArrayExtensions;
  8. using System.Collections.Generic;
  9. using System.ComponentModel.DataAnnotations;
  10. using System.Reflection;
  11. using System.Text;
  12. namespace BPA.SAAS.Manage.Application.AExternalPlatform.BaseDto
  13. {
  14. /// <summary>
  15. /// Dto参数验证
  16. /// </summary>
  17. public static class DtoValidator
  18. {
  19. /// <summary>
  20. /// 获取签名
  21. /// </summary>
  22. /// <typeparam name="T"></typeparam>
  23. /// <param name="t"></param>
  24. /// <param name="otype">0-不排序 1-按名称ASCII排序</param>
  25. /// <returns></returns>
  26. public static string GetSign<T>(T t, int otype = 1)
  27. {
  28. string retstr = "";
  29. //定义PropertyInfo的List
  30. List<PropertyInfo> proplist = new List<PropertyInfo>();
  31. //遍历泛型类的每个属性加入到List里面
  32. Array.ForEach<PropertyInfo>(typeof(T).GetProperties(),
  33. p => proplist.Add(p));
  34. //根据参数进行排序 0-不排序 1-按名称ASCII码排序
  35. if (otype == 1)
  36. proplist = proplist.OrderBy(k => k.Name).ToList();
  37. //遍历List泛型生成我们要签名的字符串
  38. proplist.ForEach(p =>
  39. {
  40. if (p.Name.ToLower() != "sign".ToLower())
  41. {
  42. if (p.GetValue(t, null) != null && p.GetValue(t, null).ToString() != "")
  43. {
  44. retstr = retstr + p.Name + "=" + p.GetValue(t, null) + "&";
  45. }
  46. }
  47. });
  48. //把字符串最后一位截断
  49. retstr = retstr.Substring(0, retstr.Length - 1);
  50. //输出字符串
  51. return retstr;
  52. }
  53. }
  54. }