|
-
- using BPA.SAAS.Manage.Application.AExternalPlatform.Enum;
- using BPA.SAAS.Manage.Core;
- using BPA.SAAS.Manage.Core.DataBase;
- using BPA.SAAS.Manage.Core.Org;
- using Furion.JsonSerialization;
- using Newtonsoft.Json;
- using NPOI.Util.ArrayExtensions;
- using System.Collections.Generic;
- using System.ComponentModel.DataAnnotations;
- using System.Reflection;
- using System.Text;
-
- namespace BPA.SAAS.Manage.Application.AExternalPlatform.BaseDto
- {
-
-
-
- /// <summary>
- /// Dto参数验证
- /// </summary>
- public static class DtoValidator
- {
-
-
- /// <summary>
- /// 获取签名
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="t"></param>
- /// <param name="otype">0-不排序 1-按名称ASCII排序</param>
- /// <returns></returns>
- public static string GetSign<T>(T t, int otype = 1)
- {
- string retstr = "";
- //定义PropertyInfo的List
- List<PropertyInfo> proplist = new List<PropertyInfo>();
- //遍历泛型类的每个属性加入到List里面
- Array.ForEach<PropertyInfo>(typeof(T).GetProperties(),
- p => proplist.Add(p));
- //根据参数进行排序 0-不排序 1-按名称ASCII码排序
- if (otype == 1)
- proplist = proplist.OrderBy(k => k.Name).ToList();
-
- //遍历List泛型生成我们要签名的字符串
- proplist.ForEach(p =>
- {
- if (p.Name.ToLower() != "sign".ToLower())
- {
- if (p.GetValue(t, null) != null && p.GetValue(t, null).ToString() != "")
- {
- retstr = retstr + p.Name + "=" + p.GetValue(t, null) + "&";
- }
-
- }
- });
- //把字符串最后一位截断
- retstr = retstr.Substring(0, retstr.Length - 1);
- //输出字符串
- return retstr;
- }
- }
- }
|