Commit 10a039dc authored by 黄奎's avatar 黄奎

新增方法

parent b63c7b0c
...@@ -6,7 +6,6 @@ using System.Text.RegularExpressions; ...@@ -6,7 +6,6 @@ using System.Text.RegularExpressions;
namespace Edu.Common namespace Edu.Common
{ {
/// <summary> /// <summary>
/// 全局配置 /// 全局配置
/// </summary> /// </summary>
...@@ -72,17 +71,7 @@ namespace Edu.Common ...@@ -72,17 +71,7 @@ namespace Edu.Common
} }
return valueStr; return valueStr;
} }
/// <summary>
/// 获取配置
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public static string GetAppSetting(string key)
{
return ReadConfigKey(key);
}
/// <summary> /// <summary>
/// 异常日志保存路径 /// 异常日志保存路径
/// </summary> /// </summary>
...@@ -141,18 +130,7 @@ namespace Edu.Common ...@@ -141,18 +130,7 @@ namespace Edu.Common
return JwtExpirTime; return JwtExpirTime;
} }
} }
/// <summary>
/// 接口请求过期时间,单位为秒
/// </summary>
public static int ApiExpirTime
{
get
{
Int32.TryParse(ReadConfigKey("ApiExpirTime"), out int ApiExpirTime);
return ApiExpirTime;
}
}
/// <summary> /// <summary>
/// 阿里云oss域名 /// 阿里云oss域名
...@@ -229,7 +207,6 @@ namespace Edu.Common ...@@ -229,7 +207,6 @@ namespace Edu.Common
} }
} }
/// <summary> /// <summary>
/// 上传文件预览站点 /// 上传文件预览站点
/// </summary> /// </summary>
...@@ -241,22 +218,6 @@ namespace Edu.Common ...@@ -241,22 +218,6 @@ namespace Edu.Common
} }
} }
/// <summary>
/// 导出文件保存路径
/// </summary>
public static string FileExportPath
{
get
{
string fileExportPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ExportFile");
if (!Directory.Exists(fileExportPath))
{
Directory.CreateDirectory(fileExportPath);
}
return fileExportPath;
}
}
/// <summary> /// <summary>
/// 获取虚拟目录 /// 获取虚拟目录
/// </summary> /// </summary>
...@@ -290,17 +251,6 @@ namespace Edu.Common ...@@ -290,17 +251,6 @@ namespace Edu.Common
} }
} }
/// <summary>
/// App支付路径
/// </summary>
public static string APPPay
{
get
{
return "";
}
}
/// <summary> /// <summary>
/// 默认密码 /// 默认密码
/// </summary> /// </summary>
...@@ -308,6 +258,5 @@ namespace Edu.Common ...@@ -308,6 +258,5 @@ namespace Edu.Common
{ {
get { return "123456"; } get { return "123456"; }
} }
} }
} }
\ No newline at end of file
using System; namespace Edu.Common
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Edu.Common
{ {
/// <summary> /// <summary>
/// 全局Key管理 /// 全局Key管理
......
using System;
using System.Collections.Generic;
using System.IO;
using System.Xml.Serialization;
namespace Edu.Common.Plugin
{
/// <summary>
/// 公共帮助类
/// </summary>
public class CommonHelper
{
/// <summary>
/// 获取oss文件全路径地址
/// </summary>
/// <param name="fileList"></param>
/// <returns></returns>
public static List<string> GetOssFileFullPath(List<string> fileList)
{
List<string> resultFileList = new List<string>();
foreach (var item in fileList)
{
resultFileList.Add(Config.GetFileUrl(item));
}
return resultFileList;
}
/// <summary>
/// 根据出生日期判断人的类型
/// </summary>
/// <param name="birthDate">出生日期</param>
/// <returns></returns>
public static string CalculateAgeCorrect(DateTime birthDate)
{
DateTime now = DateTime.Now;
int age = now.Year - birthDate.Year;
if (now.Month < birthDate.Month || (now.Month == birthDate.Month && now.Day < birthDate.Day)) age--;
if (age < 2)
{
return "婴儿";
}
else if (2 <= age && age < 12)
{
return "小孩";
}
else
{
return "成人";
}
}
/// <summary>
/// 根据出生日期判断人的类型
/// </summary>
/// <param name="birthDate">出生日期</param>
/// <returns></returns>
public static int GetAgeCorrect(DateTime birthDate)
{
DateTime now = DateTime.Now;
int age = now.Year - birthDate.Year;
if (now.Month < birthDate.Month || (now.Month == birthDate.Month && now.Day < birthDate.Day))
{
age--;
}
if (age <= 11)
{
return 3;
}
else if (12 <= age && age < 18)
{
return 2;
}
else
{
return 1;
}
}
/// <summary>
/// 根据URL地址获取文件路径
/// </summary>
/// <param name="url">文件路劲</param>
/// <returns></returns>
public static string GetFilePath(string url)
{
string path = string.Empty;
try
{
Uri uri = new Uri(url);
path = uri.AbsolutePath;
}
catch
{
}
return path;
}
/// <summary>
/// 根据日期获取星期几
/// </summary>
/// <param name="date">日期</param>
/// <returns></returns>
public static int GetWeekNow(DateTime date)
{
string strWeek = date.DayOfWeek.ToString();
int weekDay = 0;
switch (strWeek)
{
case "Monday": weekDay = 1; break;
case "Tuesday": weekDay = 2; break;
case "Wednesday": weekDay = 3; break;
case "Thursday": weekDay = 4; break;
case "Friday": weekDay = 5; break;
case "Saturday": weekDay = 6; break;
case "Sunday": weekDay = 7; break;
}
return weekDay;
}
/// <summary>
/// 根据日期获取星期几
/// </summary>
/// <param name="date">日期</param>
/// <returns></returns>
public static string GetWeekDay(DateTime date)
{
string strWeek = date.DayOfWeek.ToString();
string weekDay ="";
switch (strWeek)
{
case "Monday": weekDay = "一"; break;
case "Tuesday": weekDay = "二"; break;
case "Wednesday": weekDay = "三"; break;
case "Thursday": weekDay = "四"; break;
case "Friday": weekDay = "五"; break;
case "Saturday": weekDay = "六"; break;
case "Sunday": weekDay = "日"; break;
}
return weekDay;
}
/// <summary>
/// 判断是否为时间格式
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static bool IsTime(string value)
{
bool flag = true;
try
{
Convert.ToDateTime("2019-01-01 " + value.Trim());
}
catch (Exception)
{
flag = false;
}
return flag;
}
/// <summary>
/// 时间格式化(dd+英文月+YY)
/// </summary>
/// <returns></returns>
public static string DateTimeFormat(DateTime dt)
{
string str = string.Empty;
try
{
int month = dt.Month;
switch (month)
{
case 1: str = dt.ToString("dd") + "Jan" + dt.Year.ToString().Substring(2); break;
case 2: str = dt.ToString("dd") + "Feb" + dt.Year.ToString().Substring(2); break;
case 3: str = dt.ToString("dd") + "Mar" + dt.Year.ToString().Substring(2); break;
case 4: str = dt.ToString("dd") + "Apr" + dt.Year.ToString().Substring(2); break;
case 5: str = dt.ToString("dd") + "May" + dt.Year.ToString().Substring(2); break;
case 6: str = dt.ToString("dd") + "Jun" + dt.Year.ToString().Substring(2); break;
case 7: str = dt.ToString("dd") + "Jul" + dt.Year.ToString().Substring(2); break;
case 8: str = dt.ToString("dd") + "Aug" + dt.Year.ToString().Substring(2); break;
case 9: str = dt.ToString("dd") + "Sept" + dt.Year.ToString().Substring(2); break;
case 10: str = dt.ToString("dd") + "Oct" + dt.Year.ToString().Substring(2); break;
case 11: str = dt.ToString("dd") + "Nov" + dt.Year.ToString().Substring(2); break;
case 12: str = dt.ToString("dd") + "Dec" + dt.Year.ToString().Substring(2); break;
}
}
catch
{
}
return str;
}
/// <summary>
/// 克隆对象
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="obj"></param>
/// <returns></returns>
public static T Clone<T>(T obj)
{
T ret = default;
if (obj != null)
{
XmlSerializer cloner = new XmlSerializer(typeof(T));
MemoryStream stream = new MemoryStream();
cloner.Serialize(stream, obj);
stream.Seek(0, SeekOrigin.Begin);
ret = (T)cloner.Deserialize(stream);
}
return ret;
}
}
}
\ No newline at end of file
...@@ -10,117 +10,14 @@ namespace Edu.Common ...@@ -10,117 +10,14 @@ namespace Edu.Common
/// <summary> /// <summary>
/// 类型转换帮助类 /// 类型转换帮助类
/// </summary> /// </summary>
public class ConvertHelper public static class ConvertHelper
{ {
/// <summary>
/// 转换字符流成字符串
/// </summary>
/// <param name="bytes"></param>
/// <returns></returns>
public static string ToString(byte[] bytes)
{
var sb = new StringBuilder(64);
foreach (byte iByte in bytes) sb.AppendFormat("{0:x2}", iByte);
return sb.ToString();
}
/// <summary>
/// 转换成Byte数组
/// </summary>
/// <param name="hexString"></param>
/// <returns></returns>
public static byte[] ToBytes(string hexString)
{
if (hexString == null) return null;
var data = new byte[hexString.Length / 2];
int h, l;
for (var i = 0; i < data.Length; i++)
{
h = (hexString[2 * i] > 57 ? hexString[2 * i] - 'A' + 10 : hexString[2 * i] - '0') << 4 & 0x000000F0;
l = (hexString[2 * i + 1] > 57 ? hexString[2 * i + 1] - 'A' + 10 : hexString[2 * i + 1] - '0') & 0x0000000F;
data[i] = (byte)(h | l);
}
return data;
}
/// <summary>
/// 类型转换
/// </summary>
/// <typeparam name="T">要转换类型</typeparam>
/// <param name="obj">要转换的值</param>
/// <returns></returns>
public static T ConvertTo<T>(object obj)
{
if (obj == null) return default;//返回默认值
Type tp = typeof(T);
//泛型Nullable判断,取其中的类型
if (tp.IsGenericType)
{
tp = tp.GetGenericArguments()[0];
}
//string直接返回转换
if (tp.Name.ToLower() == "string")
{
return (T)obj;
}
//反射获取TryParse方法
var TryParse = tp.GetMethod("TryParse", BindingFlags.Public | BindingFlags.Static, Type.DefaultBinder,
new Type[] { typeof(string), tp.MakeByRefType() },
new ParameterModifier[] { new ParameterModifier(2) });
var parameters = new object[] { obj, Activator.CreateInstance(tp) };
try
{
bool success = (bool)TryParse.Invoke(null, parameters);
//成功返回转换后的值,否则返回类型的默认值
if (success)
{
return (T)parameters[1];
}
return default;
}
catch
{
return default;
}
}
/// <summary>
/// 转Int
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public static int ConvertInt(object obj)
{
return ConvertTo<int>(obj);
}
/// <summary>
/// 转Int
/// </summary>
/// <param name="obj"></param>
/// <param name="defaultValue">默认值</param>
/// <returns></returns>
public static int ToInt(object obj, int defaultValue = 0)
{
int result = defaultValue;
if (obj != null)
{
Int32.TryParse(obj.ToString(), out result);
}
return result;
}
/// <summary> /// <summary>
/// 格式化时间【yyyy-MM-dd HH:mm:ss】 /// 格式化时间【yyyy-MM-dd HH:mm:ss】
/// </summary> /// </summary>
/// <param name="time"></param> /// <param name="time"></param>
/// <returns></returns> /// <returns></returns>
public static string FormatTime(object time) public static string FormatTime(this object time)
{ {
string timeStr = ""; string timeStr = "";
if (time != null) if (time != null)
......
using Newtonsoft.Json.Converters;
namespace Edu.Common.Plugin
{
/// <summary>
/// 格式化时间【yyyy-MM-dd HH:mm:ss】
/// </summary>
public class DateConvert : IsoDateTimeConverter
{
/// <summary>
/// 格式化时间
/// </summary>
public DateConvert()
{
base.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
}
}
/// <summary>
/// 格式化日期【yyyy-MM-dd】
/// </summary>
public class DateConvertTwo : IsoDateTimeConverter
{
/// <summary>
/// 格式化时间
/// </summary>
public DateConvertTwo()
{
base.DateTimeFormat = "yyyy-MM-dd";
}
}
}
...@@ -9,26 +9,6 @@ namespace Edu.Common.Plugin ...@@ -9,26 +9,6 @@ namespace Edu.Common.Plugin
/// </summary> /// </summary>
public static class EnumHelper public static class EnumHelper
{ {
/// <summary>
/// 获取枚举值集合
/// </summary>
/// <param name="enumType"></param>
/// <returns></returns>
public static Dictionary<string, string> GetEnumList(Type enumType)
{
Dictionary<string, string> dic = new Dictionary<string, string>();
FieldInfo[] fieldinfos = enumType.GetFields();
foreach (FieldInfo field in fieldinfos)
{
if (field.FieldType.IsEnum)
{
Object[] objs = field.GetCustomAttributes(typeof(EnumFieldAttribute), false);
dic.Add(((EnumFieldAttribute)objs[0]).Name, field.GetRawConstantValue().ToString());
}
}
return dic;
}
/// <summary> /// <summary>
/// 获取枚举列表 /// 获取枚举列表
/// </summary> /// </summary>
...@@ -54,41 +34,13 @@ namespace Edu.Common.Plugin ...@@ -54,41 +34,13 @@ namespace Edu.Common.Plugin
return list; return list;
} }
/// <summary>
/// 获取枚举值的名称
/// </summary>
/// <param name="e"></param>
/// <returns></returns>
public static string GetEnumName(object e)
{
if (e == null)
{
return "";
}
//获取字段信息
System.Reflection.FieldInfo[] ms = e.GetType().GetFields();
foreach (System.Reflection.FieldInfo f in ms)
{
//判断名称是否相等
if (f.Name != e.ToString()) continue;
//反射出自定义属性
object[] attrs = f.GetCustomAttributes(typeof(EnumFieldAttribute), true);
if (attrs.Length > 0)
{
EnumFieldAttribute attr = attrs[0] as EnumFieldAttribute;
return attr.Name;
}
}
return "";
}
/// <summary> /// <summary>
/// 获取枚举特性描述值 /// 获取枚举特性描述值
/// </summary> /// </summary>
/// <param name="obj"></param> /// <param name="obj"></param>
/// <returns></returns> /// <returns></returns>
public static string GetEnumName(this System.Enum obj) public static string ToName(this System.Enum obj)
{ {
if (obj == null) if (obj == null)
{ {
...@@ -123,28 +75,6 @@ namespace Edu.Common.Plugin ...@@ -123,28 +75,6 @@ namespace Edu.Common.Plugin
{ {
return Convert.ToInt32(obj); return Convert.ToInt32(obj);
} }
/// <summary>
/// 将值转成枚举
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="obj"></param>
/// <returns></returns>
public static T ToEnum<T>(this string obj) where T : struct
{
if (string.IsNullOrEmpty(obj))
{
return default;
}
try
{
return (T)System.Enum.Parse(typeof(T), obj, true);
}
catch (Exception)
{
return default;
}
}
} }
/// <summary> /// <summary>
......
using Edu.Common;
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Text;
namespace Edu.Common.Plugin
{
/// <summary>
/// 文件操作帮助类
/// </summary>
public class FileHelper
{
/// <summary>
/// 生成图片
/// </summary>
/// <param name="url"></param>
public static void CreateImage(string url)
{
string tempPath = GetFileUrl(url);
string path = Environment.CurrentDirectory + tempPath;//下载到的地址+文件名
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
//发送请求并获取相应回应数据
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
//直到request.GetResponse()程序才开始向目标网页发送Post请求
Stream responseStream = response.GetResponseStream();
string newFilePath = path.Substring(0, path.LastIndexOf("/"));
if (!System.IO.Directory.Exists(newFilePath))//如果不存在就创建file文件夹
{
System.IO.Directory.CreateDirectory(newFilePath);
}
//创建本地文件写入流
Stream stream = new FileStream(path, FileMode.Create);
byte[] bArr = new byte[1024];
int size = responseStream.Read(bArr, 0, (int)bArr.Length);
while (size > 0)
{
stream.Write(bArr, 0, size);
size = responseStream.Read(bArr, 0, (int)bArr.Length);
}
stream.Close();
responseStream.Close();
}
/// <summary>
/// 获取Oss文件全路径
/// </summary>
/// <param name="path">文件相对路径</param>
/// <returns></returns>
public static string GetFileUrl(string path)
{
return path.Replace("http://auth-zjhejiang-com.oss-cn-hangzhou.aliyuncs.com", "")
.Replace("https://cdnimg.iotweixin.com", "").Replace("http://img.weibaoge.cn","").Replace("http://v4test.zjhejiang.com","")
.Replace("http://v4test1.oss-cn-hangzhou.aliyuncs.com","").Replace("https://viitto-1301420277.cos.ap-chengdu.myqcloud.com","");
}
/// <summary>
/// 网站文件夹虚拟目录
/// </summary>
public static string VirtualDirectory = Config.VirtualDirectory;
/// <summary>
/// 行程特色删除指定文件夹文件
/// </summary>
/// <param name="filePath">文件夹路径</param>
public static void DeleteFile(string filePath)
{
string newPath = AppContext.BaseDirectory + "\\" + filePath;
DirectoryInfo theFolder = new DirectoryInfo(newPath);
if (theFolder.Exists)
{
FileSystemInfo[] files = theFolder.GetFileSystemInfos();
for (int i = 0; i < files.Length; i++)
{
//是文件
if (files[i] is FileInfo file)
{
file.Delete();
}
}
}
}
/// <summary>
/// 删除文件扩展方法
/// </summary>
/// <param name="filePath"></param>
public static void DeleteFileExt(string filePath)
{
string newPath = AppContext.BaseDirectory + "\\" + VirtualDirectory + filePath;
File.Delete(newPath);
}
/// <summary>
/// 根据TCID获取行程特色图片
/// </summary>
/// <param name="TCID"></param>
/// <returns></returns>
public static List<string> GetTripFileList(int TCID)
{
string filepath = VirtualDirectory + "/Feature/" + TCID + "/";
List<string> fileList = new List<string>();
DirectoryInfo theFolder = new DirectoryInfo(AppContext.BaseDirectory + "\\" + filepath);
if (!theFolder.Exists)
{
theFolder.Create();
}
FileSystemInfo[] files = theFolder.GetFileSystemInfos();
for (int i = 0; i < files.Length; i++)
{
//是文件
if (files[i] is FileInfo file)
{
fileList.Add(Config.ViewFileSiteUrl + "/Feature/" + TCID + "/" + file.Name);
}
}
return fileList;
}
/// <summary>
/// 批量删除文件
/// </summary>
/// <param name="fileList"></param>
public static void DeleteFileList(List<string> fileList)
{
foreach (var item in fileList)
{
string newPath = AppContext.BaseDirectory + "\\" + VirtualDirectory + item;
File.Delete(newPath);
}
}
/// <summary>
/// 文件移动
/// </summary>
/// <param name="filePath"></param>
/// <param name="newFilePath"></param>
public static void FileCopy(string filePath, string newFilePath)
{
string newTempFilePath = filePath.Substring(filePath.IndexOf("/")); ;
var strPath = AppContext.BaseDirectory + "\\" + VirtualDirectory + newTempFilePath; //System.Web.HttpContext.Current.Server.MapPath("~/" + VirtualDirectory + newTempFilePath);
string newfilePath = AppContext.BaseDirectory + "\\" + VirtualDirectory + newFilePath.Substring(0, strPath.LastIndexOf('\\') - 1); //System.Web.HttpContext.Current.Server.MapPath("~/" + VirtualDirectory) + newFilePath.Substring(0, strPath.LastIndexOf('\\') - 1);
if (!Directory.Exists(newfilePath))
{
Directory.CreateDirectory(newfilePath);
}
string sourceFile = AppContext.BaseDirectory + "\\" + VirtualDirectory + newTempFilePath;// System.Web.HttpContext.Current.Server.MapPath("~/" + VirtualDirectory + newTempFilePath);
string targetFile = AppContext.BaseDirectory + "\\" + VirtualDirectory + newFilePath;//System.Web.HttpContext.Current.Server.MapPath("~/" + VirtualDirectory + newFilePath);
File.Move(sourceFile, targetFile);
}
/// <summary>
/// 判断文件是否存在
/// </summary>
/// <param name="filePath"></param>
/// <returns></returns>
public static bool FileExists(string filePath)
{
return File.Exists(AppContext.BaseDirectory + "\\" + VirtualDirectory + filePath);
//return File.Exists(System.Web.HttpContext.Current.Server.MapPath("~/" + VirtualDirectory + filePath));
}
/// <summary>
/// 写byte[]到fileName
/// </summary>
/// <param name="fileName">保存至硬盘路径</param>
/// <param name="pReadByte">byte[]</param>
/// <returns></returns>
public static bool WriteByteToFile(string fileName, byte[] pReadByte)
{
FileStream pFileStream = null;
try
{
pFileStream = new FileStream(fileName, FileMode.OpenOrCreate);
pFileStream.Write(pReadByte, 0, pReadByte.Length);
}
catch
{
return false;
}
finally
{
if (pFileStream != null)
pFileStream.Close();
}
return true;
}
}
}
...@@ -183,4 +183,4 @@ namespace Edu.Common.Plugin ...@@ -183,4 +183,4 @@ namespace Edu.Common.Plugin
} }
} }
} }
} }
\ No newline at end of file
This diff is collapsed.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Web;
namespace Edu.Common.Plugin
{
/// <summary>
/// IP转化帮助类
/// </summary>
public class IPHelper
{
/// <summary>
/// 判断是否是IP地址
/// </summary>
/// <param name="ipAddress"></param>
/// <returns></returns>
private static bool IsIPAddress(string ipAddress)
{
if (string.IsNullOrEmpty(ipAddress))
{
return false;
}
ipAddress = ipAddress.Trim();
if (ipAddress.Length < 7 || ipAddress.Length > 15)
{
return false;
}
string pattern = @"^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$";
Regex regex = new Regex(pattern, RegexOptions.IgnoreCase);
return regex.IsMatch(ipAddress);
}
/// <summary>
/// 判断是否是内网IP
/// </summary>
/// <param name="ipAddress"></param>
/// <returns></returns>
private static bool IsInnerIP(String ipAddress)
{
long ipNum = GetIpNum(ipAddress);
/***** ***** ***** ***** ***** *****
私有IP:
A类 10.0.0.0-10.255.255.255
B类 172.16.0.0-172.31.255.255
C类 192.168.0.0-192.168.255.255
还有127.0.0.1这个环回地址
***** ***** ***** ***** ***** *****/
long aBegin = GetIpNum("10.0.0.0");
long aEnd = GetIpNum("10.255.255.255");
long bBegin = GetIpNum("172.16.0.0");
long bEnd = GetIpNum("172.31.255.255");
long cBegin = GetIpNum("192.168.0.0");
long cEnd = GetIpNum("192.168.255.255");
bool isInnerIp = IsInner(ipNum, aBegin, aEnd) || IsInner(ipNum, bBegin, bEnd) || IsInner(ipNum, cBegin, cEnd) || ipAddress.Equals("127.0.0.1");
return isInnerIp;
}
/// <summary>
/// 获取IP地址
/// </summary>
/// <param name="ipAddress"></param>
/// <returns></returns>
private static long GetIpNum(String ipAddress)
{
String[] ip = ipAddress.Split('.');
long a = int.Parse(ip[0]);
long b = int.Parse(ip[1]);
long c = int.Parse(ip[2]);
long d = int.Parse(ip[3]);
long ipNum = a * 256 * 256 * 256 + b * 256 * 256 + c * 256 + d;
return ipNum;
}
/// <summary>
/// 判断是否是整数
/// </summary>
/// <param name="userIp"></param>
/// <param name="begin"></param>
/// <param name="end"></param>
/// <returns></returns>
private static bool IsInner(long userIp, long begin, long end)
{
return (userIp >= begin) && (userIp <= end);
}
}
}
\ No newline at end of file
using System; using System;
using System.Configuration;
using System.IO; using System.IO;
using System.Threading.Tasks; using System.Threading.Tasks;
......
using System; using System.Runtime.InteropServices;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
namespace Edu.Common.Plugin namespace Edu.Common.Plugin
{ {
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
namespace Edu.Common.Plugin
{
/// <summary>
/// 枚举帮助类
/// </summary>
public class RSAHelper
{
//Erp公钥
static readonly string TargetPublicKey = @"<RSAKeyValue><Modulus>qr3Hipzvvn9dsFn1juGEM5vHiYl4whHnJ7DFqC4ZVAotL0bRCZd7vWvPl53AJY9p8u2hNgPP3J6/I5NairyCiizW++8kCPue1Lpq9qc9ueBwij1bo5Sqi1nswpJsKyd9kOD5aOzqrnuhKTLYMZN9fkHl3L4wjpuVz1xlTgpYdxc=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>";
//小程序私钥
//static string PublicKey = @"<RSAKeyValue><Modulus>4W8WliHbSkVE20kIze0KvCIOJgwG4PSRHHb6LNjc3smttrU952pGFi7g7dly1tj+oNUpCB5Ba5a1EUQI9vlfCXUYRICdiNneW6T78BFED5x8HZp8JUCMeatD8wFrKPVV4twaj2QtqGsTw60ZVmVFzHi/eNLVBYvfnzKCGCp0dG8=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>";
static readonly string PrivateKey = @"<RSAKeyValue><Modulus>4W8WliHbSkVE20kIze0KvCIOJgwG4PSRHHb6LNjc3smttrU952pGFi7g7dly1tj+oNUpCB5Ba5a1EUQI9vlfCXUYRICdiNneW6T78BFED5x8HZp8JUCMeatD8wFrKPVV4twaj2QtqGsTw60ZVmVFzHi/eNLVBYvfnzKCGCp0dG8=</Modulus><Exponent>AQAB</Exponent><P>97qvHs/ptDJiw+FGvqvNLOJX1TJPbed9sfNNEhAZe+x/XPQfnzu0IxEkIxH/BL29gVryWExH8b/ZcgQuXCpUsw==</P><Q>6PXZPVntcKdo4ZlbQAU/+VI47rAZGkNtW/w25UVGrVC31Zc3GSqCVlKZgccRe6/PLrjOUBKDRYiYd3Yj+azXVQ==</Q><DP>ciyzW3Md1jRGutrQHT7XUHF9Y8BNRW0kzGhDRCjxZeEpDjFhhaUhr+vNiPBZZdkBR2YgPbviiLQQRvFQYKAN6w==</DP><DQ>AgBSrG9AVe5qPT3nBcbFxOuK56oFnS8lGlwxUIjm0YhW+/O/mmy+D+XHwdCm+swI2Jrn0tJF5GwG+0e9iWCNvQ==</DQ><InverseQ>WsKgSM0RiMFpXGoyL8bqZi2q1MAB+iz4WXPcL/OmHKluo8wuK/Pk+zOKkyjMO91tKXhjLOd7xpVb1AIsk/fAeQ==</InverseQ><D>daiCNFd1WZ0vo/fJZZkLWke39LmgOXbL6fxa9F83X/wI82xC4+4+qENNWDZ+zo2w0AaRBNCtulaNKHbG6wgaRh15yuOHkr90oydquHHPUqCjFWnIEYx2NnX85HtyBTwowCeePajCTsEi6vMRgKlBCIFWxqc6z5To1lTgfqtKb8k=</D></RSAKeyValue>";
/// <summary>
/// 加密
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public static byte[] EncryptData(byte[] data)
{
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
//将公钥导入到RSA对象中,准备加密;
rsa.FromXmlString(TargetPublicKey);
//对数据data进行加密,并返回加密结果;
//第二个参数用来选择Padding的格式
byte[] buffer = rsa.Encrypt(data, false);
return buffer;
}
/// <summary>
/// 解密
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public static byte[] DecryptData(byte[] data)
{
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(1024);
//将私钥导入RSA中,准备解密;
rsa.FromXmlString(PrivateKey);
//对数据进行解密,并返回解密结果;
return rsa.Decrypt(data, false);
}
}
}
...@@ -5,25 +5,6 @@ using System.Text; ...@@ -5,25 +5,6 @@ using System.Text;
namespace Edu.Common.Plugin namespace Edu.Common.Plugin
{ {
/// <summary>
/// 加密方式
/// </summary>
public enum EncryptMode
{
/// <summary>
/// 不加密
/// </summary>
None = 0,
/// <summary>
/// 16位MD5 -- (常规)
/// </summary>
MD5_16 = 1,
/// <summary>
/// 32位MD5
/// </summary>
MD5_32 = 3
}
/// <summary> /// <summary>
/// 安全相关辅助类 /// 安全相关辅助类
/// </summary> /// </summary>
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
using NPOI.OpenXmlFormats.Wordprocessing; using NPOI.OpenXmlFormats.Wordprocessing;
using NPOI.XWPF.UserModel; using NPOI.XWPF.UserModel;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Edu.Common.Plugin namespace Edu.Common.Plugin
{ {
......
...@@ -96,5 +96,9 @@ namespace Edu.Model.Entity.Course ...@@ -96,5 +96,9 @@ namespace Edu.Model.Entity.Course
/// </summary> /// </summary>
public DateStateEnum Status { get; set; } public DateStateEnum Status { get; set; }
/// <summary>
/// 是否允许下载(1-允许,0-不允许)
/// </summary>
public int IsDownLoad { get; set; }
} }
} }
\ No newline at end of file
using System; using Edu.Common;
using System;
namespace Edu.Model.ViewModel.Course namespace Edu.Model.ViewModel.Course
{ {
...@@ -20,7 +21,7 @@ namespace Edu.Model.ViewModel.Course ...@@ -20,7 +21,7 @@ namespace Edu.Model.ViewModel.Course
{ {
get get
{ {
return Common.ConvertHelper.FormatTime(this.CreateTime); return this.CreateTime.FormatTime();
} }
} }
...@@ -36,7 +37,7 @@ namespace Edu.Model.ViewModel.Course ...@@ -36,7 +37,7 @@ namespace Edu.Model.ViewModel.Course
{ {
get get
{ {
return Common.ConvertHelper.FormatTime(this.UpdateTime); return this.UpdateTime.FormatTime();
} }
} }
} }
......
using System; using Edu.Common;
using System;
namespace Edu.Model.ViewModel.Course namespace Edu.Model.ViewModel.Course
{ {
...@@ -21,11 +22,11 @@ namespace Edu.Model.ViewModel.Course ...@@ -21,11 +22,11 @@ namespace Edu.Model.ViewModel.Course
/// <summary> /// <summary>
/// 创建时间字符串 /// 创建时间字符串
/// </summary> /// </summary>
public string CreateTimeStr { get { return Common.ConvertHelper.FormatTime(this.CreateTime); } } public string CreateTimeStr { get { return this.CreateTime.FormatTime();} }
/// <summary> /// <summary>
/// 更新时间 /// 更新时间
/// </summary> /// </summary>
public string UpdateTimeStr { get { return Common.ConvertHelper.FormatTime(this.UpdateTime); } } public string UpdateTimeStr { get { return this.UpdateTime.FormatTime(); } }
} }
} }
\ No newline at end of file
namespace Edu.Model.ViewModel.Question using Edu.Common;
namespace Edu.Model.ViewModel.Question
{ {
/// <summary> /// <summary>
/// 题目知识点视图实体类 /// 题目知识点视图实体类
...@@ -18,11 +20,11 @@ ...@@ -18,11 +20,11 @@
/// <summary> /// <summary>
/// 创建时间字符串 /// 创建时间字符串
/// </summary> /// </summary>
public string CreateTimeStr { get { return Common.ConvertHelper.FormatTime(this.CreateTime); } } public string CreateTimeStr { get { return this.CreateTime.FormatTime();} }
/// <summary> /// <summary>
/// 更新时间字符串 /// 更新时间字符串
/// </summary> /// </summary>
public string UpdateTimeStr { get { return Common.ConvertHelper.FormatTime(this.UpdateTime); } } public string UpdateTimeStr { get { return this.UpdateTime.FormatTime(); } }
} }
} }
using System.Collections.Generic; using Edu.Common;
using System.Collections.Generic;
namespace Edu.Model.ViewModel.Question namespace Edu.Model.ViewModel.Question
{ {
...@@ -20,12 +21,12 @@ namespace Edu.Model.ViewModel.Question ...@@ -20,12 +21,12 @@ namespace Edu.Model.ViewModel.Question
/// <summary> /// <summary>
/// 创建时间字符串 /// 创建时间字符串
/// </summary> /// </summary>
public string CreateTimeStr { get { return Common.ConvertHelper.FormatTime(this.CreateTime); } } public string CreateTimeStr { get { return this.CreateTime.FormatTime(); } }
/// <summary> /// <summary>
/// 更新时间字符串 /// 更新时间字符串
/// </summary> /// </summary>
public string UpdateTimeStr { get { return Common.ConvertHelper.FormatTime(this.UpdateTime); } } public string UpdateTimeStr { get { return this.UpdateTime.FormatTime(); } }
/// <summary> /// <summary>
/// 答案列表 /// 答案列表
......
using System; using Edu.Common;
using Edu.Common.Plugin;
using System;
namespace Edu.Model.ViewModel.User namespace Edu.Model.ViewModel.User
{ {
...@@ -26,7 +28,7 @@ namespace Edu.Model.ViewModel.User ...@@ -26,7 +28,7 @@ namespace Edu.Model.ViewModel.User
/// <summary> /// <summary>
/// 创建时间字符串 /// 创建时间字符串
/// </summary> /// </summary>
public string CreateTimeStr { get { return Common.ConvertHelper.FormatTime(this.CreateTime); } } public string CreateTimeStr { get { return this.CreateTime.FormatTime(); } }
/// <summary> /// <summary>
/// 更新人 /// 更新人
...@@ -36,11 +38,11 @@ namespace Edu.Model.ViewModel.User ...@@ -36,11 +38,11 @@ namespace Edu.Model.ViewModel.User
/// <summary> /// <summary>
/// 更新时间 /// 更新时间
/// </summary> /// </summary>
public string UpdateTimeStr { get { return Common.ConvertHelper.FormatTime(this.UpdateTime); } } public string UpdateTimeStr { get { return this.UpdateTime.FormatTime(); } }
/// <summary> /// <summary>
/// 审核状态字符串 /// 审核状态字符串
/// </summary> /// </summary>
public string AuditStatusStr { get { return Common.Plugin.EnumHelper.GetEnumName(this.AuditStatus); } } public string AuditStatusStr { get { return this.AuditStatus.ToName(); } }
} }
} }
\ No newline at end of file
using System; using Edu.Common;
using System;
namespace Edu.Model.ViewModel.User namespace Edu.Model.ViewModel.User
{ {
...@@ -20,7 +21,7 @@ namespace Edu.Model.ViewModel.User ...@@ -20,7 +21,7 @@ namespace Edu.Model.ViewModel.User
{ {
get get
{ {
return Common.ConvertHelper.FormatTime(this.CreateTime); return this.CreateTime.FormatTime();
} }
} }
...@@ -39,7 +40,7 @@ namespace Edu.Model.ViewModel.User ...@@ -39,7 +40,7 @@ namespace Edu.Model.ViewModel.User
{ {
get get
{ {
return Common.ConvertHelper.FormatTime(this.UpdateTime); return this.UpdateTime.FormatTime();
} }
} }
} }
......
using System; using Edu.Common;
using System;
namespace Edu.Model.ViewModel.User namespace Edu.Model.ViewModel.User
{ {
...@@ -16,7 +17,7 @@ namespace Edu.Model.ViewModel.User ...@@ -16,7 +17,7 @@ namespace Edu.Model.ViewModel.User
/// <summary> /// <summary>
/// 创建时间字符串 /// 创建时间字符串
/// </summary> /// </summary>
public string CreateTimeStr { get { return Common.ConvertHelper.FormatTime(this.CreateTime); } } public string CreateTimeStr { get { return this.CreateTime.FormatTime(); } }
/// <summary> /// <summary>
/// 更新人 /// 更新人
...@@ -26,6 +27,6 @@ namespace Edu.Model.ViewModel.User ...@@ -26,6 +27,6 @@ namespace Edu.Model.ViewModel.User
/// <summary> /// <summary>
/// 更新时间 /// 更新时间
/// </summary> /// </summary>
public string UpdateTimeStr { get { return Common.ConvertHelper.FormatTime(this.UpdateTime); } } public string UpdateTimeStr { get { return this.UpdateTime.FormatTime(); } }
} }
} }
using System; using Edu.Common;
using System;
namespace Edu.Model.ViewModel.User namespace Edu.Model.ViewModel.User
{ {
...@@ -25,7 +26,7 @@ namespace Edu.Model.ViewModel.User ...@@ -25,7 +26,7 @@ namespace Edu.Model.ViewModel.User
{ {
get get
{ {
return Common.ConvertHelper.FormatTime(this.CreateTime); return this.CreateTime.FormatTime();
} }
} }
...@@ -41,7 +42,7 @@ namespace Edu.Model.ViewModel.User ...@@ -41,7 +42,7 @@ namespace Edu.Model.ViewModel.User
{ {
get get
{ {
return Common.ConvertHelper.FormatTime(this.UpdateTime); return this.UpdateTime.FormatTime();
} }
} }
} }
......
using System; using Edu.Common;
using System;
namespace Edu.Model.ViewModel.User namespace Edu.Model.ViewModel.User
{ {
...@@ -16,7 +17,7 @@ namespace Edu.Model.ViewModel.User ...@@ -16,7 +17,7 @@ namespace Edu.Model.ViewModel.User
/// <summary> /// <summary>
/// 创建时间 /// 创建时间
/// </summary> /// </summary>
public string CreateTimeStr { get { return Common.ConvertHelper.FormatTime(this.CreateTime); } } public string CreateTimeStr { get { return this.CreateTime.FormatTime(); } }
/// <summary> /// <summary>
/// 修改人姓名 /// 修改人姓名
...@@ -26,7 +27,7 @@ namespace Edu.Model.ViewModel.User ...@@ -26,7 +27,7 @@ namespace Edu.Model.ViewModel.User
/// <summary> /// <summary>
/// 修改时间 /// 修改时间
/// </summary> /// </summary>
public string UpdateTimeStr { get { return Common.ConvertHelper.FormatTime(this.UpdateTime); } } public string UpdateTimeStr { get { return this.UpdateTime.FormatTime(); } }
/// <summary> /// <summary>
/// 禁用、启用字符串 /// 禁用、启用字符串
......
using System; using Edu.Common;
using Edu.Common.Plugin;
using System;
namespace Edu.Model.ViewModel.User namespace Edu.Model.ViewModel.User
{ {
...@@ -26,7 +28,7 @@ namespace Edu.Model.ViewModel.User ...@@ -26,7 +28,7 @@ namespace Edu.Model.ViewModel.User
/// <summary> /// <summary>
/// 创建时间 /// 创建时间
/// </summary> /// </summary>
public string CreateTimeStr { get { return Common.ConvertHelper.FormatTime(this.CreateTime); } } public string CreateTimeStr { get { return this.CreateTime.FormatTime(); } }
/// <summary> /// <summary>
/// 修改人 /// 修改人
...@@ -36,12 +38,12 @@ namespace Edu.Model.ViewModel.User ...@@ -36,12 +38,12 @@ namespace Edu.Model.ViewModel.User
/// <summary> /// <summary>
/// 修改时间 /// 修改时间
/// </summary> /// </summary>
public string UpdateTimeStr { get { return Common.ConvertHelper.FormatTime(this.UpdateTime); } } public string UpdateTimeStr { get { return this.UpdateTime.FormatTime(); } }
/// <summary> /// <summary>
/// 审核状态字符串 /// 审核状态字符串
/// </summary> /// </summary>
public string AuditStatusStr { get { return Common.Plugin.EnumHelper.GetEnumName(this.AuditStatus); } } public string AuditStatusStr { get { return this.AuditStatus.ToName(); } }
/// <summary> /// <summary>
/// 课程数量 /// 课程数量
......
...@@ -12,16 +12,12 @@ ...@@ -12,16 +12,12 @@
}, },
"JwtSecretKey": "@VIITTOREBORN*2018", "JwtSecretKey": "@VIITTOREBORN*2018",
"JwtExpirTime": 2592000, "JwtExpirTime": 2592000,
"ApiExpirTime": 2592000,
"AllowedHosts": "*", "AllowedHosts": "*",
"OpenValidation": "False", "OpenValidation": "False",
"UploadSiteUrl": "http://192.168.1.214:8120", "UploadSiteUrl": "http://192.168.1.214:8120",
"ViewFileSiteUrl": "https://viitto-1301420277.cos.ap-chengdu.myqcloud.com", "ViewFileSiteUrl": "https://viitto-1301420277.cos.ap-chengdu.myqcloud.com",
"ImKey": "b612b31e837c79c68f141aeb719d2b20",
"ImSecret": "66000451fb72",
"Mongo": "mongodb://47.96.25.130:27017", "Mongo": "mongodb://47.96.25.130:27017",
"MongoDBName": "Edu", "MongoDBName": "Edu",
"RabbitMqConfig": { "RabbitMqConfig": {
"HostName": "47.96.25.130", "HostName": "47.96.25.130",
"VirtualHost": "/", "VirtualHost": "/",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment