123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422 |
- using Microsoft.Win32;
- using Newtonsoft.Json.Linq;
- using System;
- using System.Diagnostics;
- using System.Drawing;
- using System.IO;
- using System.Net;
- using System.Text;
- using System.Windows.Forms;
- namespace ThCardReader
- {
- public partial class MainForm : Form
- {
- public static SiBusinessAddress address;
- private DateTime? _lastJiangSuClickTime = null; // 用于双击检测
- public MainForm()
- {
- InitializeComponent();
- CreateLogFolder();
- GetSiBusinessAddress();
- RestService service = new RestService();
- service.Start();
- Exec_CheckUpdate(true);
- }
- private void GetSiBusinessAddress()
- {
- try
- {
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://172.16.32.167:8077/readCard/getSiBusinessAddress");
- request.Proxy = null;
- request.KeepAlive = false;
- request.Method = "GET";
- request.ContentType = "application/json; charset=UTF-8";
- request.Timeout = 3000; // 3秒超时
- HttpWebResponse response = (HttpWebResponse)request.GetResponse();
- Stream myResponseStream = response.GetResponseStream();
- StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.UTF8);
- string retString = myStreamReader.ReadToEnd();
- myStreamReader.Close();
- myResponseStream.Close();
- if (response != null)
- {
- response.Close();
- }
- if (request != null)
- {
- request.Abort();
- }
- address = Newtonsoft.Json.JsonConvert.DeserializeObject<SiBusinessAddress>(retString);
- if (address.validFlag == 0)
- {
- SetDefaultAddress();
- }
- }
- catch (Exception ex)
- {
- // 网络连接失败时使用默认配置,让程序继续运行
- System.Diagnostics.Debug.WriteLine($"获取远程配置失败: {ex.Message},使用默认配置");
- SetDefaultAddress();
- }
- }
- private void SetDefaultAddress()
- {
- address = new SiBusinessAddress();
- address.readSiCardUrl = "https://scr.hun.hsip.gov.cn/hsa-hgs-adapt/api/card/initDll";
- address.readSiCardUser = "430105|10.93.28.229:80";
- address.readSiCardBuffSize = 2048;
- address.readIdCardUrl = "https://scr.hun.hsip.gov.cn/hsa-hgs-adapt/api/card/initDll";
- address.readIdCardUser = "430105|10.93.28.229:80";
- address.readIdCardBuffSize = 8192;
- address.readQrEcTokenUrl = "https://dvs.hun.hsip.gov.cn/localcfc/api/hsecfc/localQrCodeQuery";
- address.organizationId = "H43010500370";
- address.validFlag = 0;
- }
- private void HideForm()
- {
- this.WindowState = FormWindowState.Minimized;
- }
- private void CreateLogFolder()
- {
- string path = "D:\\读卡日志\\";
- if (!Directory.Exists(path))
- {
- Directory.CreateDirectory(path);
- if (!File.Exists("D:\\读卡日志\\ThyyBusiness.log"))
- {
- File.Create("D:\\读卡日志\\ThyyBusiness.log").Close();
- }
- }
- }
- private void MainForm_Load(object sender, EventArgs e)
- {
- RegistryKey registryKey = Registry.CurrentUser.OpenSubKey
- ("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
- registryKey.SetValue("ThCardReader", Application.ExecutablePath);
- }
- private void CheckUpdate(object sender, EventArgs e)
- {
- Exec_CheckUpdate(false);
- }
- private void Exec_CheckUpdate(Boolean fromLoad)
- {
- string currentVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
- string newVersion = GetVersion();
- if (currentVersion.Equals(newVersion))
- {
- if (!fromLoad)
- {
- MessageBox.Show("已经是最新版本。", String.Format("读卡插件-V{0}", currentVersion), MessageBoxButtons.OK);
- }
- }
- else
- {
- if (MessageBox.Show(String.Format("检查到新版本(V{0}),是否更新?", newVersion),
- String.Format("读卡插件-V{0}", currentVersion),
- MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
- {
- UpdateForm updateForm = new UpdateForm(newVersion);
- updateForm.Show();
- }
- }
- }
- private void ResetDriver(object sender, EventArgs e)
- {
- string path = Directory.GetCurrentDirectory();
- string logDir = path + "\\dlllog(Nation)";
- string driverDir = path + "\\SSCardDriver";
- DeleteFile(logDir);
- DeleteFile(driverDir);
- MessageBox.Show("删除驱动成功。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- private void DeleteFile(string path)
- {
- try
- {
- if (Directory.Exists(path))
- {
- foreach (string f in Directory.GetFileSystemEntries(path))
- {
- if (File.Exists(f))
- {
- File.Delete(f);
- }
- else
- {
- DeleteFile(f);
- }
- }
- Directory.Delete(path);
- }
- }
- catch (Exception e)
- {
- MessageBox.Show("程序出错:" + e.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- private void RestartProcess(object sender, EventArgs e)
- {
- Application.Restart();
- Environment.Exit(0);
- }
- private void ShutdownProcess(object sender, EventArgs e)
- {
- Process.GetCurrentProcess().Kill();
- }
- public static string GetVersion()
- {
- try
- {
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://webhis.thyy.cn:8080/download/readcard/version.txt");
- request.Proxy = null;
- request.KeepAlive = false;
- request.Method = "GET";
- request.ContentType = "application/json; charset=UTF-8";
- request.AutomaticDecompression = DecompressionMethods.GZip;
- request.Timeout = 3000; // 3秒超时
- HttpWebResponse response = (HttpWebResponse)request.GetResponse();
- Stream myResponseStream = response.GetResponseStream();
- StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.UTF8);
- string retString = myStreamReader.ReadToEnd();
- myStreamReader.Close();
- myResponseStream.Close();
- if (response != null)
- {
- response.Close();
- }
- if (request != null)
- {
- request.Abort();
- }
- return retString;
- }
- catch (Exception ex)
- {
- // 获取版本失败时返回当前版本,避免程序崩溃
- System.Diagnostics.Debug.WriteLine($"获取远程版本失败: {ex.Message}");
- return System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
- }
- }
- private void ShowMainForm(object sender, EventArgs e)
- {
- if (this.WindowState == FormWindowState.Minimized)
- {
- this.WindowState = FormWindowState.Normal;
- this.Show();
- }
- }
- private void ShowMainForm(object sender, MouseEventArgs e)
- {
- if (this.WindowState == FormWindowState.Minimized)
- {
- this.WindowState = FormWindowState.Normal;
- this.Show();
- }
- }
- private void TestSiCard(object sender, EventArgs e)
- {
- EnableAllButtons(false);
- ClearParamsDisplay();
-
- // 显示请求网址
- this.request_url_text.Text = "本地直接调用 - SsCardBusiness.ReadSiCard()";
-
- // 显示请求参数
- var requestParams = new { action = "ReadSiCard", device = "泰和SSCard.dll", type = "社保卡" };
- this.request_params_text.Text = Newtonsoft.Json.JsonConvert.SerializeObject(requestParams, Newtonsoft.Json.Formatting.Indented);
-
- JObject result = SsCardBusiness.ReadSiCard();
- this.result_text.Text = result.ToString();
-
- // 显示响应参数并设置状态颜色
- this.response_params_text.Text = result.ToString(Newtonsoft.Json.Formatting.Indented);
- SetStatusColor(result);
-
- EnableAllButtons(true);
- this.sicard_test.Focus();
- }
- private void TestIdCard(object sender, EventArgs e)
- {
- EnableAllButtons(false);
- ClearParamsDisplay();
-
- // 显示请求网址
- this.request_url_text.Text = "本地直接调用 - SsCardBusiness.ReadIdCard()";
-
- // 显示请求参数
- var requestParams = new { action = "ReadIdCard", device = "泰和SSCard.dll", type = "身份证" };
- this.request_params_text.Text = Newtonsoft.Json.JsonConvert.SerializeObject(requestParams, Newtonsoft.Json.Formatting.Indented);
-
- JObject result = SsCardBusiness.ReadIdCard();
- this.result_text.Text = result.ToString();
-
- // 显示响应参数并设置状态颜色
- this.response_params_text.Text = result.ToString(Newtonsoft.Json.Formatting.Indented);
- SetStatusColor(result);
-
- EnableAllButtons(true);
- this.idcard_test.Focus();
- }
- private void TestQrCode(object sender, EventArgs e)
- {
- EnableAllButtons(false);
- ClearParamsDisplay();
-
- // 显示请求网址
- this.request_url_text.Text = "本地直接调用 - NationalEcBusiness.ReadQrCode(\"01101\")";
-
- // 显示请求参数
- var requestParams = new { action = "ReadQrCode", device = "泰和NationECCode.dll", biztype = "01101", type = "电子凭证" };
- this.request_params_text.Text = Newtonsoft.Json.JsonConvert.SerializeObject(requestParams, Newtonsoft.Json.Formatting.Indented);
-
- JObject result = NationalEcBusiness.ReadQrCode("01101");
- this.result_text.Text = result.ToString();
-
- // 显示响应参数并设置状态颜色
- this.response_params_text.Text = result.ToString(Newtonsoft.Json.Formatting.Indented);
- SetStatusColor(result);
-
- EnableAllButtons(true);
- this.qrcode_test.Focus();
- }
- private void TestIdCard2(object sender, EventArgs e)
- {
- EnableAllButtons(false);
- ClearParamsDisplay();
-
- // 显示请求网址
- this.request_url_text.Text = "本地直接调用 - NationalEcBusiness.ReadIdCard(\"01101\")";
-
- // 显示请求参数
- var requestParams = new { action = "ReadIdCard", device = "泰和NationECCode.dll刷脸终端", biztype = "01101", type = "身份证" };
- this.request_params_text.Text = Newtonsoft.Json.JsonConvert.SerializeObject(requestParams, Newtonsoft.Json.Formatting.Indented);
-
- JObject result = NationalEcBusiness.ReadIdCard("01101");
- this.result_text.Text = result.ToString();
-
- // 显示响应参数并设置状态颜色
- this.response_params_text.Text = result.ToString(Newtonsoft.Json.Formatting.Indented);
- SetStatusColor(result);
-
- EnableAllButtons(true);
- this.id_card_test2.Focus();
- }
- private void TestQrCode2(object sender, EventArgs e)
- {
- EnableAllButtons(false);
- ClearParamsDisplay();
-
- // 显示请求网址
- this.request_url_text.Text = "本地直接调用 - NationalEcBusiness.ReadQrCode2(\"01101\")";
-
- // 显示请求参数
- var requestParams = new { action = "ReadQrCode2", device = "泰和NationECCode.dll刷脸终端", biztype = "01101", type = "电子凭证" };
- this.request_params_text.Text = Newtonsoft.Json.JsonConvert.SerializeObject(requestParams, Newtonsoft.Json.Formatting.Indented);
-
- JObject result = NationalEcBusiness.ReadQrCode2("01101");
- this.result_text.Text = result.ToString();
-
- // 显示响应参数并设置状态颜色
- this.response_params_text.Text = result.ToString(Newtonsoft.Json.Formatting.Indented);
- SetStatusColor(result);
-
- EnableAllButtons(true);
- this.qr_code_test2.Focus();
- }
- private void TestFace(object sender, EventArgs e)
- {
- EnableAllButtons(false);
- ClearParamsDisplay();
-
- // 显示请求网址
- this.request_url_text.Text = "本地直接调用 - NationalEcBusiness.ReadFace(\"01101\")";
-
- // 显示请求参数
- var requestParams = new { action = "ReadFace", device = "泰和NationECCode.dll刷脸终端", biztype = "01101", type = "刷脸" };
- this.request_params_text.Text = Newtonsoft.Json.JsonConvert.SerializeObject(requestParams, Newtonsoft.Json.Formatting.Indented);
-
- JObject result = NationalEcBusiness.ReadFace("01101");
- this.result_text.Text = result.ToString();
-
- // 显示响应参数并设置状态颜色
- this.response_params_text.Text = result.ToString(Newtonsoft.Json.Formatting.Indented);
- SetStatusColor(result);
-
- EnableAllButtons(true);
- this.face_test.Focus();
- }
- private void TestHuaShiIdCard(object sender, EventArgs e)
- {
- EnableAllButtons(false);
- ClearParamsDisplay();
-
- // 显示请求网址
- this.request_url_text.Text = "本地直接调用 - HuaShiIdCardBusiness.ReadIdCard()";
-
- // 显示请求参数
- var requestParams = new { action = "ReadIdCard", device = "华视Termb.dll", port = 1001 };
- this.request_params_text.Text = Newtonsoft.Json.JsonConvert.SerializeObject(requestParams, Newtonsoft.Json.Formatting.Indented);
-
- JObject result = HuaShiIdCardBusiness.ReadIdCard();
- this.result_text.Text = result.ToString();
-
- // 显示响应参数并设置状态颜色
- this.response_params_text.Text = result.ToString(Newtonsoft.Json.Formatting.Indented);
-
- // 华视读卡器没有专门的DLL错误信息,显示通用错误信息
- if (result["success"] != null && !(bool)result["success"])
- {
- this.dll_error_text.Text = result["message"]?.ToString() ?? "华视读卡器操作失败";
- this.dll_error_text.BackColor = System.Drawing.Color.FromArgb(255, 240, 240);
- this.dll_error_text.ForeColor = System.Drawing.Color.DarkRed;
- }
- else
- {
- this.dll_error_text.Text = "华视读卡器操作成功";
- this.dll_error_text.BackColor = System.Drawing.Color.FromArgb(220, 252, 231);
- this.dll_error_text.ForeColor = System.Drawing.Color.FromArgb(22, 101, 52);
- }
-
- SetStatusColor(result);
-
- EnableAllButtons(true);
- this.huashi_idcard_test.Focus();
- }
- /// <summary>
- /// 测试江苏医保读社保卡
- /// 单击:传统模式(显式初始化)
- /// 双击:测试新的autoInit智能模式
- /// </summary>
- private void TestJiangSuSiCard(object sender, EventArgs e)
- {
- EnableAllButtons(false);
- ClearParamsDisplay();
-
- // 检查是否是双击(测试autoInit功能)
- bool useAutoInitTest = false;
- var now = DateTime.Now;
- if (_lastJiangSuClickTime.HasValue && (now - _lastJiangSuClickTime.Value).TotalMilliseconds < 600)
- {
- useAutoInitTest = true;
- _lastJiangSuClickTime = null; // 重置
- }
- else
- {
- _lastJiangSuClickTime = now;
- // 如果是单击,稍等一下看是否有第二次点击
- if (!useAutoInitTest)
- {
- System.Threading.Thread.Sleep(100);
- }
- }
-
- try
- {
- // 使用写死的江苏医保参数先初始化
- var config = new JiangSuSocialCardBusiness.JiangSuConfig();
-
- // 显示江苏医保接口详细信息
- this.request_url_text.Text = GetJiangSuInterfaceInfo();
-
- // 显示请求参数
- var requestParams = new {
- action = useAutoInitTest ? "TestAutoInitMode" : "InitAndReadCard",
- device = "江苏医保HeaSecReadInfo.dll",
- testMode = useAutoInitTest ? "智能模式测试(autoInit=true)" : "传统模式+自动备选(保证成功)",
- clickType = useAutoInitTest ? "双击 - 测试autoInit参数" : "单击 - 传统显式初始化",
- step1 = useAutoInitTest ? "直接调用ReadSocialCard(false, true)" : "先尝试显式初始化",
- step2 = useAutoInitTest ? "自动处理初始化逻辑" : "再调用传统读卡方法",
- step3 = useAutoInitTest ? "失败时提供详细错误信息" : "失败时自动尝试离线模式",
- config = new {
- IP = config.IP,
- PORT = config.PORT,
- TIMEOUT = config.TIMEOUT,
- LOG_PATH = config.LOG_PATH,
- CARD_PASSTYPE = config.CARD_PASSTYPE,
- EC_URL = config.EC_URL,
- API_NAME = config.API_NAME,
- API_VERSION = config.API_VERSION,
- ACCESS_KEY = config.ACCESS_KEY,
- SECRETKEY = config.SECRETKEY,
- ORG_ID = config.ORG_ID,
- AREA_CODE = config.AREA_CODE,
- EXT = config.EXT
- }
- };
- this.request_params_text.Text = Newtonsoft.Json.JsonConvert.SerializeObject(requestParams, Newtonsoft.Json.Formatting.Indented);
- if (useAutoInitTest)
- {
- // 双击模式:测试autoInit智能功能
- var autoReadResult = JiangSuSocialCardBusiness.ReadSocialCard(false, true);
- this.result_text.Text = autoReadResult.ToString();
- this.response_params_text.Text = autoReadResult.ToString(Newtonsoft.Json.Formatting.Indented);
- SetStatusColor(autoReadResult);
- // 显示DLL原始错误信息
- if (autoReadResult["dllErrorMsg"] != null)
- {
- string dllError = autoReadResult["dllErrorMsg"].ToString();
- this.dll_error_text.Text = dllError;
- // 根据错误信息设置颜色
- if (string.IsNullOrEmpty(dllError))
- {
- this.dll_error_text.BackColor = System.Drawing.Color.FromArgb(220, 252, 231); // 浅绿色 - 成功
- this.dll_error_text.ForeColor = System.Drawing.Color.FromArgb(22, 101, 52);
- }
- else
- {
- this.dll_error_text.BackColor = System.Drawing.Color.FromArgb(255, 240, 240); // 浅红色 - 错误
- this.dll_error_text.ForeColor = System.Drawing.Color.DarkRed;
- }
- }
- // 更新原始数据显示
- UpdateDllRawDataInfo(autoReadResult);
- }
- else
- {
- // 单击模式:传统显式初始化 + 读卡
- var initResult = JiangSuSocialCardBusiness.Initialize(config);
- if ((bool)initResult["success"])
- {
- // 初始化成功,进行读卡
- var readResult = JiangSuSocialCardBusiness.ReadSocialCard(false, false); // 传统模式
- this.result_text.Text = readResult.ToString();
- this.response_params_text.Text = readResult.ToString(Newtonsoft.Json.Formatting.Indented);
- SetStatusColor(readResult);
- // 显示DLL原始错误信息
- if (readResult["dllErrorMsg"] != null)
- {
- string dllError = readResult["dllErrorMsg"].ToString();
- this.dll_error_text.Text = dllError;
- // 根据错误信息设置颜色
- if (string.IsNullOrEmpty(dllError))
- {
- this.dll_error_text.BackColor = System.Drawing.Color.FromArgb(220, 252, 231); // 浅绿色 - 成功
- this.dll_error_text.ForeColor = System.Drawing.Color.FromArgb(22, 101, 52);
- }
- else
- {
- this.dll_error_text.BackColor = System.Drawing.Color.FromArgb(255, 240, 240); // 浅红色 - 错误
- this.dll_error_text.ForeColor = System.Drawing.Color.DarkRed;
- }
- }
- // 更新原始数据显示
- UpdateDllRawDataInfo(readResult);
- }
- else
- {
- // 在线初始化失败,尝试新的智能模式和离线模式
- var autoInitResult = JiangSuSocialCardBusiness.ReadSocialCard(false, true); // 智能模式
- var offlineResult = JiangSuSocialCardBusiness.ReadSocialCardOffline(); // 离线模式
- // 创建合并结果显示三种尝试
- var combinedResult = new JObject();
- combinedResult["traditionalInitAttempt"] = initResult;
- combinedResult["smartModeAttempt"] = autoInitResult;
- combinedResult["offlineAttempt"] = offlineResult;
- combinedResult["recommendation"] = "在线初始化失败,已尝试智能模式和离线模式测试读卡功能";
- combinedResult["successfulMode"] = (bool)offlineResult["success"] ? "离线模式" :
- (bool)autoInitResult["success"] ? "智能模式" : "都失败";
- this.result_text.Text = combinedResult.ToString();
- this.response_params_text.Text = combinedResult.ToString(Newtonsoft.Json.Formatting.Indented);
- // 根据最好的结果设置状态
- if ((bool)offlineResult["success"])
- {
- SetStatusColor(offlineResult);
- UpdateDllRawDataInfo(offlineResult);
- }
- else if ((bool)autoInitResult["success"])
- {
- SetStatusColor(autoInitResult);
- UpdateDllRawDataInfo(autoInitResult);
- }
- else
- {
- SetStatusColor(initResult); // 显示初始化失败
- UpdateDllRawDataInfo(initResult);
- }
- // 显示综合的DLL错误信息
- var dllErrors = new System.Text.StringBuilder();
- if (initResult["dllErrorMsg"] != null)
- dllErrors.AppendLine($"传统模式: {initResult["dllErrorMsg"]}");
- if (autoInitResult["dllErrorMsg"] != null)
- dllErrors.AppendLine($"智能模式: {autoInitResult["dllErrorMsg"]}");
- if (offlineResult["dllErrorMsg"] != null)
- dllErrors.AppendLine($"离线模式: {offlineResult["dllErrorMsg"]}");
- this.dll_error_text.Text = dllErrors.ToString();
- this.dll_error_text.BackColor = System.Drawing.Color.FromArgb(255, 240, 240); // 浅红色
- this.dll_error_text.ForeColor = System.Drawing.Color.DarkRed;
- }
- }
- }
- catch (Exception ex)
- {
- var errorResult = new JObject();
- errorResult["success"] = false;
- errorResult["code"] = 1001;
- errorResult["message"] = "江苏社保卡测试异常: " + ex.Message;
- errorResult["device"] = "江苏医保HeaSecReadInfo.dll";
-
- this.result_text.Text = errorResult.ToString();
- this.response_params_text.Text = errorResult.ToString(Newtonsoft.Json.Formatting.Indented);
-
- // 显示异常的DLL错误信息
- this.dll_error_text.Text = $"系统异常: {ex.Message}";
- this.dll_error_text.BackColor = System.Drawing.Color.FromArgb(255, 245, 225); // 浅橙色
- this.dll_error_text.ForeColor = System.Drawing.Color.FromArgb(156, 39, 6); // 深橙色
-
- SetStatusColor(errorResult, true); // 标记为异常
-
- // 更新原始数据显示(异常时显示无数据)
- UpdateDllRawDataInfo(errorResult);
- }
-
- EnableAllButtons(true);
- this.jiangsu_sicard_test.Focus();
- }
- /// <summary>
- /// 测试江苏人社标准接口读社保卡
- /// </summary>
- private void TestJiangSuRenSheCard(object sender, EventArgs e)
- {
- EnableAllButtons(false);
- ClearParamsDisplay();
-
- try
- {
- // 显示江苏人社标准接口详细信息
- this.request_url_text.Text = GetJiangSuRenSheInterfaceInfo();
-
- // 显示请求参数
- var requestParams = new {
- action = "ReadSocialCardByStandard",
- device = "江苏人社标准社保卡读卡器",
- interfaceType = "江苏人社标准接口 v2.1.1",
- cardType = 3, // 自动寻卡接触式优先
- note = "使用相同的HeaSecReadInfo.dll初始化,但调用江苏人社标准接口规范"
- };
- this.request_params_text.Text = Newtonsoft.Json.JsonConvert.SerializeObject(requestParams, Newtonsoft.Json.Formatting.Indented);
-
- // 调用江苏人社标准接口(会自动初始化)
- var readResult = JiangSuSocialCardBusiness.ReadSocialCardByStandard(3);
-
- this.result_text.Text = readResult.ToString();
- this.response_params_text.Text = readResult.ToString(Newtonsoft.Json.Formatting.Indented);
- SetStatusColor(readResult);
-
- // 显示DLL原始错误信息
- if (readResult["dllErrorMsg"] != null)
- {
- string dllError = readResult["dllErrorMsg"].ToString();
- this.dll_error_text.Text = dllError;
-
- // 根据错误信息设置颜色
- if (string.IsNullOrEmpty(dllError))
- {
- this.dll_error_text.BackColor = System.Drawing.Color.FromArgb(220, 252, 231); // 浅绿色 - 成功
- this.dll_error_text.ForeColor = System.Drawing.Color.FromArgb(22, 101, 52);
- }
- else
- {
- this.dll_error_text.BackColor = System.Drawing.Color.FromArgb(255, 240, 240); // 浅红色 - 错误
- this.dll_error_text.ForeColor = System.Drawing.Color.DarkRed;
- }
- }
-
- // 更新原始数据显示
- UpdateDllRawDataInfo(readResult);
- }
- catch (Exception ex)
- {
- var errorResult = new JObject();
- errorResult["success"] = false;
- errorResult["code"] = 1001;
- errorResult["message"] = "江苏人社标准接口测试异常: " + ex.Message;
- errorResult["device"] = "江苏人社标准社保卡读卡器";
- errorResult["interface"] = "江苏人社标准接口 v2.1.1";
-
- this.result_text.Text = errorResult.ToString();
- this.response_params_text.Text = errorResult.ToString(Newtonsoft.Json.Formatting.Indented);
-
- // 显示异常的DLL错误信息
- this.dll_error_text.Text = $"系统异常: {ex.Message}";
- this.dll_error_text.BackColor = System.Drawing.Color.FromArgb(255, 245, 225); // 浅橙色
- this.dll_error_text.ForeColor = System.Drawing.Color.FromArgb(156, 39, 6); // 深橙色
-
- SetStatusColor(errorResult, true); // 标记为异常
-
- // 更新原始数据显示(异常时显示无数据)
- UpdateDllRawDataInfo(errorResult);
- }
-
- EnableAllButtons(true);
- this.jiangsu_renshe_test.Focus();
- }
- /// <summary>
- /// 获取江苏人社标准接口详细信息
- /// </summary>
- /// <returns>接口信息字符串</returns>
- private string GetJiangSuRenSheInterfaceInfo()
- {
- var info = new System.Text.StringBuilder();
- info.AppendLine("=== 江苏人社标准接口调用详情 ===");
- info.AppendLine();
-
- info.AppendLine("【✅ 实际调用流程】");
- info.AppendLine("1. 检查初始化: 如未初始化则自动调用HeaSecReadInfo.dll.Init()");
- info.AppendLine("2. 人社标准读卡: HeaSecReadInfo.dll.iReadCardBas(cardType, 1024字节缓冲区)");
- info.AppendLine("说明: 使用相同的初始化配置,但调用人社部标准接口规范!");
- info.AppendLine();
-
- info.AppendLine("【📋 接口规范差异】");
- info.AppendLine("江苏医保接口: ReadCardBas(cardInfo, busiInfo) - 双缓冲区");
- info.AppendLine("江苏人社接口: iReadCardBas(cardType, outInfo) - 单缓冲区");
- info.AppendLine("返回格式: 发卡地区|社保号|卡号|卡识别码|姓名|卡复位信息|...");
- info.AppendLine("数据分割: 使用|分割的标准12字段格式");
- info.AppendLine();
-
- info.AppendLine("【🔄 卡类型操作模式】");
- info.AppendLine("1 - 接触式操作卡");
- info.AppendLine("2 - 非接触式操作卡");
- info.AppendLine("3 - 自动寻卡(接触式优先)");
- info.AppendLine("4 - 自动寻卡(非接触式优先)");
- info.AppendLine("当前使用: 类型3(自动寻卡接触式优先)");
- info.AppendLine();
-
- info.AppendLine("【🔧 初始化配置】");
- info.AppendLine("✅ 相同DLL: HeaSecReadInfo.dll");
- info.AppendLine("✅ 相同初始化: 13个网络配置参数");
- info.AppendLine("✅ 相同设备: 江苏医保社保卡读卡器硬件");
- info.AppendLine("⚠️ 不同接口: 人社部标准vs医保自定义");
- info.AppendLine();
-
- info.AppendLine("【🌐 HTTP接口地址】");
- info.AppendLine("自动寻卡: http://localhost:8321/readcard/jiangsu/standard");
- info.AppendLine("接触式: http://localhost:8321/readcard/jiangsu/standard1");
- info.AppendLine("非接触式: http://localhost:8321/readcard/jiangsu/standard2");
- info.AppendLine("自动接触优先: http://localhost:8321/readcard/jiangsu/standard3");
- info.AppendLine("自动非接触优先: http://localhost:8321/readcard/jiangsu/standard4");
-
- return info.ToString();
- }
- /// <summary>
- /// 获取江苏医保接口详细信息
- /// </summary>
- /// <returns>接口信息字符串</returns>
- private string GetJiangSuInterfaceInfo()
- {
- var config = new JiangSuSocialCardBusiness.JiangSuConfig();
-
- var info = new System.Text.StringBuilder();
- info.AppendLine("=== 江苏医保接口调用详情 ===");
- info.AppendLine();
-
- info.AppendLine("【✅ 实际调用流程】");
- info.AppendLine("1. 初始化: HeaSecReadInfo.dll.Init(13个参数的JSON)");
- info.AppendLine("2. 读社保卡: HeaSecReadInfo.dll.ReadCardBas()");
- info.AppendLine("说明: 13个网络配置参数已传递给DLL进行初始化!");
- info.AppendLine();
-
- info.AppendLine("【📡 网络配置参数(已传给DLL)】");
- info.AppendLine($"江苏医保服务器: {config.IP}:{config.PORT}");
- info.AppendLine($"超时设置: {config.TIMEOUT}秒");
- info.AppendLine($"电子凭证URL: {config.EC_URL}");
- info.AppendLine($"CSB接口: {config.API_NAME} v{config.API_VERSION}");
- info.AppendLine($"认证密钥: {config.ACCESS_KEY.Substring(0, 8)}***");
- info.AppendLine($"机构编号: {config.ORG_ID}(铭和医院)");
- info.AppendLine($"行政区划: {config.AREA_CODE}(江苏宿迁沭阳)");
- info.AppendLine($"密码验证: CARD_PASSTYPE={config.CARD_PASSTYPE}");
- info.AppendLine();
-
- info.AppendLine("【🔄 DLL内部处理机制】");
- info.AppendLine("DLL收到配置后会:");
- info.AppendLine("- 连接江苏医保服务器(10.61.165.3:8086)");
- info.AppendLine("- 验证CSB接口认证(ACCESS_KEY/SECRETKEY)");
- info.AppendLine("- 准备网络查询功能(电子凭证等)");
- info.AppendLine("- 配置本地读卡器硬件");
- info.AppendLine();
-
- info.AppendLine("【📊 当前状态】");
- info.AppendLine("✅ 网络参数已传递: 13个配置全部发送给DLL");
- info.AppendLine("✅ DLL初始化成功: 返回码0表示网络连接正常");
- info.AppendLine("⚠️ 等待插卡: 错误码-11表示未检测到社保卡");
- info.AppendLine();
-
- info.AppendLine("【🛠️ 故障排查】");
- info.AppendLine("如果插卡后仍报错-11,可能原因:");
- info.AppendLine("1. 读卡器硬件未识别或驱动问题");
- info.AppendLine("2. 社保卡芯片损坏或接触不良");
- info.AppendLine("3. CARD_PASSTYPE参数不匹配医院环境");
- info.AppendLine("4. 需要PIN码但当前设置跳过了验证");
- info.AppendLine();
-
- info.AppendLine("【🌐 HTTP接口地址】");
- info.AppendLine("读卡: http://localhost:8321/readcard/jiangsu/readcard");
- info.AppendLine("初始化: http://localhost:8321/readcard/jiangsu/init");
- info.AppendLine("验证PIN: http://localhost:8321/readcard/jiangsu/verifypin");
- info.AppendLine("设备状态: http://localhost:8321/readcard/jiangsu/status");
-
- return info.ToString();
- }
- /// <summary>
- /// 测试江苏医保读卡器硬件状态
- /// </summary>
- private void TestJiangSuDeviceStatus(object sender, EventArgs e)
- {
- EnableAllButtons(false);
- ClearParamsDisplay();
-
- try
- {
- this.request_url_text.Text = "=== 江苏医保网络配置影响测试 ===\n\n测试不同网络配置对错误码的影响,验证 -11 到 -1 的变化原因...";
-
- // 显示检测参数
- var testParams = new {
- action = "NetworkConfigurationTest",
- device = "江苏医保HeaSecReadInfo.dll",
- tests = new string[] { "原始配置", "HSM配置", "无效配置", "空配置" },
- purpose = "验证网络配置变化是否真的影响错误码"
- };
- this.request_params_text.Text = Newtonsoft.Json.JsonConvert.SerializeObject(testParams, Newtonsoft.Json.Formatting.Indented);
-
- // 运行网络配置测试
- var networkTestResult = JiangSuSocialCardBusiness.TestNetworkConfigurations();
-
- var results = new JObject();
- results["networkConfigTest"] = networkTestResult;
-
- // 测试CARD_PASSTYPE=1的读卡
- try
- {
- var config1 = new JiangSuSocialCardBusiness.JiangSuConfig();
- config1.CARD_PASSTYPE = "1";
- var init1 = JiangSuSocialCardBusiness.Initialize(config1);
- var read1 = JiangSuSocialCardBusiness.ReadSocialCard(false);
- results["testPassType1"] = new JObject
- {
- ["passType"] = "1(验证卡PIN)",
- ["initResult"] = init1,
- ["readResult"] = read1
- };
- }
- catch (Exception ex1)
- {
- results["testPassType1"] = new JObject
- {
- ["passType"] = "1(验证卡PIN)",
- ["error"] = ex1.Message
- };
- }
-
- // 测试CARD_PASSTYPE=2的读卡
- try
- {
- var config2 = new JiangSuSocialCardBusiness.JiangSuConfig();
- config2.CARD_PASSTYPE = "2";
- var init2 = JiangSuSocialCardBusiness.Initialize(config2);
- var read2 = JiangSuSocialCardBusiness.ReadSocialCard(false);
- results["testPassType2"] = new JObject
- {
- ["passType"] = "2(验证数据库密码)",
- ["initResult"] = init2,
- ["readResult"] = read2
- };
- }
- catch (Exception ex2)
- {
- results["testPassType2"] = new JObject
- {
- ["passType"] = "2(验证数据库密码)",
- ["error"] = ex2.Message
- };
- }
-
- this.result_text.Text = results.ToString();
- this.response_params_text.Text = results.ToString(Newtonsoft.Json.Formatting.Indented);
-
- // 根据结果设置颜色
- bool hasSuccess = false;
- if (results["testPassType1"] != null && results["testPassType1"]["readResult"] != null)
- {
- var readResult1 = (JObject)results["testPassType1"]["readResult"];
- if (readResult1["success"] != null && (bool)readResult1["success"])
- hasSuccess = true;
- }
- if (results["testPassType2"] != null && results["testPassType2"]["readResult"] != null)
- {
- var readResult2 = (JObject)results["testPassType2"]["readResult"];
- if (readResult2["success"] != null && (bool)readResult2["success"])
- hasSuccess = true;
- }
-
- if (hasSuccess)
- {
- SetStatusColor(new JObject { ["success"] = true });
- }
- else
- {
- SetStatusColor(new JObject { ["success"] = false }, true);
- }
- }
- catch (Exception ex)
- {
- var errorResult = new JObject();
- errorResult["success"] = false;
- errorResult["code"] = 9001;
- errorResult["message"] = "硬件检测异常: " + ex.Message;
- errorResult["device"] = "江苏医保HeaSecReadInfo.dll";
-
- this.result_text.Text = errorResult.ToString();
- this.response_params_text.Text = errorResult.ToString(Newtonsoft.Json.Formatting.Indented);
- SetStatusColor(errorResult, true);
- }
-
- EnableAllButtons(true);
- }
- private void ClearParamsDisplay()
- {
- this.request_url_text.Text = "";
- this.request_params_text.Text = "";
- this.response_params_text.Text = "";
- this.dll_error_text.Text = "";
-
- // 清理原始数据显示区域
- if (this.dll_raw_data_text != null)
- {
- this.dll_raw_data_text.Text = "";
- }
-
- // 重置为默认颜色
- this.response_params_text.BackColor = System.Drawing.SystemColors.Window;
- this.response_params_text.ForeColor = System.Drawing.SystemColors.WindowText;
- this.result_text.BackColor = System.Drawing.SystemColors.Window;
- this.result_text.ForeColor = System.Drawing.SystemColors.WindowText;
-
- // 重置DLL错误信息显示区域
- this.dll_error_text.BackColor = System.Drawing.Color.FromArgb(255, 240, 240);
- this.dll_error_text.ForeColor = System.Drawing.Color.DarkRed;
- }
- /// <summary>
- /// 根据结果设置状态颜色
- /// </summary>
- /// <param name="result">结果对象</param>
- /// <param name="isException">是否为异常情况</param>
- private void SetStatusColor(JObject result, bool isException = false)
- {
- try
- {
- if (isException)
- {
- // 异常状态 - 橙色背景
- this.response_params_text.BackColor = System.Drawing.Color.FromArgb(255, 245, 225); // 浅橙色
- this.response_params_text.ForeColor = System.Drawing.Color.FromArgb(156, 39, 6); // 深橙色
- this.result_text.BackColor = System.Drawing.Color.FromArgb(255, 245, 225);
- this.result_text.ForeColor = System.Drawing.Color.FromArgb(156, 39, 6);
- return;
- }
- // 检查不同的成功标识字段
- bool isSuccess = false;
- int code = 0;
- // 尝试获取 success 字段(江苏医保格式)
- if (result["success"] != null)
- {
- isSuccess = (bool)result["success"];
- }
-
- // 尝试获取 code 字段
- if (result["code"] != null)
- {
- code = (int)result["code"];
- // 如果没有success字段,根据code判断(200表示成功)
- if (result["success"] == null)
- {
- isSuccess = (code == 200);
- }
- }
- if (isSuccess || code == 200)
- {
- // 成功状态 - 绿色背景
- this.response_params_text.BackColor = System.Drawing.Color.FromArgb(220, 252, 231); // 浅绿色
- this.response_params_text.ForeColor = System.Drawing.Color.FromArgb(22, 101, 52); // 深绿色
- this.result_text.BackColor = System.Drawing.Color.FromArgb(220, 252, 231);
- this.result_text.ForeColor = System.Drawing.Color.FromArgb(22, 101, 52);
- }
- else
- {
- // 失败状态 - 红色背景
- this.response_params_text.BackColor = System.Drawing.Color.FromArgb(254, 226, 226); // 浅红色
- this.response_params_text.ForeColor = System.Drawing.Color.FromArgb(153, 27, 27); // 深红色
- this.result_text.BackColor = System.Drawing.Color.FromArgb(254, 226, 226);
- this.result_text.ForeColor = System.Drawing.Color.FromArgb(153, 27, 27);
- }
- }
- catch (Exception ex)
- {
- // 解析状态失败,设置为默认颜色
- this.response_params_text.BackColor = System.Drawing.SystemColors.Window;
- this.response_params_text.ForeColor = System.Drawing.SystemColors.WindowText;
- this.result_text.BackColor = System.Drawing.SystemColors.Window;
- this.result_text.ForeColor = System.Drawing.SystemColors.WindowText;
-
- System.Diagnostics.Debug.WriteLine($"设置状态颜色失败: {ex.Message}");
- }
- }
- /// <summary>
- /// 测试江苏医保刷脸授权获取医保身份功能
- /// 使用NationECCode.dll与泰和完全一致
- /// </summary>
- private void TestJiangSuFace(object sender, EventArgs e)
- {
- EnableAllButtons(false);
- ClearParamsDisplay();
-
- try
- {
- // 显示江苏医保刷脸详细信息
- this.request_url_text.Text = GetJiangSuFaceInterfaceInfo();
-
- // 显示请求参数
- var requestParams = new {
- action = "JiangSuFaceAuth",
- device = "江苏医保刷脸认证器(NationECCode.dll)",
- implementation = "与泰和完全一致(相同DLL、相同URL、相同逻辑)",
- businessType = "01101",
- transType1 = "cn.nhsa.ec.auth(获取authNo)",
- transType2 = "cn.nhsa.auth.check(根据authNo获取医保身份)",
- orgId = "H32132200561(写死参数)",
- serviceUrl = "http://10.58.33.207:10086/localcfc/api/hsecfc/localQrCodeQuery(写死参数)",
- note = "完全使用写死的配置参数,与泰和实现方式一致"
- };
- this.request_params_text.Text = Newtonsoft.Json.JsonConvert.SerializeObject(requestParams, Newtonsoft.Json.Formatting.Indented);
-
- // 调用江苏医保刷脸功能(使用NationECCode.dll与泰和完全一致)
- var faceResult = JiangSuSocialCardBusiness.ReadFace("01101");
-
- this.result_text.Text = faceResult.ToString();
- this.response_params_text.Text = faceResult.ToString(Newtonsoft.Json.Formatting.Indented);
- SetStatusColor(faceResult);
-
- // 显示DLL错误信息(如果有)
- if (faceResult["message"] != null)
- {
- string message = faceResult["message"].ToString();
- bool isSuccess = faceResult["code"] != null && (int)faceResult["code"] == 200;
-
- this.dll_error_text.Text = message;
-
- if (isSuccess)
- {
- this.dll_error_text.BackColor = System.Drawing.Color.FromArgb(220, 252, 231); // 浅绿色 - 成功
- this.dll_error_text.ForeColor = System.Drawing.Color.FromArgb(22, 101, 52);
- }
- else
- {
- this.dll_error_text.BackColor = System.Drawing.Color.FromArgb(255, 240, 240); // 浅红色 - 错误
- this.dll_error_text.ForeColor = System.Drawing.Color.DarkRed;
- }
- }
-
- // 更新原始数据显示
- UpdateDllRawDataInfo(faceResult);
- }
- catch (Exception ex)
- {
- var errorResult = new JObject();
- errorResult["success"] = false;
- errorResult["code"] = 4001;
- errorResult["message"] = "江苏医保刷脸测试异常: " + ex.Message;
- errorResult["device"] = "江苏医保刷脸认证器(NationECCode.dll)";
- errorResult["implementation"] = "与泰和完全一致";
-
- this.result_text.Text = errorResult.ToString();
- this.response_params_text.Text = errorResult.ToString(Newtonsoft.Json.Formatting.Indented);
-
- this.dll_error_text.Text = "系统异常: " + ex.Message;
- this.dll_error_text.BackColor = System.Drawing.Color.FromArgb(255, 245, 225); // 浅橙色
- this.dll_error_text.ForeColor = System.Drawing.Color.FromArgb(156, 39, 6); // 深橙色
-
- SetStatusColor(errorResult, true);
- UpdateDllRawDataInfo(errorResult);
- }
-
- EnableAllButtons(true);
- this.jiangsu_face_test.Focus();
- }
- /// <summary>
- /// 获取江苏医保刷脸接口详细信息
- /// </summary>
- /// <returns>接口信息字符串</returns>
- private string GetJiangSuFaceInterfaceInfo()
- {
- var info = new System.Text.StringBuilder();
- info.AppendLine("=== 江苏医保刷脸授权获取医保身份接口调用详情 ===");
- info.AppendLine();
-
- info.AppendLine("【✅ 实现方式】");
- info.AppendLine("DLL文件: NationECCode.dll(与泰和完全相同)");
- info.AppendLine("服务地址: http://10.58.33.207:10086/localcfc/api/hsecfc/localQrCodeQuery(写死参数)");
- info.AppendLine("机构编号: H32132200561(写死参数)");
- info.AppendLine("实现逻辑: 与泰和的ReadFace方法完全一致");
- info.AppendLine();
-
- info.AppendLine("【🔄 两步式认证流程】");
- info.AppendLine("第一步: 调用cn.nhsa.ec.auth获取authNo");
- info.AppendLine("第二步: 调用cn.nhsa.auth.check根据authNo获取医保身份信息");
- info.AppendLine("符合规范: 国家医保电子凭证业务标准动态库交互规范2021-11-12");
- info.AppendLine();
-
- info.AppendLine("【📋 支持的业务类型】");
- info.AppendLine("01101 - 门诊挂号(当前测试)");
- info.AppendLine("01301 - 门诊结算");
- info.AppendLine("02121 - 药店购药");
- info.AppendLine("01102 - 住院建档");
- info.AppendLine("01103 - 入院登记");
- info.AppendLine();
-
- info.AppendLine("【🌐 HTTP接口地址】");
- info.AppendLine("江苏医保刷脸: http://localhost:8321/readcard/entry?param=jiangsu_face_01101");
- info.AppendLine("门诊挂号: http://localhost:8321/readcard/entry?param=jiangsu_face_01101");
- info.AppendLine("门诊结算: http://localhost:8321/readcard/entry?param=jiangsu_face_01301");
- info.AppendLine("药店购药: http://localhost:8321/readcard/entry?param=jiangsu_face_02121");
- info.AppendLine("通用格式: jiangsu_face_${biztype}");
-
- return info.ToString();
- }
- /// <summary>
- /// 测试江苏医保电子凭证解码功能
- /// </summary>
- private void TestJiangSuEcDecode(object sender, EventArgs e)
- {
- EnableAllButtons(false);
- ClearParamsDisplay();
-
- try
- {
- // 显示江苏医保电子凭证解码详细信息
- this.request_url_text.Text = GetJiangSuEcDecodeInterfaceInfo();
-
- // 显示实际DLL调用参数
- var config = new JiangSuSocialCardBusiness.JiangSuConfig();
- var requestParams = new {
- data = new {
- orgId = config.ORG_ID,
- businessType = "01101",
- operatorId = "system001",
- operatorName = "系统管理员",
- officeId = "32760",
- officeName = "医保科"
- },
- transType = "ec.query",
- orgId = config.ORG_ID,
- note = "实际DLL调用参数格式 - 符合江苏医保接口规范v0.9.9.15",
- interfaceVersion = "1.14.6 电子凭证解码",
- function = "HeaSecReadInfo.dll.EcQuery"
- };
- this.request_params_text.Text = Newtonsoft.Json.JsonConvert.SerializeObject(requestParams, Newtonsoft.Json.Formatting.Indented);
-
- // 调用江苏医保电子凭证解码接口
- var decodeResult = JiangSuSocialCardBusiness.ReadElectronicCertificate("01101");
-
- this.result_text.Text = decodeResult.ToString();
- this.response_params_text.Text = decodeResult.ToString(Newtonsoft.Json.Formatting.Indented);
- SetStatusColor(decodeResult);
-
- // 显示DLL原始错误信息
- if (decodeResult["dllErrorMsg"] != null)
- {
- string dllError = decodeResult["dllErrorMsg"].ToString();
- this.dll_error_text.Text = dllError;
-
- if (string.IsNullOrEmpty(dllError))
- {
- this.dll_error_text.BackColor = Color.LightGreen;
- this.dll_error_text.ForeColor = Color.DarkGreen;
- }
- else
- {
- this.dll_error_text.BackColor = Color.LightPink;
- this.dll_error_text.ForeColor = Color.DarkRed;
- }
- }
-
- // 更新原始数据显示
- UpdateDllRawDataInfo(decodeResult);
- }
- catch (Exception ex)
- {
- var errorResult = new JObject();
- errorResult["success"] = false;
- errorResult["code"] = 3001;
- errorResult["message"] = "江苏医保电子凭证解码测试异常: " + ex.Message;
- errorResult["device"] = "江苏医保HeaSecReadInfo.dll";
- errorResult["interfaceVersion"] = "江苏医保电子凭证解码接口 v0.9.9.15";
-
- this.result_text.Text = errorResult.ToString();
- this.response_params_text.Text = errorResult.ToString(Newtonsoft.Json.Formatting.Indented);
-
- this.dll_error_text.Text = "系统异常: " + ex.Message;
- this.dll_error_text.BackColor = Color.LightYellow;
- this.dll_error_text.ForeColor = Color.DarkRed;
-
- SetStatusColor(errorResult, true);
- UpdateDllRawDataInfo(errorResult);
- }
-
- EnableAllButtons(true);
- this.jiangsu_ec_decode_test.Focus();
- }
- /// <summary>
- /// 获取江苏医保电子凭证解码接口详细信息
- /// </summary>
- /// <returns>接口信息字符串</returns>
- private string GetJiangSuEcDecodeInterfaceInfo()
- {
- var info = new System.Text.StringBuilder();
- info.AppendLine("=== 江苏医保电子凭证解码接口调用详情 ===");
- info.AppendLine();
-
- info.AppendLine("【✅ 实际调用流程】");
- info.AppendLine("1. 自动初始化: 检查并初始化HeaSecReadInfo.dll");
- info.AppendLine("2. 电子凭证解码: HeaSecReadInfo.dll.EcQuery(业务参数JSON)");
- info.AppendLine("说明: 符合江苏医保接口规范v0.9.9.15第1.14.6节要求!");
- info.AppendLine();
-
- info.AppendLine("【📋 接口规范详情】");
- info.AppendLine("接口名称: 1.14.6 电子凭证解码");
- info.AppendLine("调用函数: EcQuery");
- info.AppendLine("输入格式: JSON字符串(业务类型+配置参数)");
- info.AppendLine("输出格式: JSON字符串(解码结果+状态信息)");
- info.AppendLine("缓冲区大小: 8192字节");
- info.AppendLine();
-
- info.AppendLine("【🔄 支持的业务类型】");
- info.AppendLine("门诊业务:");
- info.AppendLine(" 01101 - 挂号");
- info.AppendLine(" 01201 - 问诊");
- info.AppendLine(" 01202 - 预约检查");
- info.AppendLine(" 01203 - 检查");
- info.AppendLine(" 01204 - 治疗");
- info.AppendLine(" 01301 - 结算");
- info.AppendLine(" 01302 - 取药");
- info.AppendLine("住院业务:");
- info.AppendLine(" 01102 - 建档");
- info.AppendLine(" 01103 - 入院登记");
- info.AppendLine(" 01104 - 缴纳预缴金");
- info.AppendLine("药店业务:");
- info.AppendLine(" 02121 - 购药");
- info.AppendLine(" 02122 - 下载外购处方");
- info.AppendLine("当前测试: 01101(门诊挂号)");
- info.AppendLine();
-
- info.AppendLine("【🔧 初始化配置】");
- info.AppendLine("✅ 江苏医保服务器: 10.61.165.3:8086");
- info.AppendLine("✅ CSB接口认证: ACCESS_KEY/SECRET_KEY");
- info.AppendLine("✅ 机构编号: H32132100055(铭和医院)");
- info.AppendLine("✅ 行政区划: 321322(江苏宿迁沭阳)");
- info.AppendLine("✅ API接口: hsEcQuery v1.0.0");
- info.AppendLine();
-
- info.AppendLine("【🌐 HTTP接口地址】");
- info.AppendLine("门诊挂号: http://localhost:8321/api/entry?param=jiangsu_qrcode_01101");
- info.AppendLine("门诊问诊: http://localhost:8321/api/entry?param=jiangsu_qrcode_01201");
- info.AppendLine("门诊结算: http://localhost:8321/api/entry?param=jiangsu_qrcode_01301");
- info.AppendLine("住院登记: http://localhost:8321/api/entry?param=jiangsu_qrcode_01103");
- info.AppendLine("药店购药: http://localhost:8321/api/entry?param=jiangsu_qrcode_02121");
- info.AppendLine("通用格式: jiangsu_qrcode_[业务类型] 或 jiangsu_ec_[业务类型]");
-
- return info.ToString();
- }
- private void EnableAllButtons(Boolean value)
- {
- this.sicard_test.Enabled = value;
- this.idcard_test.Enabled = value;
- this.qrcode_test.Enabled = value;
- this.face_test.Enabled = value;
- this.id_card_test2.Enabled = value;
- this.qr_code_test2.Enabled = value;
- this.huashi_idcard_test.Enabled = value;
- this.jiangsu_sicard_test.Enabled = value;
- this.jiangsu_renshe_test.Enabled = value;
- this.jiangsu_face_test.Enabled = value;
- this.jiangsu_ec_decode_test.Enabled = value;
- }
- protected override void WndProc(ref Message m)
- {
- const int WM_SYSCOMMAND = 0x0112;
- const int SC_CLOSE = 0xF060;
- if (m.Msg == WM_SYSCOMMAND && (int)m.WParam == SC_CLOSE)
- {
- // User clicked close button
- this.WindowState = FormWindowState.Minimized;
- return;
- }
- base.WndProc(ref m);
- }
- protected override void OnResize(EventArgs e)
- {
- if (WindowState == FormWindowState.Minimized)
- {
- this.Hide();
- }
- }
- /// <summary>
- /// 更新DLL原始数据显示
- /// </summary>
- private void UpdateDllRawDataInfo(dynamic result)
- {
- try
- {
- this.Invoke((Action)(() =>
- {
- if (dll_raw_data_text != null)
- {
- string rawDataInfo = "";
- Color textColor = Color.DarkBlue; // 默认深蓝色
- if (result != null)
- {
- // 检查是否有原始读卡数据
- if (result.rawCardData != null || result.rawBusiData != null)
- {
- var rawDataBuilder = new System.Text.StringBuilder();
- rawDataBuilder.AppendLine("=== 读卡原始数据 ===");
- rawDataBuilder.AppendLine($"时间: {DateTime.Now:yyyy-MM-dd HH:mm:ss}");
- rawDataBuilder.AppendLine();
- if (result.rawCardData != null)
- {
- string cardData = result.rawCardData.ToString();
- rawDataBuilder.AppendLine("【基本信息数据】");
- if (!string.IsNullOrEmpty(cardData))
- {
- rawDataBuilder.AppendLine(cardData);
- textColor = Color.Green; // 有数据:绿色
- }
- else
- {
- rawDataBuilder.AppendLine("(空数据)");
- textColor = Color.Orange; // 空数据:橙色
- }
- rawDataBuilder.AppendLine();
- }
- if (result.rawBusiData != null)
- {
- string busiData = result.rawBusiData.ToString();
- rawDataBuilder.AppendLine("【业务信息数据】");
- if (!string.IsNullOrEmpty(busiData))
- {
- rawDataBuilder.AppendLine(busiData);
- if (textColor != Color.Green) // 如果基本信息没有数据,但业务信息有数据
- {
- textColor = Color.Green;
- }
- }
- else
- {
- rawDataBuilder.AppendLine("(空数据)");
- if (textColor == Color.DarkBlue) // 如果都没有数据
- {
- textColor = Color.Orange;
- }
- }
- }
- rawDataInfo = rawDataBuilder.ToString();
- }
- else
- {
- // 没有读卡数据的情况
- bool isSuccess = result.success != null && (bool)result.success;
- if (!isSuccess)
- {
- rawDataInfo = $"读卡失败 - {DateTime.Now:yyyy-MM-dd HH:mm:ss}\n无原始数据返回";
- textColor = Color.Red; // 失败:红色
- }
- else
- {
- rawDataInfo = $"操作成功 - {DateTime.Now:yyyy-MM-dd HH:mm:ss}\n此操作无读卡数据";
- textColor = Color.Gray; // 无相关数据:灰色
- }
- }
- }
- dll_raw_data_text.Text = rawDataInfo;
- dll_raw_data_text.ForeColor = textColor;
- }
- }));
- }
- catch (Exception ex)
- {
- // 静默处理,避免影响主要功能
- Console.WriteLine($"更新DLL原始数据失败: {ex.Message}");
- }
- }
- }
- }
|