| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- using System;
- using System.Configuration;
- namespace BeiJingComService.Infrastructure
- {
- public static class AppConfig
- {
- // ===== HTTP 通道 =====
- public static int HttpPort => GetInt("HttpPort", 5001);
- public static int MaxRequestSize => GetInt("MaxRequestSize", 4194304);
- public static string AccessToken => Get("AccessToken", "");
- public static string CorsAllowOrigin => Get("CorsAllowOrigin", "*");
- // ===== 本地 COM(首信医保 MedicareCom.Outpatient) =====
- /// <summary>COM 组件 ProgID,首信医保为 MedicareCom.Outpatient。</summary>
- public static string ComProgId => Get("ComProgId", "MedicareCom.Outpatient");
- /// <summary>次要 COM 组件 ProgID(中药订单共享 EachCommunicationCom.Outpatient);留空表示不启用。</summary>
- public static string ComProgIdSecondary => Get("ComProgIdSecondary", "");
- /// <summary>单笔 COM 调用超时(毫秒)。</summary>
- public static int ComTimeoutMs => GetInt("ComTimeoutMs", 60000);
- /// <summary>
- /// COM 会话空闲关阈值(毫秒):队列空闲超过该时间即主动 close,实现"用完即关"。
- /// 阈值越小读卡器释放越及时;小于该阈值的连续读卡仍复用会话(更快)。
- /// </summary>
- public static int ComIdleTimeoutMs => GetInt("ComIdleTimeoutMs", 2000);
- /// <summary>
- /// Round59:未插卡(0xfffffffe)返回耗时超过该值(毫秒)即判定读卡器亚健康,主动关闭会话。
- /// 默认 2000,0 = 禁用(回到只有空闲关闭的老逻辑)。
- /// 依据:三天日志 18 次未插卡中,返回 <1 秒的 10 次全部平安,
- /// 返回 >3 秒的 7 次里 2 次紧接 f8、3 次导致 close 失败。
- /// </summary>
- public static int NoCardSlowCloseMs => GetInt("NoCardSlowCloseMs", 2000);
- // ===== COM 弹框置顶(Round57) =====
- /// <summary>
- /// 总开关。false = 不装 CBT 钩子、不起看门狗,完全恢复 1.0.0.3 的弹框行为(一级回滚开关)。
- /// </summary>
- public static bool ComDialogTopmost => GetBool("ComDialogTopmost", true);
- /// <summary>看门狗轮询间隔(毫秒);0 = 只留钩子、不启用看门狗。</summary>
- public static int ComDialogTopmostWatchMs => GetInt("ComDialogTopmostWatchMs", 200);
- /// <summary>
- /// true = 弹框出现时额外抢前台焦点(AttachThreadInput + SetForegroundWindow)。
- /// 默认关:抢焦点会打断操作员正在输入的窗口;置顶本身不需要焦点。
- /// </summary>
- public static bool ComDialogForeground => GetBool("ComDialogForeground", false);
- /// <summary>
- /// 只置顶这些窗口类名(逗号分隔),留空 = 不限类名(推荐)。
- /// 仅作现场排障的收窄手段;不要默认填 "#32770"(VB6 窗体类名不是它)。
- /// </summary>
- public static string ComDialogTopmostClasses => Get("ComDialogTopmostClasses", "");
- // ===== 扫码预捕获(Round54) =====
- /// <summary>
- /// 总开关。false 时完全不装低级键盘钩子;/api/scan/take 仍可访问但恒返回未命中。
- /// 现场遇到安全软件拦截钩子时改这里,重启生效。
- /// </summary>
- public static bool ScanCaptureEnabled => GetBool("ScanCaptureEnabled", true);
- /// <summary>
- /// 捕获码的存活时间(毫秒)。业务侧取用时超过该时间视为过期。
- /// 等待弹框实测最长约 1 秒,默认 5000 已留 5 倍余量;建议 3000~8000,不要超过 10000。
- /// </summary>
- public static int ScanCaptureTtlMs => GetInt("ScanCaptureTtlMs", 5000);
- /// <summary>
- /// 判定「这是扫码枪」的主判据:整串从首字符到回车的最大总耗时(毫秒)。
- /// 人工敲 18 位身份证最快也要 1.5 秒以上,300ms 足以区分。
- /// </summary>
- public static int ScanCaptureMaxDurationMs => GetInt("ScanCaptureMaxDurationMs", 300);
- /// <summary>判定:相邻字符最大间隔(毫秒),超过即清空重来。</summary>
- public static int ScanCaptureMaxKeyGapMs => GetInt("ScanCaptureMaxKeyGapMs", 50);
- /// <summary>判定:有效串最小长度。</summary>
- public static int ScanCaptureMinLength => GetInt("ScanCaptureMinLength", 8);
- // ===== 宿主 =====
- public static string ServiceName => Get("ServiceName", "BeiJingComService");
- public static bool AutoStart => GetBool("AutoStart", true);
- // ===== 日志 =====
- public static string LogDirectory => Get("LogDirectory", "Log");
- public static int LogRetainDays => GetInt("LogRetainDays", 30);
- // ===== 调用原文日志 =====
- /// <summary>是否把每次调用的入参/出参原文写入 yyyy-MM-dd_Trade.log。关闭后仍保留摘要日志。</summary>
- public static bool TradeLogEnabled => GetBool("TradeLogEnabled", true);
- /// <summary>原文落盘前是否按字段名脱敏(身份证、卡号、姓名、手机号等)。正式环境建议保持 true。</summary>
- public static bool TradeLogMaskSensitive => GetBool("TradeLogMaskSensitive", true);
- /// <summary>需脱敏的字段名,逗号分隔,不区分大小写。配置变更需重启程序生效。</summary>
- public static string TradeLogSensitiveFields => Get("TradeLogSensitiveFields", DEFAULT_SENSITIVE_FIELDS);
- /// <summary>单条原文最多落盘的字符数,0 表示不截断。</summary>
- public static int TradeLogMaxChars => GetInt("TradeLogMaxChars", 0);
- private const string DEFAULT_SENSITIVE_FIELDS =
- "xm,brxm,czyxm,name,sfzh,zjhm,idcard,identity,grbh,ylzh,sbzh,kh,cardno,card_no,sjhm,lxdh,phone,mobile,csrq,birthday,dz,address";
- private static string Get(string key, string defaultValue)
- {
- var value = ConfigurationManager.AppSettings[key];
- return string.IsNullOrWhiteSpace(value) ? defaultValue : value;
- }
- private static int GetInt(string key, int defaultValue)
- {
- var value = ConfigurationManager.AppSettings[key];
- if (string.IsNullOrWhiteSpace(value)) return defaultValue;
- if (!int.TryParse(value, out int result))
- throw new ConfigurationErrorsException($"AppSettings 配置项 {key} 不是有效的整数: {value}");
- return result;
- }
- private static bool GetBool(string key, bool defaultValue)
- {
- var value = ConfigurationManager.AppSettings[key];
- if (string.IsNullOrWhiteSpace(value)) return defaultValue;
- if (!bool.TryParse(value, out bool result))
- throw new ConfigurationErrorsException($"AppSettings 配置项 {key} 不是有效的布尔值: {value}");
- return result;
- }
- }
- }
|