using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration.Json; using System; using System.IO; using System.Text.RegularExpressions; namespace Edu.Common { /// /// 全局配置 /// public class Config { /// /// 配置文件注入 /// public readonly static IConfiguration Configuration; static Config() { try { Configuration = new ConfigurationBuilder() .Add(new JsonConfigurationSource { Path = "appsettings.json", ReloadOnChange = true }) .Build(); } catch (Exception ex) { Common.Plugin.LogHelper.Write(ex, "Config"); } } /// /// 获取连接字符串 /// /// /// public static string GetConnectionString(string key) { try { return Configuration.GetConnectionString(key); } catch { return ""; } } /// /// 读取配置文件key的值 /// /// /// public static string ReadConfigKey(string key, string subKey = "") { string valueStr = ""; try { if (!string.IsNullOrWhiteSpace(subKey)) { valueStr = Configuration.GetSection(key)[subKey].ToString(); } else { valueStr = Configuration.GetSection(key).Value; } } catch { } return valueStr; } /// /// 异常日志保存路径 /// public static string LogPath { get { string logPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log/error"); return logPath.ToString(); } } /// /// 打印日志保存路径 /// public static string InofLogPath { get { string logPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log/info"); return logPath.ToString(); } } /// /// 接口请求日志保存路径 /// public static string RequestLogPath { get { string logPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log/request"); return logPath.ToString(); } } /// /// JWT加密秘钥 /// public static string JwtSecretKey { get { return ReadConfigKey("JwtSecretKey"); } } /// /// 过期时间,单位为秒 /// public static int JwtExpirTime { get { Int32.TryParse(ReadConfigKey("JwtExpirTime"), out int JwtExpirTime); return JwtExpirTime; } } /// /// 阿里云oss域名 /// public static string GetOssFileUrl { get { return ReadConfigKey("ViewFileSiteUrl"); } } public static string ErpViewFileSiteUrl { get { return ReadConfigKey("ErpViewFileSiteUrl"); } } public static string ErpUrl { get { return ReadConfigKey("ErpUrl"); } } /// /// 企业应用APP地址 /// public static string WorkAPPDomain { get { return ReadConfigKey("WorkAPPDomain"); } } /// /// 获取Oss文件全路径 /// /// 文件相对路径 /// public static string GetFileUrl(string path) { if (string.IsNullOrWhiteSpace(path)) { return null; } else { string p = @"(http|https)://(?[^(:|/]*)"; Regex reg = new Regex(p, RegexOptions.IgnoreCase); string value = reg.Match(path).Value; if (!string.IsNullOrEmpty(value)) { return path; } else { return GetOssFileUrl + path; } } } /// /// 获取erp站点图片 /// /// /// public static string GetErpFileUrl(string path) { if (string.IsNullOrWhiteSpace(path)) { return null; } else { string p = @"(http|https)://(?[^(:|/]*)"; Regex reg = new Regex(p, RegexOptions.IgnoreCase); string value = reg.Match(path).Value; if (!string.IsNullOrEmpty(value)) { return path; } else { return ErpViewFileSiteUrl + path; } } } /// /// 获取文件相对路径 /// public static string GetFilePath(string path) { if (!string.IsNullOrWhiteSpace(path)) { string p = @"(http|https)://(?[^(:|/]*)"; Regex reg = new Regex(p, RegexOptions.IgnoreCase); string value = reg.Match(path).Value; if (!string.IsNullOrEmpty(value)) { Uri url = new Uri(path); return url.AbsolutePath; } else { return path; } } else { return path; } } /// /// 上传站点地址 /// public static string UploadSiteUrl { get { return ReadConfigKey("UploadSiteUrl"); } } /// /// 获取wkhtmltopdf路径 /// public static string wkhtmltopdfConfig { get { return ReadConfigKey("WkHtmlToPdfPath"); } } /// /// 上传文件预览站点 /// public static string ViewFileSiteUrl { get { return ReadConfigKey("ViewFileSiteUrl"); } } /// /// 获取虚拟目录 /// public static string VirtualDirectory { get { return ReadConfigKey("VirtualDirectory"); } } /// /// Mongo连接地址 /// public static string Mongo { get { return ReadConfigKey("Mongo"); } } /// /// 获取MongoDBName /// public static string MongoDBName { get { return ReadConfigKey("MongoDBName"); } } /// /// 默认密码 /// public static string DefaultPwd { get { return "123456"; } } /// /// 是否线上 /// public static bool IsOnline { get { bool.TryParse(ReadConfigKey("IsOnline"), out bool _isOnline); return _isOnline; } } /// /// 是否发送短信 /// public static int IsSendMsg { get { int.TryParse(ReadConfigKey("IsSendMsg"), out int _isSendMsg); return _isSendMsg; } } /// /// 导出文件保存路径 /// public static string FileExportPath { get { string fileExportPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "/upfile/ExportFile"); if (!Directory.Exists(fileExportPath)) { Directory.CreateDirectory(fileExportPath); } return fileExportPath; } } /// /// 退课流程编号 /// public static int BackClassFlowId { get { int.TryParse(ReadConfigKey("BackClassFlowId"), out int BackClassFlowId); return BackClassFlowId; } } /// /// 调课流程编号 /// public static int ChangeClassFlowId { get { int.TryParse(ReadConfigKey("ChangeClassFlowId"), out int ChangeClassFlowId); return ChangeClassFlowId; } } /// /// 停课流程编号 /// public static int StopClassFlowId { get { int.TryParse(ReadConfigKey("StopClassFlowId"), out int StopClassFlowId); return StopClassFlowId; } } /// /// 临时上课邀请流程编号 /// public static int TempInvitationClassFlowId { get { int.TryParse(ReadConfigKey("TempInvitationClassFlowId"), out int TempInvitationClassFlowId); return TempInvitationClassFlowId; } } /// /// 订单转班流程编号 /// public static int OrderTransClassFlowId { get { int.TryParse(ReadConfigKey("OrderTransClassFlowId"), out int OrderTransClassFlowId); return OrderTransClassFlowId; } } /// /// 订单分拆流程编号 /// public static int OrderSplitClassFlowId { get { int.TryParse(ReadConfigKey("OrderSplitClassFlowId"), out int OrderSplitClassFlowId); return OrderSplitClassFlowId; } } /// /// 学生请假流程编号 /// public static int StudentLeaveFlowId { get { int.TryParse(ReadConfigKey("StudentLeaveFlowId"), out int StudentLeaveFlowId); return StudentLeaveFlowId; } } /// /// 组卷审批流程编号 /// public static int ZuJuanFlowId { get { int.TryParse(ReadConfigKey("ZuJuanFlowId"), out int ZuJuanFlowId); return ZuJuanFlowId; } } /// /// 考试申请流程编号 /// public static int ExamApplyFlowId { get { int.TryParse(ReadConfigKey("ExamApplyFlowId"), out int ExamApplyFlowId); return ExamApplyFlowId; } } /// /// 投稿审批流程编号 /// public static int ContributeFlowId { get { int.TryParse(ReadConfigKey("ContributeFlowId"), out int ContributeFlowId); return ContributeFlowId; } } /// /// okr关注事项配置 /// public static string OKRMatterValue { get { return ReadConfigKey("OKRMatterValue"); } } /// /// 分区校长岗位编号 /// public static int SchoolPostId { get { int.TryParse(ReadConfigKey("SchoolPostId"), out int SchoolPostId); return SchoolPostId; } } /// /// 教务长岗位编号 /// public static int JiaoWuZhang { get { int.TryParse(ReadConfigKey("JiaoWuZhang"), out int JiaoWuZhang); return JiaoWuZhang; } } /// /// 数字选择题前缀符号 /// public static string NumberQuestionChar { get { return "@"; } } /// /// 留学就业部门主管审核编号 /// public static int StudyAbroadDirectorId { get { int.TryParse(ReadConfigKey("StudyAbroadDirectorId"), out int studyAbroadDirectorId); return studyAbroadDirectorId; } } /// /// 留学就业部门负责人审核编号 /// public static int StudyAbroadManagerId { get { int.TryParse(ReadConfigKey("StudyAbroadManagerId"), out int studyAbroadManagerId); return studyAbroadManagerId; } } /// /// 获取合同默认抬头 /// public static string ContractDefaultTitle { get { return ReadConfigKey("ContractDefaultTitle"); } } /// /// 是否推送消息 /// public static int IsPushMessage { get { int.TryParse(ReadConfigKey("IsPushMessage"), out int IsPushMessage); return IsPushMessage; } } /// /// 超过下班时间多少分钟数不能打卡 /// public static int MoreThanMinutes { get { int.TryParse(ReadConfigKey("MoreThanMinutes"), out int MoreThanMinutes); return MoreThanMinutes; } } /// /// 连续缺课多少课时 /// public static int AbsentHours { get { int.TryParse(ReadConfigKey("AbsentHours"), out int AbsentHours); if (AbsentHours == 0) { AbsentHours = 12; } return AbsentHours; } } /// /// 消息推送AppId /// public static string PushAppId { get { return ReadConfigKey("PushAppId"); } } /// /// 收入单据 /// public static string IncomeFinanceApi { get { return ReadConfigKey("IncomeFinanceApi"); } } /// /// 微信结算率 /// public static string SettlementRate { get { return ReadConfigKey("SettlementRate"); } } /// /// 销售发放提成的前提比例 /// public static string SellCommissionFFBL { get { return ReadConfigKey("SellCommissionFFBL"); } } /// /// 收入请求加密 /// public static string FinanceKey { get { return ReadConfigKey("FinanceKey"); } } /// /// 微信支付成功回调地址 /// public static string sTenpayNotifyUrl { get { return ReadConfigKey("sTenpayNotifyUrl"); } } /// /// 微信退款成功回调地址 /// public static string sTenpayNotifyRefundUrl { get { return ReadConfigKey("sTenpayNotifyRefundUrl"); } } /// /// 甲鹤教育接口请求地址 /// public static string DmcMallApi { get { return ReadConfigKey("DmcMallApi"); } } /// /// 甲鹤教育商户id /// public static string JHTenantId { get { return ReadConfigKey("JHTenantId"); } } //JHMallUserOpenId /// /// 甲鹤教育固定用户OpenId /// public static string JHMallUserOpenId { get { return ReadConfigKey("JHMallUserOpenId"); } } /// /// 甲鹤教育小程序id /// public static string JHMallBaseId { get { return ReadConfigKey("JHMallBaseId"); } } /// /// 电商加密 /// public static string MallJwtSecretKey { get { return ReadConfigKey("MallJwtSecretKey"); } } /// /// 值班日期验证 /// public static DateTime DutyDate { get { DateTime.TryParse(ReadConfigKey("DutyDate"), out DateTime dt); return dt; } } /// /// 获取字母排序 /// public static string ClassNoLetterStr { get { return "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; } } /// /// 公告字典中的key /// public static string Notice_BaseKey { get { return ReadConfigKey("Notice_BaseKey"); } } /// /// 合同功能菜单code(学管) /// public static string EducationContractSchool { get { return ReadConfigKey("EducationContractSchool"); } } /// /// 合同功能菜单code(行政) /// public static string EducationContractAdmin { get { return ReadConfigKey("EducationContractAdmin"); } } /// /// 是否开启调课验证 /// public static int IsOpenChangeClassVerify { get { int.TryParse(ReadConfigKey("IsOpenChangeClassVerify"), out int IsOpenChangeClassVerify); return IsOpenChangeClassVerify; } } /// /// 甲鹤小程序AppId /// public static string AppID { get { return "wx38e054ee42b054f4"; } } /// /// 甲小鹤AppId /// public static string JiaXiaoHeAppId { get { return "wx0f4b451960f8ef29"; } } /// /// 甲小鹤AppSecret /// public static string JiaXiaoHeAppSecret { get { return "62332ef58d16280fc05613fc61ecff1d"; } } /// /// 甲鹤小程序AppSecret /// public static string AppSecret { get { return "d3ad4699265ba885ae2c8b65bf574ea5"; } } /// /// 微信小程序Api地址 /// public static string WechatApi { get { return "https://api.weixin.qq.com/"; } } /// /// 是否是本地服务器 /// public static int IsLocal { get { Int32.TryParse(ReadConfigKey("IsLocal"), out int _IsLocal); return _IsLocal; } } /// /// 临时访问小程序二维码Token /// public static string TempToken { get { return ReadConfigKey("TempToken"); } } /// /// 公众号的AppId /// public static string WeChatAccountAppId { get { return ReadConfigKey("WeChatAccountAppId"); } } /// /// 公众号的AppSecret /// public static string WeChatAccountAppSecret { get { return ReadConfigKey("WeChatAccountAppSecret"); } } } }