江苏电子凭证解码接口调用方法.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  1. using System;
  2. using System.Runtime.InteropServices;
  3. using System.Text;
  4. using Newtonsoft.Json;
  5. using Newtonsoft.Json.Linq;
  6. namespace JiangSuElectronicCertificate
  7. {
  8. /// <summary>
  9. /// 江苏医保电子凭证解码接口
  10. /// 基于江苏医保接口规范v0.9.9.15和HeaSecReadInfo.dll实现
  11. /// 符合国家医保电子凭证业务标准动态库交互规范2021-11-12
  12. /// </summary>
  13. public class JiangSuEcDecoder
  14. {
  15. #region DLL导入声明
  16. /// <summary>
  17. /// 1.14.1 初始化
  18. /// </summary>
  19. /// <param name="pInitInfo">JSON格式的初始化参数</param>
  20. /// <param name="pErrMsg">错误信息输出缓冲区</param>
  21. /// <returns>0-成功,其他-失败</returns>
  22. [DllImport("HeaSecReadInfo.dll", EntryPoint = "Init", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
  23. private extern static Int32 Init(string pInitInfo, StringBuilder pErrMsg);
  24. /// <summary>
  25. /// 1.14.6 电子凭证解码
  26. /// </summary>
  27. /// <param name="pInData">输入数据(JSON格式)</param>
  28. /// <param name="pOutData">输出数据缓冲区</param>
  29. /// <returns>0-成功,其他-失败</returns>
  30. [DllImport("HeaSecReadInfo.dll", EntryPoint = "EcQuery", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
  31. private extern static Int32 EcQuery(string pInData, StringBuilder pOutData);
  32. #endregion
  33. #region 配置类
  34. /// <summary>
  35. /// 江苏医保配置信息
  36. /// </summary>
  37. public class JiangSuConfig
  38. {
  39. /// <summary>
  40. /// 服务器IP地址(根据具体医院配置修改)
  41. /// </summary>
  42. public string IP { get; set; } = "10.61.165.3";
  43. /// <summary>
  44. /// 服务器端口号
  45. /// </summary>
  46. public int PORT { get; set; } = 8086;
  47. /// <summary>
  48. /// 超时时间(秒)
  49. /// </summary>
  50. public int TIMEOUT { get; set; } = 30;
  51. /// <summary>
  52. /// 日志路径(根据项目实际路径修改)
  53. /// </summary>
  54. public string LOG_PATH { get; set; } = "C:\\logs\\";
  55. /// <summary>
  56. /// 电子凭证解码URL(根据具体医院配置修改)
  57. /// </summary>
  58. public string EC_URL { get; set; } = "http://10.58.33.207:10086/localcfc/api/hsecfc/localQrCodeQuery";
  59. /// <summary>
  60. /// 卡片通道类型
  61. /// </summary>
  62. public string CARD_PASSTYPE { get; set; } = "2";
  63. /// <summary>
  64. /// API名称
  65. /// </summary>
  66. public string API_NAME { get; set; } = "hssServives";
  67. /// <summary>
  68. /// API版本
  69. /// </summary>
  70. public string API_VERSION { get; set; } = "1.0.0";
  71. /// <summary>
  72. /// 访问密钥(根据具体医院申请的密钥修改)
  73. /// </summary>
  74. public string ACCESS_KEY { get; set; } = "090ea4c914324ee38b6978365df46a80";
  75. /// <summary>
  76. /// 秘钥(根据具体医院申请的密钥修改)
  77. /// </summary>
  78. public string SECRETKEY { get; set; } = "CMgTEMfftMP0EMMoliOs65wZmv8=";
  79. /// <summary>
  80. /// 机构编号(根据具体医院的医保定点编号修改)
  81. /// </summary>
  82. public string ORG_ID { get; set; } = "H32132200561";
  83. /// <summary>
  84. /// 扩展参数
  85. /// </summary>
  86. public string EXT { get; set; } = "{}";
  87. /// <summary>
  88. /// 地区编码
  89. /// </summary>
  90. public string AREA_CODE { get; set; } = "321322";
  91. /// <summary>
  92. /// 转换为JSON格式
  93. /// </summary>
  94. /// <returns>JSON字符串</returns>
  95. public string ToJson()
  96. {
  97. var config = new
  98. {
  99. IP = this.IP,
  100. PORT = this.PORT,
  101. TIMEOUT = this.TIMEOUT,
  102. LOG_PATH = this.LOG_PATH,
  103. EC_URL = this.EC_URL,
  104. CARD_PASSTYPE = this.CARD_PASSTYPE,
  105. API_NAME = this.API_NAME,
  106. API_VERSION = this.API_VERSION,
  107. ACCESS_KEY = this.ACCESS_KEY,
  108. SECRETKEY = this.SECRETKEY,
  109. ORG_ID = this.ORG_ID,
  110. EXT = this.EXT,
  111. AREA_CODE = this.AREA_CODE
  112. };
  113. return JsonConvert.SerializeObject(config, Formatting.None);
  114. }
  115. }
  116. #endregion
  117. #region 私有变量
  118. private static bool isInitialized = false;
  119. private static JiangSuConfig currentConfig = null;
  120. #endregion
  121. #region 公共方法
  122. /// <summary>
  123. /// 初始化江苏医保系统
  124. /// </summary>
  125. /// <param name="config">配置信息,为null时使用默认配置</param>
  126. /// <returns>初始化结果</returns>
  127. public static JObject Initialize(JiangSuConfig config = null)
  128. {
  129. var result = new JObject();
  130. try
  131. {
  132. // 使用传入的配置或默认配置
  133. if (config == null)
  134. {
  135. config = new JiangSuConfig();
  136. }
  137. currentConfig = config;
  138. // 准备初始化参数
  139. string initParams = config.ToJson();
  140. // 准备错误信息缓冲区
  141. StringBuilder errorBuffer = new StringBuilder(1024);
  142. // 调用DLL初始化函数
  143. int initResult = Init(initParams, errorBuffer);
  144. if (initResult == 0)
  145. {
  146. isInitialized = true;
  147. result["success"] = true;
  148. result["code"] = 200;
  149. result["message"] = "江苏医保系统初始化成功";
  150. result["device"] = "江苏医保电子凭证解码器";
  151. result["config"] = JObject.Parse(initParams);
  152. result["timestamp"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  153. }
  154. else
  155. {
  156. isInitialized = false;
  157. string errorMessage = errorBuffer.ToString();
  158. result["success"] = false;
  159. result["code"] = 1000 + initResult;
  160. result["message"] = $"江苏医保系统初始化失败,错误码: {initResult}";
  161. result["device"] = "江苏医保电子凭证解码器";
  162. result["dllErrorCode"] = initResult;
  163. result["dllErrorMessage"] = errorMessage;
  164. }
  165. }
  166. catch (Exception ex)
  167. {
  168. isInitialized = false;
  169. result["success"] = false;
  170. result["code"] = 1001;
  171. result["message"] = $"江苏医保系统初始化异常: {ex.Message}";
  172. result["device"] = "江苏医保电子凭证解码器";
  173. result["exception"] = ex.GetType().Name;
  174. }
  175. return result;
  176. }
  177. /// <summary>
  178. /// 江苏医保电子凭证解码
  179. /// </summary>
  180. /// <param name="businessType">业务类型编码(默认01101门诊挂号)</param>
  181. /// <param name="operatorId">收款员编号</param>
  182. /// <param name="operatorName">收款员姓名</param>
  183. /// <param name="officeId">医保科室编号</param>
  184. /// <param name="officeName">科室名称</param>
  185. /// <returns>解码结果</returns>
  186. public static JObject DecodeElectronicCertificate(
  187. string businessType = "01101",
  188. string operatorId = "system001",
  189. string operatorName = "系统管理员",
  190. string officeId = "32760",
  191. string officeName = "医保科")
  192. {
  193. var result = new JObject();
  194. try
  195. {
  196. // 检查初始化状态
  197. if (!isInitialized)
  198. {
  199. // 自动初始化
  200. var autoInitResult = Initialize();
  201. if (!(bool)autoInitResult["success"])
  202. {
  203. result["success"] = false;
  204. result["code"] = 1002;
  205. result["message"] = "江苏医保系统未初始化,电子凭证解码失败";
  206. result["device"] = "江苏医保电子凭证解码器";
  207. result["autoInitError"] = autoInitResult["message"];
  208. result["type"] = "qrcode";
  209. return result;
  210. }
  211. }
  212. // 获取当前配置
  213. if (currentConfig == null)
  214. {
  215. result["success"] = false;
  216. result["code"] = 1003;
  217. result["message"] = "江苏医保配置信息为空";
  218. result["device"] = "江苏医保电子凭证解码器";
  219. result["type"] = "qrcode";
  220. return result;
  221. }
  222. // 按照江苏医保接口规范1.14.6构造输入参数
  223. var inputData = new
  224. {
  225. data = new
  226. {
  227. orgId = currentConfig.ORG_ID, // 定点编号
  228. businessType = businessType, // 用码业务类型
  229. operatorId = operatorId, // 收款员编号
  230. operatorName = operatorName, // 收款员姓名
  231. officeId = officeId, // 医保科室编号
  232. officeName = officeName // 科室名称
  233. },
  234. transType = "ec.query", // 固定值:ec.query
  235. orgId = currentConfig.ORG_ID // 定点编号
  236. };
  237. // JSON序列化输入参数
  238. string jsonInput = JsonConvert.SerializeObject(inputData, Formatting.None);
  239. // 按照规范分配8192字节输出缓冲区
  240. StringBuilder outputBuffer = new StringBuilder(8192);
  241. // 调用江苏医保DLL的EcQuery函数
  242. int dllResult = EcQuery(jsonInput, outputBuffer);
  243. if (dllResult == 0)
  244. {
  245. // 解析DLL返回的JSON数据
  246. string responseJson = outputBuffer.ToString();
  247. if (string.IsNullOrEmpty(responseJson))
  248. {
  249. result["success"] = false;
  250. result["code"] = 1004;
  251. result["message"] = "电子凭证解码返回数据为空";
  252. result["device"] = "江苏医保电子凭证解码器";
  253. result["type"] = "qrcode";
  254. return result;
  255. }
  256. // 解析江苏医保返回的JSON数据
  257. var jiangsuResponse = JObject.Parse(responseJson);
  258. // 检查江苏医保接口返回的code字段
  259. int responseCode = (int)(jiangsuResponse["code"] ?? -1);
  260. if (responseCode == 0)
  261. {
  262. // 成功:提取患者信息
  263. var patientData = jiangsuResponse["data"];
  264. if (patientData != null)
  265. {
  266. result["success"] = true;
  267. result["code"] = 200;
  268. result["message"] = "江苏医保电子凭证解码成功";
  269. result["device"] = "江苏医保电子凭证解码器";
  270. result["type"] = "qrcode";
  271. result["originalType"] = "jiangsu_ec";
  272. result["timestamp"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  273. // 按照文档规范提取患者信息
  274. var patientInfo = new
  275. {
  276. idNo = patientData["idNo"]?.ToString() ?? "", // 身份证号
  277. userName = patientData["userName"]?.ToString() ?? "", // 姓名
  278. idType = patientData["idType"]?.ToString() ?? "", // 证件类型
  279. ecToken = patientData["ecToken"]?.ToString() ?? "", // 令牌
  280. insuOrg = patientData["insuOrg"]?.ToString() ?? "", // 参保地区编码
  281. ecIndexNo = patientData["ecIndexNo"]?.ToString() ?? "", // 电子凭证索引号
  282. gender = patientData["gender"]?.ToString() ?? "", // 性别
  283. birthday = patientData["birthday"]?.ToString() ?? "", // 出生日期
  284. nationality = patientData["nationality"]?.ToString() ?? "", // 国籍
  285. email = patientData["email"]?.ToString() ?? "", // 邮箱
  286. extra = patientData["extra"]?.ToString() ?? "" // 扩展参数
  287. };
  288. // 按照泰和医院格式构造data字段(包含code/data/message结构)
  289. var dllResponseFormat = new
  290. {
  291. code = 0,
  292. data = patientInfo,
  293. message = "交易成功"
  294. };
  295. result["data"] = JsonConvert.SerializeObject(dllResponseFormat);
  296. // 保存原始江苏医保返回数据(用于调试和日志)
  297. result["jiangsuOriginalData"] = responseJson;
  298. result["businessType"] = businessType;
  299. result["interfaceVersion"] = "v0.9.9.15";
  300. }
  301. else
  302. {
  303. result["success"] = false;
  304. result["code"] = 1005;
  305. result["message"] = "电子凭证解码成功,但患者数据为空";
  306. result["device"] = "江苏医保电子凭证解码器";
  307. result["type"] = "qrcode";
  308. result["jiangsuOriginalData"] = responseJson;
  309. }
  310. }
  311. else
  312. {
  313. // 江苏医保接口返回失败
  314. string errorMessage = jiangsuResponse["message"]?.ToString() ?? "电子凭证解码失败";
  315. result["success"] = false;
  316. result["code"] = 2000 + responseCode; // 使用2xxx系列表示江苏医保接口错误
  317. result["message"] = $"江苏医保电子凭证解码失败: {errorMessage}";
  318. result["device"] = "江苏医保电子凭证解码器";
  319. result["type"] = "qrcode";
  320. result["jiangsuErrorCode"] = responseCode;
  321. result["jiangsuErrorMessage"] = errorMessage;
  322. result["jiangsuOriginalData"] = responseJson;
  323. result["businessType"] = businessType;
  324. }
  325. }
  326. else
  327. {
  328. // DLL函数调用失败
  329. string errorInfo = outputBuffer.ToString();
  330. result["success"] = false;
  331. result["code"] = 3000 + dllResult; // 使用3xxx系列表示DLL调用错误
  332. result["message"] = $"江苏医保DLL调用失败,错误码: {dllResult}";
  333. result["device"] = "江苏医保电子凭证解码器";
  334. result["type"] = "qrcode";
  335. result["dllErrorCode"] = dllResult;
  336. result["dllErrorMessage"] = errorInfo;
  337. result["businessType"] = businessType;
  338. result["suggestion"] = GetEcQueryErrorSuggestion(dllResult);
  339. }
  340. }
  341. catch (JsonException jsonEx)
  342. {
  343. result["success"] = false;
  344. result["code"] = 1006;
  345. result["message"] = $"电子凭证解码数据解析异常: {jsonEx.Message}";
  346. result["device"] = "江苏医保电子凭证解码器";
  347. result["type"] = "qrcode";
  348. result["exception"] = jsonEx.GetType().Name;
  349. result["businessType"] = businessType;
  350. }
  351. catch (Exception ex)
  352. {
  353. result["success"] = false;
  354. result["code"] = 1007;
  355. result["message"] = $"电子凭证解码系统异常: {ex.Message}";
  356. result["device"] = "江苏医保电子凭证解码器";
  357. result["type"] = "qrcode";
  358. result["exception"] = ex.GetType().Name;
  359. result["businessType"] = businessType;
  360. }
  361. return result;
  362. }
  363. /// <summary>
  364. /// 检查业务类型编码是否有效
  365. /// </summary>
  366. /// <param name="businessType">业务类型编码</param>
  367. /// <returns>是否有效</returns>
  368. public static bool IsValidBusinessType(string businessType)
  369. {
  370. if (string.IsNullOrEmpty(businessType) || businessType.Length != 5)
  371. return false;
  372. // 有效的业务类型列表(根据国家医保电子凭证业务标准)
  373. string[] validTypes = {
  374. "01101", // 医院-挂号
  375. "01102", // 医院-住院建档
  376. "01103", // 医院-入院登记
  377. "01104", // 医院-缴纳预缴金
  378. "01201", // 医院-问诊
  379. "01202", // 医院-预约检查
  380. "01203", // 医院-检查
  381. "01204", // 医院-治疗
  382. "01301", // 医院-结算
  383. "01302", // 医院-取药
  384. "01303", // 医院-取报告
  385. "01304", // 医院-打印票据和清单
  386. "01305", // 医院-病历材料复印
  387. "01306", // 医院-诊间核验身份
  388. "02121", // 药店-药店购药
  389. "02122", // 药店-下载外购处方
  390. "02123", // 药店-特殊门诊
  391. "02124", // 药店-药师审核处方
  392. "03131", // 医疗类APP-线上身份认证
  393. "03132", // 医疗类APP-线上结算
  394. "05101", // 柜台-线下修改密码
  395. "05151" // 柜台-医保业务办理
  396. };
  397. return Array.IndexOf(validTypes, businessType) >= 0;
  398. }
  399. #endregion
  400. #region 私有方法
  401. /// <summary>
  402. /// 获取电子凭证查询错误建议
  403. /// </summary>
  404. /// <param name="errorCode">错误码</param>
  405. /// <returns>错误建议</returns>
  406. private static string GetEcQueryErrorSuggestion(int errorCode)
  407. {
  408. switch (errorCode)
  409. {
  410. case -1:
  411. return "请检查网络连接和服务器配置";
  412. case -2:
  413. return "请检查输入参数是否正确";
  414. case -3:
  415. return "请求超时,请稍后重试";
  416. case -4:
  417. return "权限验证失败,请检查密钥配置";
  418. case -5:
  419. return "请求地址无效,请检查EC_URL配置";
  420. default:
  421. return "请联系技术支持或查看详细错误信息";
  422. }
  423. }
  424. #endregion
  425. }
  426. #region Web API控制器示例
  427. /// <summary>
  428. /// 江苏医保电子凭证Web API控制器示例
  429. /// 可以直接集成到ASP.NET Web API项目中
  430. /// </summary>
  431. public class JiangSuEcController : System.Web.Http.ApiController
  432. {
  433. /// <summary>
  434. /// 电子凭证解码接口
  435. /// POST /api/jiangsuec/decode
  436. /// </summary>
  437. /// <param name="request">请求参数</param>
  438. /// <returns>解码结果</returns>
  439. [System.Web.Http.HttpPost]
  440. [System.Web.Http.Route("api/jiangsuec/decode")]
  441. public JObject Decode([System.Web.Http.FromBody] dynamic request)
  442. {
  443. try
  444. {
  445. string businessType = request?.businessType ?? "01101";
  446. string operatorId = request?.operatorId ?? "system001";
  447. string operatorName = request?.operatorName ?? "系统管理员";
  448. string officeId = request?.officeId ?? "32760";
  449. string officeName = request?.officeName ?? "医保科";
  450. return JiangSuEcDecoder.DecodeElectronicCertificate(
  451. businessType, operatorId, operatorName, officeId, officeName);
  452. }
  453. catch (Exception ex)
  454. {
  455. var errorResult = new JObject();
  456. errorResult["success"] = false;
  457. errorResult["code"] = 9001;
  458. errorResult["message"] = $"接口调用异常: {ex.Message}";
  459. errorResult["device"] = "江苏医保电子凭证解码器";
  460. errorResult["timestamp"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  461. return errorResult;
  462. }
  463. }
  464. /// <summary>
  465. /// 初始化接口
  466. /// POST /api/jiangsuec/init
  467. /// </summary>
  468. /// <param name="request">配置参数</param>
  469. /// <returns>初始化结果</returns>
  470. [System.Web.Http.HttpPost]
  471. [System.Web.Http.Route("api/jiangsuec/init")]
  472. public JObject Init([System.Web.Http.FromBody] dynamic request)
  473. {
  474. try
  475. {
  476. JiangSuEcDecoder.JiangSuConfig config = null;
  477. if (request?.config != null)
  478. {
  479. config = new JiangSuEcDecoder.JiangSuConfig();
  480. if (request.config.IP != null) config.IP = (string)request.config.IP;
  481. if (request.config.PORT != null) config.PORT = (int)request.config.PORT;
  482. if (request.config.ORG_ID != null) config.ORG_ID = (string)request.config.ORG_ID;
  483. if (request.config.ACCESS_KEY != null) config.ACCESS_KEY = (string)request.config.ACCESS_KEY;
  484. if (request.config.SECRETKEY != null) config.SECRETKEY = (string)request.config.SECRETKEY;
  485. if (request.config.EC_URL != null) config.EC_URL = (string)request.config.EC_URL;
  486. }
  487. return JiangSuEcDecoder.Initialize(config);
  488. }
  489. catch (Exception ex)
  490. {
  491. var errorResult = new JObject();
  492. errorResult["success"] = false;
  493. errorResult["code"] = 9002;
  494. errorResult["message"] = $"初始化接口异常: {ex.Message}";
  495. errorResult["device"] = "江苏医保电子凭证解码器";
  496. errorResult["timestamp"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  497. return errorResult;
  498. }
  499. }
  500. }
  501. #endregion
  502. }
  503. #region 使用示例
  504. /*
  505. // 使用示例1:基本调用
  506. public void Example1()
  507. {
  508. // 1. 初始化(可选,会自动初始化)
  509. var initResult = JiangSuEcDecoder.Initialize();
  510. Console.WriteLine($"初始化结果: {initResult}");
  511. // 2. 解码电子凭证(门诊挂号)
  512. var decodeResult = JiangSuEcDecoder.DecodeElectronicCertificate(
  513. businessType: "01101", // 门诊挂号
  514. operatorId: "OP001", // 操作员编号
  515. operatorName: "张医生", // 操作员姓名
  516. officeId: "32760", // 科室编号
  517. officeName: "内科" // 科室名称
  518. );
  519. Console.WriteLine($"解码结果: {decodeResult}");
  520. if ((bool)decodeResult["success"])
  521. {
  522. var patientData = decodeResult["data"];
  523. Console.WriteLine($"患者姓名: {patientData["userName"]}");
  524. Console.WriteLine($"身份证号: {patientData["idNo"]}");
  525. Console.WriteLine($"电子凭证令牌: {patientData["ecToken"]}");
  526. }
  527. }
  528. // 使用示例2:自定义配置
  529. public void Example2()
  530. {
  531. // 创建自定义配置
  532. var config = new JiangSuEcDecoder.JiangSuConfig
  533. {
  534. IP = "192.168.1.100", // 医院内网IP
  535. PORT = 8086, // 端口
  536. ORG_ID = "H32132200561", // 医保定点编号
  537. ACCESS_KEY = "your_access_key_here", // 申请的访问密钥
  538. SECRETKEY = "your_secret_key_here", // 申请的秘钥
  539. EC_URL = "http://your.hospital.com:10086/localcfc/api/hsecfc/localQrCodeQuery"
  540. };
  541. // 使用自定义配置初始化
  542. var initResult = JiangSuEcDecoder.Initialize(config);
  543. // 解码电子凭证
  544. var decodeResult = JiangSuEcDecoder.DecodeElectronicCertificate("01301"); // 门诊结算
  545. }
  546. // 使用示例3:Web API集成
  547. public class YourController : ApiController
  548. {
  549. [HttpPost]
  550. public JObject DecodeQRCode([FromBody] dynamic request)
  551. {
  552. string businessType = request?.type ?? "01101";
  553. return JiangSuEcDecoder.DecodeElectronicCertificate(businessType);
  554. }
  555. }
  556. // 使用示例4:JavaScript前端调用
  557. /*
  558. // 前端JavaScript调用示例
  559. $.ajax({
  560. url: "http://localhost:8321/api/jiangsuec/decode",
  561. type: "POST",
  562. contentType: "application/json",
  563. data: JSON.stringify({
  564. businessType: "01101", // 门诊挂号
  565. operatorId: "OP001", // 操作员编号
  566. operatorName: "张医生", // 操作员姓名
  567. officeId: "32760", // 科室编号
  568. officeName: "内科" // 科室名称
  569. }),
  570. success: function(result) {
  571. if (result.success) {
  572. console.log("解码成功:", result.data);
  573. alert("患者: " + result.data.userName + ", 身份证: " + result.data.idNo);
  574. } else {
  575. console.log("解码失败:", result.message);
  576. alert("解码失败: " + result.message);
  577. }
  578. },
  579. error: function(xhr, status, error) {
  580. console.log("请求失败:", error);
  581. alert("网络请求失败");
  582. }
  583. });
  584. */
  585. /*
  586. */
  587. #endregion
  588. </rewritten_file>