diff --git a/StoreHub.Framework/Security/JwtClaimTypes.cs b/StoreHub.Framework/Security/JwtClaimTypes.cs
index 57f100f..d73afb7 100644
--- a/StoreHub.Framework/Security/JwtClaimTypes.cs
+++ b/StoreHub.Framework/Security/JwtClaimTypes.cs
@@ -5,8 +5,7 @@
///
public static class JwtClaimTypes
{
- /// 用户ID
- public const string UserId = "uid";
+ public const string UserId = "user_name";
/// 登录账户
public const string UserName = "user_name";
diff --git a/StoreHub.Framework/Startup.cs b/StoreHub.Framework/Startup.cs
index a16e7bc..3525ac6 100644
--- a/StoreHub.Framework/Startup.cs
+++ b/StoreHub.Framework/Startup.cs
@@ -34,6 +34,7 @@ namespace StoreHub.Framework
});
+
Func KJDFsqlFactory = r =>
{
var config = r.GetRequiredService();
@@ -51,3 +52,4 @@ namespace StoreHub.Framework
}
}
}
+
diff --git a/StoreHub.KJDWebService/Commons/BaseClass.cs b/StoreHub.KJDWebService/Commons/BaseClass.cs
new file mode 100644
index 0000000..14855ed
--- /dev/null
+++ b/StoreHub.KJDWebService/Commons/BaseClass.cs
@@ -0,0 +1,53 @@
+using StoreHub.KJDWebService.Commons;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+
+namespace StoreHub.KJDWebService.Commons
+{
+
+ public class BaseClass
+ {
+ public static string BuildPDDObjString(string file, bool IsLoginDef = false)
+ {
+ string LoginApiUrl = "http://1.13.195.131:9001";
+ string MainPath = "kuajingda";
+ return LoginApiUrl + "/bxx_" + file + "?obj=" + MainPath + "/bxx_" + file;
+ }
+
+ public static int TimeDifferent = 0;
+ public static int VersionCount = 99999999;
+ public static int CompanyId = 1;
+ public static string CompanyName = "1";
+ public static string UserKey = "1";
+ public static string Mobile = "18888888888";
+ public static string UserName = "18888888888";
+ public static string ShopId = "18888888888";
+ public static string ShopName = "18888888888";
+ }
+
+ public class UserLogin
+ {
+ ///
+ /// 获取签名字符串,新版
+ ///
+ ///
+ public static string GetSignaturex()
+ {
+ return GetSignaturex(BaseClass.ShopId, BaseClass.ShopName);
+ }
+ public static string GetSignaturex(string shopId, string shopName)
+ {
+ if (string.IsNullOrEmpty(shopId))
+ shopId = "11111111";
+ if (string.IsNullOrEmpty(shopName))
+ shopName = "wx11111111";
+ int time = TimeUtils.DateTimeToTimestampSeconds(DateTime.Now) + BaseClass.TimeDifferent;
+ string time1 = EncrypUtil.Encryption(time);
+ return "time=" + time + "&code=" + time1 + "&NbCodeVersion=1" + "&version=" + BaseClass.VersionCount +
+ "&company_id=" + BaseClass.CompanyId + "&company=" + HtmlUtils.UrlEncodeUtf8(BaseClass.CompanyName) +
+ "&user_name=" + BaseClass.UserName + "&user_key=" + BaseClass.UserKey + "&mobile=" + BaseClass.Mobile +
+ "&sid=" + shopId + "&shop=" + HtmlUtils.UrlEncodeUtf8(shopName);
+ }
+ }
+}
diff --git a/StoreHub.KJDWebService/Commons/EncrypUtil.cs b/StoreHub.KJDWebService/Commons/EncrypUtil.cs
new file mode 100644
index 0000000..a2489fb
--- /dev/null
+++ b/StoreHub.KJDWebService/Commons/EncrypUtil.cs
@@ -0,0 +1,60 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Security.Cryptography;
+using System.Text;
+
+namespace StoreHub.KJDWebService.Commons
+{
+ public class EncrypUtil
+ {
+ ///
+ /// 加密算法
+ ///
+ /// 加密字符串
+ ///
+ public static string Encryption(int s)
+ {
+ string sign = $"{s}sdhewu*/fhAAue48485ew5+5%@3485esGFFHFD";
+ return GetMd5(sign);
+ }
+
+ ///
+ /// MD5加密
+ ///
+ ///
+ ///
+ public static string GetMd5(string instring)
+ {
+ byte[] result = Encoding.Default.GetBytes(instring.Trim());
+ MD5 md5 = new MD5CryptoServiceProvider();
+ byte[] output = md5.ComputeHash(result);
+ return BitConverter.ToString(output).Replace("-", "");
+ }
+
+ ///
+ /// 获取文件MD5值
+ ///
+ ///
+ ///
+ public static string GetFileMd5(string FilePath)
+ {
+ try
+ {
+ FileStream get_file = new FileStream(FilePath, FileMode.Open, FileAccess.Read, FileShare.Read);
+ System.Security.Cryptography.MD5CryptoServiceProvider get_md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
+ byte[] hash_byte = get_md5.ComputeHash(get_file);
+ string resule = System.BitConverter.ToString(hash_byte);
+ resule = resule.Replace("-", "");
+ get_file.Close();
+ return resule;
+ }
+ catch (Exception e)
+ {
+ return e.ToString();
+ }
+ }
+ }
+}
+
diff --git a/StoreHub.KJDWebService/Commons/Extension/Extension.Convert.cs b/StoreHub.KJDWebService/Commons/Extension/Extension.Convert.cs
new file mode 100644
index 0000000..1999a32
--- /dev/null
+++ b/StoreHub.KJDWebService/Commons/Extension/Extension.Convert.cs
@@ -0,0 +1,705 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Runtime.Serialization.Formatters.Binary;
+using System.Text;
+using System.Threading.Tasks;
+using NaiBa.Util.Helper;
+using Newtonsoft.Json;
+
+namespace NaiBa.Util.Extension
+{
+ public static partial class Extensions
+ {
+ #region 转换为long
+ ///
+ /// 将object转换为long,若转换失败,则返回0。不抛出异常。
+ ///
+ ///
+ ///
+ public static long ParseToLong(this object obj)
+ {
+ if (obj == null)
+ return 0L;
+
+ try
+ {
+ string str = obj.ParseToString();
+ if (string.IsNullOrEmpty(str))
+ {
+ return 0;
+ }
+ return long.Parse(str);
+ }
+ catch
+ {
+ return 0L;
+ }
+ }
+
+ public static long? ParseToNullableLong(this object obj)
+ {
+ if (obj == null)
+ return null;
+
+ try
+ {
+ string str = obj.ParseToString();
+ if (string.IsNullOrEmpty(str))
+ {
+ return null;
+ }
+ return long.Parse(str);
+ }
+ catch
+ {
+ return null;
+ }
+ }
+
+ ///
+ /// 将object转换为long,若转换失败,则返回指定值。不抛出异常。
+ ///
+ ///
+ ///
+ ///
+ public static long ParseToLong(this string str, long defaultValue)
+ {
+ if (str == null)
+ return defaultValue;
+
+ try
+ {
+ return long.Parse(str);
+ }
+ catch
+ {
+ return defaultValue;
+ }
+ }
+ #endregion
+
+ #region 转换为int
+ ///
+ /// 将object转换为int,若转换失败,则返回0。不抛出异常。
+ ///
+ ///
+ ///
+ public static int ParseToInt(this object str)
+ {
+ if (str == null)
+ return 0;
+
+ try
+ {
+ return Convert.ToInt32(str);
+ }
+ catch
+ {
+ return 0;
+ }
+ }
+
+ public static int? ParseToNullableInt(this object str)
+ {
+ if (str == null)
+ return null;
+
+ try
+ {
+ return Convert.ToInt32(str);
+ }
+ catch
+ {
+ return null;
+ }
+ }
+
+ public static int DecimalPointParseToInt(this object str)
+ {
+ try
+ {
+ string temp = str.ParseToString();
+ int i = temp.IndexOf('.');
+ if (i > 0)
+ {
+ temp = temp.Substring(0, i);
+ }
+ return Convert.ToInt32(temp);
+ }
+ catch
+ {
+ return 0;
+ }
+ }
+
+ ///
+ /// 将object转换为int,若转换失败,则返回指定值。不抛出异常。
+ /// null返回默认值
+ ///
+ ///
+ ///
+ ///
+ public static int ParseToInt(this object str, int defaultValue)
+ {
+ if (str == null)
+ {
+ return defaultValue;
+ }
+ try
+ {
+ return Convert.ToInt32(str);
+ }
+ catch
+ {
+ return defaultValue;
+ }
+ }
+ #endregion
+
+ #region 转换为short
+ ///
+ /// 将object转换为short,若转换失败,则返回0。不抛出异常。
+ ///
+ ///
+ ///
+ public static short ParseToShort(this object obj)
+ {
+ try
+ {
+ return short.Parse(obj.ToString());
+ }
+ catch
+ {
+ return 0;
+ }
+ }
+
+ ///
+ /// 将object转换为short,若转换失败,则返回指定值。不抛出异常。
+ ///
+ ///
+ ///
+ public static short ParseToShort(this object str, short defaultValue)
+ {
+ try
+ {
+ return short.Parse(str.ToString());
+ }
+ catch
+ {
+ return defaultValue;
+ }
+ }
+ #endregion
+
+ #region 转换为demical
+ ///
+ /// 将object转换为demical,若转换失败,则返回指定值。不抛出异常。
+ ///
+ ///
+ ///
+ public static decimal ParseToDecimal(this object str, decimal defaultValue)
+ {
+ try
+ {
+ return decimal.Parse(str.ToString());
+ }
+ catch
+ {
+ return defaultValue;
+ }
+ }
+
+ ///
+ /// 将object转换为demical,若转换失败,则返回0。不抛出异常。
+ ///
+ ///
+ ///
+ public static decimal ParseToDecimal(this object str)
+ {
+ try
+ {
+ return decimal.Parse(str.ToString());
+ }
+ catch
+ {
+ return 0;
+ }
+ }
+ public static decimal? ParseToNullableDecimal(this object str)
+ {
+ try
+ {
+ return decimal.Parse(str.ToString());
+ }
+ catch
+ {
+ return null;
+ }
+ }
+ #endregion
+
+ #region 转化为bool
+ ///
+ /// 将object转换为bool,若转换失败,则返回false。不抛出异常。
+ ///
+ ///
+ ///
+ public static bool ParseToBool(this object str)
+ {
+ try
+ {
+ if (str is null)
+ return false;
+ return bool.Parse(str.ToString());
+ }
+ catch
+ {
+ return false;
+ }
+ }
+
+ ///
+ /// 将object转换为bool,若转换失败,则返回指定值。不抛出异常。
+ ///
+ ///
+ ///
+ public static bool ParseToBool(this object str, bool result)
+ {
+ try
+ {
+ return bool.Parse(str.ToString());
+ }
+ catch
+ {
+ return result;
+ }
+ }
+ #endregion
+
+ #region 转换为float
+ ///
+ /// 将object转换为float,若转换失败,则返回0。不抛出异常。
+ ///
+ ///
+ ///
+ public static float ParseToFloat(this object str)
+ {
+ try
+ {
+ return float.Parse(str.ToString());
+ }
+ catch
+ {
+ return 0;
+ }
+ }
+
+ ///
+ /// 将object转换为float,若转换失败,则返回指定值。不抛出异常。
+ ///
+ ///
+ ///
+ public static float ParseToFloat(this object str, float result)
+ {
+ try
+ {
+ return float.Parse(str.ToString());
+ }
+ catch
+ {
+ return result;
+ }
+ }
+ #endregion
+
+ #region 转换为Guid
+ ///
+ /// 将string转换为Guid,若转换失败,则返回Guid.Empty。不抛出异常。
+ ///
+ ///
+ ///
+ public static Guid ParseToGuid(this string str)
+ {
+ try
+ {
+ return new Guid(str);
+ }
+ catch
+ {
+ return Guid.Empty;
+ }
+ }
+ #endregion
+
+ #region 转换为DateTime
+
+ public static DateTime? ParseToDateTimeNullable(this string str)
+ {
+ try
+ {
+ if (string.IsNullOrWhiteSpace(str))
+ {
+ return null;
+ }
+
+ try
+ {
+ return DateTime.Parse(str);
+ }
+ catch
+ {
+ }
+
+ if (str.Contains("年") && str.Contains("月") && str.Contains("日") && !str.Contains("周"))
+ str = str.Replace("年", "-").Replace("月", "-").Replace("日", "").Replace("时", ":").Replace("分", ":").Replace("秒", "").Trim(' ', ':');
+ if (str.Contains("-") || str.Contains("/"))
+ {
+ return DateTime.Parse(str);
+ }
+ else
+ {
+ int length = str.Length;
+ switch (length)
+ {
+ case 4:
+ return DateTime.ParseExact(str, "yyyy", System.Globalization.CultureInfo.CurrentCulture);
+ case 6:
+ return DateTime.ParseExact(str, "yyyyMM", System.Globalization.CultureInfo.CurrentCulture);
+ case 8:
+ return DateTime.ParseExact(str, "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture);
+ case 10:
+ return DateTime.ParseExact(str, "yyyyMMddHH", System.Globalization.CultureInfo.CurrentCulture);
+ case 12:
+ return DateTime.ParseExact(str, "yyyyMMddHHmm", System.Globalization.CultureInfo.CurrentCulture);
+ case 14:
+ return DateTime.ParseExact(str, "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture);
+ default:
+ return DateTime.ParseExact(str, "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture);
+ }
+ }
+ }
+ catch
+ {
+ return null;
+ }
+ }
+
+ ///
+ /// 将string转换为DateTime,若转换失败,则返回日期最小值。不抛出异常。
+ ///
+ ///
+ ///
+ public static DateTime ParseToDateTime(this string str)
+ {
+ try
+ {
+ if (string.IsNullOrWhiteSpace(str))
+ {
+ return DateTime.MinValue;
+ }
+ if (str.Contains("-") || str.Contains("/"))
+ {
+ return DateTime.Parse(str);
+ }
+ else
+ {
+ int length = str.Length;
+ switch (length)
+ {
+ case 4:
+ return DateTime.ParseExact(str, "yyyy", System.Globalization.CultureInfo.CurrentCulture);
+ case 6:
+ return DateTime.ParseExact(str, "yyyyMM", System.Globalization.CultureInfo.CurrentCulture);
+ case 8:
+ return DateTime.ParseExact(str, "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture);
+ case 10:
+ return DateTime.ParseExact(str, "yyyyMMddHH", System.Globalization.CultureInfo.CurrentCulture);
+ case 12:
+ return DateTime.ParseExact(str, "yyyyMMddHHmm", System.Globalization.CultureInfo.CurrentCulture);
+ case 14:
+ return DateTime.ParseExact(str, "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture);
+ default:
+ return DateTime.ParseExact(str, "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture);
+ }
+ }
+ }
+ catch
+ {
+ return DateTime.MinValue;
+ }
+ }
+
+ ///
+ /// 将string转换为DateTime,若转换失败,则返回默认值。
+ ///
+ ///
+ ///
+ ///
+ public static DateTime ParseToDateTime(this string str, DateTime? defaultValue)
+ {
+ try
+ {
+ if (string.IsNullOrWhiteSpace(str))
+ {
+ return defaultValue.GetValueOrDefault();
+ }
+ if (str.Contains("-") || str.Contains("/"))
+ {
+ return DateTime.Parse(str);
+ }
+ else
+ {
+ int length = str.Length;
+ switch (length)
+ {
+ case 4:
+ return DateTime.ParseExact(str, "yyyy", System.Globalization.CultureInfo.CurrentCulture);
+ case 6:
+ return DateTime.ParseExact(str, "yyyyMM", System.Globalization.CultureInfo.CurrentCulture);
+ case 8:
+ return DateTime.ParseExact(str, "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture);
+ case 10:
+ return DateTime.ParseExact(str, "yyyyMMddHH", System.Globalization.CultureInfo.CurrentCulture);
+ case 12:
+ return DateTime.ParseExact(str, "yyyyMMddHHmm", System.Globalization.CultureInfo.CurrentCulture);
+ case 14:
+ return DateTime.ParseExact(str, "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture);
+ default:
+ return DateTime.ParseExact(str, "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture);
+ }
+ }
+ }
+ catch
+ {
+ return defaultValue.GetValueOrDefault();
+ }
+ }
+ #endregion
+
+ #region 转换为string
+ ///
+ /// 将object转换为string,若转换失败,则返回""。不抛出异常。
+ ///
+ ///
+ ///
+ public static string ParseToString(this object obj)
+ {
+ try
+ {
+ if (obj == null)
+ {
+ return string.Empty;
+ }
+ else
+ {
+ if (obj is DateTime)
+ return (obj as DateTime?).Value.ToString("yyyy-MM-dd HH:mm:ss");
+ return obj.ToString();
+ }
+ }
+ catch
+ {
+ return string.Empty;
+ }
+ }
+
+ public static string ParseToNullableString(this object obj)
+ {
+ try
+ {
+ if (obj == null)
+ {
+ return null;
+ }
+ else
+ {
+ if (obj is DateTime)
+ return (obj as DateTime?).Value.ToString("yyyy-MM-dd HH:mm:ss");
+ return obj.ToString();
+ }
+ }
+ catch
+ {
+ return null;
+ }
+ }
+
+ public static string ParseToStrings(this object obj, string split = ",")
+ {
+ try
+ {
+ var list = obj as IEnumerable;
+ if (list != null)
+ {
+ return string.Join(split, list);
+ }
+ else
+ {
+ return obj.ToString();
+ }
+ }
+ catch
+ {
+ return string.Empty;
+ }
+ }
+ #endregion
+
+ #region 转换为double
+ ///
+ /// 将object转换为double,若转换失败,则返回0。不抛出异常。
+ ///
+ ///
+ ///
+ public static double ParseToDouble(this object obj)
+ {
+ try
+ {
+ return double.Parse(obj.ToString());
+ }
+ catch
+ {
+ return 0;
+ }
+ }
+
+ ///
+ /// 将object转换为double,若转换失败,则返回指定值。不抛出异常。
+ ///
+ ///
+ ///
+ ///
+ public static double ParseToDouble(this object str, double defaultValue)
+ {
+ try
+ {
+ return double.Parse(str.ToString());
+ }
+ catch
+ {
+ return defaultValue;
+ }
+ }
+ #endregion
+
+ #region 字符串转指定类型Array
+ public static T[] SplitToArray(this string value, string split = ",")
+ {
+ if (string.IsNullOrEmpty(value))
+ {
+ return default(T[]);
+ }
+ var arr = value.Split(new string[] { split }, StringSplitOptions.RemoveEmptyEntries).CastSuper().ToArray();
+ return arr;
+ }
+
+ public static T[] SplitToArray(this string value, string[] split)
+ {
+ if (string.IsNullOrEmpty(value))
+ {
+ return default(T[]);
+ }
+ var arr = value.Split(split, StringSplitOptions.RemoveEmptyEntries).CastSuper().ToArray();
+ return arr;
+ }
+ #endregion
+
+ #region 字符串转指定类型List
+ public static List SplitToList(this string value, string split = ",")
+ {
+ if (string.IsNullOrEmpty(value))
+ {
+ return new List();
+ }
+ var list = value.Split(new string[] { split }, StringSplitOptions.RemoveEmptyEntries).CastSuper().ToList();
+ return list;
+ }
+
+ public static List SplitToList(this string value, string[] split)
+ {
+ if (string.IsNullOrEmpty(value))
+ {
+ return new List();
+ }
+ var list = value.Split(split, StringSplitOptions.RemoveEmptyEntries).CastSuper().ToList();
+ return list;
+ }
+ #endregion
+
+ #region 强制转换类型
+ ///
+ /// 强制转换类型
+ ///
+ ///
+ ///
+ ///
+ public static IEnumerable CastSuper(this IEnumerable source)
+ {
+ foreach (object item in source)
+ {
+ yield return (TResult)Convert.ChangeType(item, typeof(TResult));
+ }
+ }
+ #endregion
+
+ #region Object转换为Json
+ public static string ParseToJson(this object obj)
+ {
+ return JsonConvert.SerializeObject(obj);
+ }
+ #endregion
+
+ #region Json转为Object
+ public static T ParseToObject(this string json)
+ {
+ if (string.IsNullOrEmpty(json))
+ {
+ return Activator.CreateInstance();
+ }
+ return JsonConvert.DeserializeObject(json);
+ }
+ #endregion
+
+ #region 深拷贝(克隆出一个新对象,拷贝对象里面的数据和子对象)
+ public static T DeepClone(this T o)
+ {
+ return o.ParseToJson().ParseToObject();
+ // 这种方式在用 Obfuscator 的时候有问题
+ //using (MemoryStream stream = new MemoryStream())
+ //{
+ // BinaryFormatter formatter = new BinaryFormatter();
+ // formatter.Serialize(stream, o);
+ // stream.Position = 0;
+ // return (T)formatter.Deserialize(stream);
+ //}
+ }
+ #endregion
+
+ #region 浅拷贝(拷贝对象里面的数据[property and field],但不拷贝对象里面的子对象)
+ public static void ShadowClone(this T1 source, ref T2 destination)
+ {
+ var sourceMembers = ReflectionHelper.GetMembers(source.GetType());
+ var destinationMembers = ReflectionHelper.GetMembers(destination.GetType());
+
+ // Copy data from source to destination
+ foreach (var sourceMember in sourceMembers)
+ {
+ if (!ReflectionHelper.CanRead(sourceMember))
+ {
+ continue;
+ }
+ var destinationMember = destinationMembers.FirstOrDefault(x => x.Name.ToLower() == sourceMember.Name.ToLower());
+ if (destinationMember == null || !ReflectionHelper.CanWrite(destinationMember))
+ {
+ continue;
+ }
+ ReflectionHelper.SetObjectValue(ref destination, destinationMember, ReflectionHelper.GetMemberValue(source, sourceMember));
+ }
+ }
+ #endregion
+ }
+}
diff --git a/StoreHub.KJDWebService/Commons/Extension/Extension.Enum.cs b/StoreHub.KJDWebService/Commons/Extension/Extension.Enum.cs
new file mode 100644
index 0000000..707f49a
--- /dev/null
+++ b/StoreHub.KJDWebService/Commons/Extension/Extension.Enum.cs
@@ -0,0 +1,114 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+using System.Threading.Tasks;
+using Newtonsoft.Json;
+
+namespace NaiBa.Util.Extension
+{
+ public static partial class Extensions
+ {
+ #region 枚举成员转成dictionary类型
+ ///
+ /// 转成dictionary类型
+ ///
+ ///
+ ///
+ public static Dictionary EnumToDictionary(this Type enumType)
+ {
+ Dictionary dictionary = new Dictionary();
+ Type typeDescription = typeof(DescriptionAttribute);
+ FieldInfo[] fields = enumType.GetFields();
+ int sValue = 0;
+ string sText = string.Empty;
+ foreach (FieldInfo field in fields)
+ {
+ if (field.FieldType.IsEnum)
+ {
+ sValue = ((int)enumType.InvokeMember(field.Name, BindingFlags.GetField, null, null, null));
+ object[] arr = field.GetCustomAttributes(typeDescription, true);
+ if (arr.Length > 0)
+ {
+ DescriptionAttribute da = (DescriptionAttribute)arr[0];
+ sText = da.Description;
+ }
+ else
+ {
+ sText = field.Name;
+ }
+ dictionary.Add(sValue, sText);
+ }
+ }
+ return dictionary.OrderBy(p => p.Key).ToDictionary(p => p.Key, p => p.Value);
+ }
+
+ ///
+ /// 枚举成员转成键值对Json字符串
+ ///
+ ///
+ ///
+ public static string EnumToDictionaryString(this Type enumType)
+ {
+ List> dictionaryList = EnumToDictionary(enumType).ToList();
+ var sJson = JsonConvert.SerializeObject(dictionaryList);
+ return sJson;
+ }
+ #endregion
+
+ #region 根据类型获取枚举的描述
+ ///
+ /// 获取枚举值对应的描述
+ ///
+ ///
+ ///
+ public static string GetDescription(this System.Enum enumType)
+ {
+ FieldInfo EnumInfo = enumType.GetType().GetField(enumType.ToString());
+ if (EnumInfo != null)
+ {
+ DescriptionAttribute[] EnumAttributes = (DescriptionAttribute[])EnumInfo.GetCustomAttributes(typeof(DescriptionAttribute), false);
+ if (EnumAttributes.Length > 0)
+ {
+ return EnumAttributes[0].Description;
+ }
+ }
+ return enumType.ToString();
+ }
+ #endregion
+
+ #region 根据值获取枚举的描述
+ public static string GetDescriptionByEnum(this object obj)
+ {
+ var tEnum = System.Enum.Parse(typeof(T), obj.ParseToString()) as System.Enum;
+ var description = tEnum.GetDescription();
+ return description;
+ }
+ #endregion
+
+ #region 根据描述获取枚举值
+ public static int GetEnumValueByDescription(this string description)
+ {
+ Dictionary dict = typeof(T).EnumToDictionary();
+ int value = dict.Where(p => p.Value == description).Select(p => p.Key).FirstOrDefault();
+ return value;
+ }
+ #endregion
+
+ #region 根据枚举名称获取值
+ public static int GetEnumValueByName(this string name)
+ {
+ return (int)System.Enum.Parse(typeof(T), name);
+ }
+ #endregion
+
+ #region 根据枚举值获取名称
+ public static object GetEnumNameByValue(this int value)
+ {
+ return System.Enum.ToObject(typeof(T), value);
+ }
+ #endregion
+ }
+}
diff --git a/StoreHub.KJDWebService/Commons/Extension/Extension.Exception.cs b/StoreHub.KJDWebService/Commons/Extension/Extension.Exception.cs
new file mode 100644
index 0000000..11447f3
--- /dev/null
+++ b/StoreHub.KJDWebService/Commons/Extension/Extension.Exception.cs
@@ -0,0 +1,18 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace NaiBa.Util.Extension
+{
+ public static partial class Extensions
+ {
+ public static Exception GetOriginalException(this Exception ex)
+ {
+ if (ex.InnerException == null) return ex;
+
+ return ex.InnerException.GetOriginalException();
+ }
+ }
+}
diff --git a/StoreHub.KJDWebService/Commons/Extension/Extension.Linq.cs b/StoreHub.KJDWebService/Commons/Extension/Extension.Linq.cs
new file mode 100644
index 0000000..4eadb77
--- /dev/null
+++ b/StoreHub.KJDWebService/Commons/Extension/Extension.Linq.cs
@@ -0,0 +1,110 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Linq.Expressions;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace NaiBa.Util.Extension
+{
+ public static class LinqExtensions
+ {
+ public static Expression Property(this Expression expression, string propertyName)
+ {
+ return Expression.Property(expression, propertyName);
+ }
+ public static Expression AndAlso(this Expression left, Expression right)
+ {
+ return Expression.AndAlso(left, right);
+ }
+ public static Expression Call(this Expression instance, string methodName, params Expression[] arguments)
+ {
+ return Expression.Call(instance, instance.Type.GetMethod(methodName), arguments);
+ }
+ public static Expression GreaterThan(this Expression left, Expression right)
+ {
+ return Expression.GreaterThan(left, right);
+ }
+ public static Expression ToLambda(this Expression body, params ParameterExpression[] parameters)
+ {
+ return Expression.Lambda(body, parameters);
+ }
+
+ public static Expression> True() { return param => true; }
+
+ public static Expression> False() { return param => false; }
+
+ ///
+ /// 组合And
+ ///
+ ///
+ public static Expression> And(this Expression> first, Expression> second)
+ {
+ return first.Compose(second, Expression.AndAlso);
+ }
+ ///
+ /// 组合Or
+ ///
+ ///
+ public static Expression> Or(this Expression> first, Expression> second)
+ {
+ return first.Compose(second, Expression.OrElse);
+ }
+
+ ///
+ /// Combines the first expression with the second using the specified merge function.
+ ///
+ static Expression Compose(this Expression first, Expression second, Func merge)
+ {
+ var map = first.Parameters
+ .Select((f, i) => new { f, s = second.Parameters[i] })
+ .ToDictionary(p => p.s, p => p.f);
+ var secondBody = ParameterRebinder.ReplaceParameters(map, second.Body);
+ return Expression.Lambda(merge(first.Body, secondBody), first.Parameters);
+ }
+
+ ///
+ /// ParameterRebinder
+ ///
+ private class ParameterRebinder : ExpressionVisitor
+ {
+ ///
+ /// The ParameterExpression map
+ ///
+ readonly Dictionary map;
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The map.
+ ParameterRebinder(Dictionary map)
+ {
+ this.map = map ?? new Dictionary();
+ }
+ ///
+ /// Replaces the parameters.
+ ///
+ /// The map.
+ /// The exp.
+ /// Expression
+ public static Expression ReplaceParameters(Dictionary map, Expression exp)
+ {
+ return new ParameterRebinder(map).Visit(exp);
+ }
+ ///
+ /// Visits the parameter.
+ ///
+ /// The p.
+ /// Expression
+ protected override Expression VisitParameter(ParameterExpression p)
+ {
+ ParameterExpression replacement;
+
+ if (map.TryGetValue(p, out replacement))
+ {
+ p = replacement;
+ }
+ return base.VisitParameter(p);
+ }
+ }
+ }
+}
diff --git a/StoreHub.KJDWebService/Commons/Extension/Extension.Validate.cs b/StoreHub.KJDWebService/Commons/Extension/Extension.Validate.cs
new file mode 100644
index 0000000..161f7d0
--- /dev/null
+++ b/StoreHub.KJDWebService/Commons/Extension/Extension.Validate.cs
@@ -0,0 +1,119 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Microsoft.AspNetCore.Http;
+using NaiBa.Util.Helper;
+using Newtonsoft.Json.Linq;
+
+namespace NaiBa.Util.Extension
+{
+ public static partial class Extensions
+ {
+ public static bool IsNullOrEmpty(this object value)
+ {
+ if (value != null && !string.IsNullOrEmpty(value.ParseToString()))
+ {
+ return false;
+ }
+ else
+ {
+ return true;
+ }
+ }
+
+ public static bool IsNullOrZero(this object value)
+ {
+ if (value == null || string.IsNullOrEmpty(value.ParseToString()) || value.ParseToString().Trim() == "0")
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ public static bool IsNumericType(this object value)
+ {
+ if (value == null)
+ {
+ return false;
+ }
+ switch (Type.GetTypeCode(value.GetType()))
+ {
+ case TypeCode.Byte:
+ case TypeCode.SByte:
+ case TypeCode.UInt16:
+ case TypeCode.UInt32:
+ case TypeCode.UInt64:
+ case TypeCode.Int16:
+ case TypeCode.Int32:
+ case TypeCode.Int64:
+ case TypeCode.Decimal:
+ case TypeCode.Double:
+ case TypeCode.Single:
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ public static bool IsStringType(this object value)
+ {
+ if (value == null)
+ {
+ return false;
+ }
+ switch (Type.GetTypeCode(value.GetType()))
+ {
+ case TypeCode.String:
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ public static bool IsNumber(this string value)
+ {
+ return RegexHelper.IsNumber(value);
+ }
+
+ public static bool IsAlphabet(this string value)
+ {
+ return RegexHelper.IsAlphabet(value);
+ }
+
+ public static bool IsAlphabetOrNumber(this string value)
+ {
+ return RegexHelper.IsAlphabetOrNumber(value);
+ }
+
+ public static bool IsJson(this string value)
+ {
+ return JsonHelper.IsJson(value);
+ }
+
+ public static bool IsJTokenNullOrEmpty(this JToken token)
+ {
+ return (token == null) ||
+ (token.Type == JTokenType.Array && !token.HasValues) ||
+ (token.Type == JTokenType.Object && !token.HasValues) ||
+ (token.Type == JTokenType.String && token.ToString() == string.Empty) ||
+ (token.Type == JTokenType.Null);
+ }
+
+ public static bool IsAjaxRequest(this Microsoft.AspNetCore.Http.HttpRequest request)
+ {
+ if (request == null)
+ throw new ArgumentNullException("request");
+
+ if (request.Headers != null)
+ return request.Headers["X-Requested-With"] == "XMLHttpRequest";
+ return false;
+ }
+ }
+}
+
+
diff --git a/StoreHub.KJDWebService/Commons/Helper/HtmlHelper.cs b/StoreHub.KJDWebService/Commons/Helper/HtmlHelper.cs
new file mode 100644
index 0000000..658dbaa
--- /dev/null
+++ b/StoreHub.KJDWebService/Commons/Helper/HtmlHelper.cs
@@ -0,0 +1,215 @@
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Linq;
+using System.Net;
+using System.Text;
+using System.Text.RegularExpressions;
+using System.Threading.Tasks;
+using NaiBa.Util.Extension;
+
+namespace NaiBa.Util.Helper
+{
+ public class HtmlHelper
+ {
+ public static string HtmlEncode(string html)
+ {
+ if (string.IsNullOrEmpty(html))
+ {
+ return string.Empty;
+ }
+ else
+ {
+ return WebUtility.HtmlEncode(html);
+ }
+ }
+
+ public static string HtmlDecode(string url)
+ {
+ if (string.IsNullOrEmpty(url))
+ {
+ return string.Empty;
+ }
+ else
+ {
+ return WebUtility.HtmlDecode(url);
+ }
+ }
+
+ ///
+ /// Unicode解码
+ ///
+ ///
+ ///
+ public static string UnicodeDecode(string html)
+ {
+ html = WebUtility.HtmlDecode(html);
+
+ Regex reUnicode = new Regex(@"\\u([0-9a-fA-F]{4})", RegexOptions.Compiled);
+ return reUnicode.Replace(html, m =>
+ {
+ short c;
+ if (short.TryParse(m.Groups[1].Value, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out c))
+ {
+ return "" + (char)c;
+ }
+ return m.Value;
+ });
+ }
+
+ #region Resove
+ public static string Resove(string html, string prefix, string subfix = "")
+ {
+ int inl = html.IndexOf(prefix);
+ if (inl == -1)
+ {
+ prefix = prefix.Replace("\"", "'");
+ subfix = subfix.Replace("\"", "'");
+ inl = html.IndexOf(prefix);
+ }
+ if (inl == -1)
+ {
+ return null;
+ }
+ inl += prefix.Length;
+ if (!string.IsNullOrEmpty(subfix))
+ {
+ int inl2 = html.IndexOf(subfix, inl);
+ if (inl2 == -1)
+ {
+ return null;
+ }
+ string result = html.Substring(inl, inl2 - inl);
+ return result;
+ }
+ else
+ {
+ string result = html.Substring(inl);
+ return result;
+ }
+ }
+ #endregion
+
+ #region ResoveReverse
+ public static string ResoveReverse(string html, string subfix, string prefix)
+ {
+ int inl = html.IndexOf(subfix);
+ if (inl == -1)
+ {
+ return null;
+ }
+ string subString = html.Substring(0, inl);
+ int inl2 = subString.LastIndexOf(prefix);
+ if (inl2 == -1)
+ {
+ return null;
+ }
+ string s = subString.Substring(inl2 + prefix.Length, subString.Length - inl2 - prefix.Length);
+ return s;
+ }
+ #endregion
+
+ #region ResoveList
+ public static List ResoveList(string html, string prefix, string subfix)
+ {
+ List list = new List();
+ int index = 0;
+ do
+ {
+ index = html.IndexOf(prefix, index);
+ if (index == -1)
+ {
+ break;
+ }
+ index += prefix.Length;
+ int indexEnd = html.IndexOf(subfix, index);
+ if (indexEnd > 0)
+ {
+ string content = html.Substring(index, indexEnd - index);
+ list.Add(content);
+ }
+ index = indexEnd;
+ }
+ while (index > -1);
+ return list;
+ }
+ #endregion
+
+ #region ResoveListByAT
+ public static List ResoveListByAT(string html)
+ {
+ List list = new List();
+
+ int index = html.IndexOf('@');
+ while (index > 0)
+ {
+ int indexx = html.LastIndexOf("'", index); //向前一个单引号
+ int indexy = html.IndexOf("'", index + 1); //向后一个单引号
+ string s78 = html.Substring(indexx, indexy - indexx);
+ s78 = s78.Replace("'", "");
+ list.Add(s78);
+ index = html.IndexOf('@', indexy);
+ }
+ return list;
+ }
+ #endregion
+
+ ///
+ /// 清除HTML代码
+ ///
+ ///
+ public static string ClearHtml(string html)
+ {
+ html = html.ParseToString();
+ html = Regex.Replace(html, @"(|||)", ""), "(<[^>]*?>)", "").Trim();
+ }
+ ///
+ /// 清除HTML代码
+ ///
+ ///
+ /// 返回文字内容
+ public static void ClearHtmlX(ref string HtmlString)
+ {
+ if (string.IsNullOrEmpty(HtmlString))
+ {
+ //LogSave.Add("匹配正则发生错误:原始字符串为空");
+ return;
+ }
+ HtmlString = Regex.Replace(Regex.Replace(HtmlString,
+ @"(|)");
+ h = Clear(h, @"(