CardReader.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  1. /******************************************************************************
  2. * 文件名称: CardReader.cs
  3. * 文件说明: 读卡的封装,包括社保卡,身份证,电子凭证等等
  4. * 当前版本: V1.0
  5. * 创建日期: 2022-06-20
  6. *
  7. * * 2020-06-20: 增加 CardReader 类
  8. * ***** 2020-06-20: 增加 CardReader 方法,获取URL地址,USER信息,地方版SSCard.dll使用
  9. * ***** 2020-06-20: 增加 CardReader 方法重载,国家版电子凭证使用
  10. * ***** 2020-06-20: 增加 Init 方法,SSCard环境初始化
  11. * ***** 2020-06-20: 增加 ReadCardBas 方法,读社保卡
  12. * ***** 2020-06-20: 增加 VerifyPIN 方法,验证密码
  13. * ***** 2020-06-20: 增加 ChangePIN 方法,修改密码
  14. * ***** 2020-06-20: 增加 ReadSFZ 方法,读身份证
  15. * ***** 2020-06-20: 增加 GetQRBase 方法,读二维码
  16. * ***** 2020-06-20: 增加 NationEcTrans 方法,读电子凭证(国家版)
  17. ******************************************************************************/
  18. using System;
  19. using System.Collections.Generic;
  20. using System.Linq;
  21. using System.Reflection;
  22. using System.Runtime.InteropServices;
  23. using System.Text;
  24. using System.Threading.Tasks;
  25. using PTMedicalInsurance.Variables;
  26. using PTMedicalInsurance.Helper;
  27. using Newtonsoft.Json;
  28. using Newtonsoft.Json.Linq;
  29. using System.Windows.Forms;
  30. using Sunny.UI;
  31. using System.Security.Policy;
  32. using System.IO;
  33. namespace PTMedicalInsurance.Common
  34. {
  35. class CardReader
  36. {
  37. private string URL;
  38. private string User;
  39. public CardReader()
  40. {
  41. }
  42. public CardReader(string URL, string User)
  43. {
  44. this.URL = URL;
  45. this.User = User;
  46. }
  47. const string DllPath = @"D:\CardDLL\SSCard.dll";
  48. [DllImport("SSCard.dll", EntryPoint = "Init", CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)]
  49. static extern int Init(StringBuilder pURL, StringBuilder pUser);
  50. [DllImport("SSCard.dll", EntryPoint = "ReadCardBas", CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)]
  51. static extern int ReadCardBas(StringBuilder pOutBuff, int nOutBuffLen, StringBuilder pSignBuff, int nSignBuffLen);
  52. [DllImport("SSCard.dll", EntryPoint = "VerifyPIN", CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)]
  53. static extern int VerifyPIN(StringBuilder pOutBuff, int nOutBuffLen);
  54. [DllImport("SSCard.dll", EntryPoint = "ChangePIN", CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)]
  55. static extern int ChangePIN(StringBuilder pOutBuff, int nOutBuffLen);
  56. [DllImport("SSCard.dll", EntryPoint = "ReadSFZ", CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)]
  57. static extern int ReadSFZ(StringBuilder pOutBuff, int nOutBuffLen, StringBuilder pSignBuff, int nSignBuffLen);
  58. [DllImport("SSCard.dll", EntryPoint = "GetQRBase", CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)]
  59. static extern int GetQRBase(int nTimeout, StringBuilder pOutBuff, int nOutBuffLen, StringBuilder pSignBuff, int nSignBuffLen);
  60. //电子凭证
  61. [DllImport("NationECCode.dll", EntryPoint = "NationEcTrans", CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)]
  62. static extern IntPtr NationEcTrans(StringBuilder strUrl, StringBuilder InData, StringBuilder OutData);
  63. public int Init()
  64. {
  65. string errMsg = "";
  66. int result = -1;
  67. try
  68. {
  69. StringBuilder sbURL = new StringBuilder(URL);
  70. StringBuilder sbUSER = new StringBuilder(User);
  71. result = Init(sbURL, sbUSER);
  72. return result;
  73. }
  74. catch (Exception ex)
  75. {
  76. errMsg = ex.Message;
  77. return result;
  78. }
  79. finally
  80. {
  81. Global.writeLog("初始化", URL + ":" + User, result.ToString() + ":" + errMsg);
  82. }
  83. }
  84. public int ReadCardBas(out string basInfo, out string regInfo)
  85. {
  86. basInfo = ""; regInfo = "";
  87. int rtn = -1;
  88. try
  89. {
  90. StringBuilder sbBasInfo = new StringBuilder(1024);
  91. StringBuilder sbRegInfo = new StringBuilder(1024);
  92. rtn = ReadCardBas(sbBasInfo, 1024, sbRegInfo, 1024);
  93. basInfo = sbBasInfo.ToString();
  94. regInfo = sbRegInfo.ToString();
  95. return rtn;
  96. }
  97. catch (Exception ex)
  98. {
  99. basInfo = "ReadCardBas异常:" + ex.Message;
  100. return rtn;
  101. }
  102. finally
  103. {
  104. Global.writeLog("读社保卡(" + URL + ")", regInfo, basInfo);
  105. }
  106. }
  107. public int VerifyPIN(out string outBuff)
  108. {
  109. outBuff = "";
  110. int rtn = -1;
  111. try
  112. {
  113. StringBuilder sbOutBuff = new StringBuilder(1024);
  114. rtn = VerifyPIN(sbOutBuff, 1024);
  115. outBuff = sbOutBuff.ToString();
  116. return rtn;
  117. }
  118. catch (Exception ex)
  119. {
  120. outBuff = "VerifyPIN:" + ex.Message;
  121. return rtn;
  122. }
  123. }
  124. public int ChangePIN(out string outBuff)
  125. {
  126. outBuff = "";
  127. int rtn = -1;
  128. try
  129. {
  130. StringBuilder sbOutBuff = new StringBuilder(1024);
  131. rtn = ChangePIN(sbOutBuff, 1024);
  132. outBuff = sbOutBuff.ToString();
  133. return rtn;
  134. }
  135. catch (Exception ex)
  136. {
  137. outBuff = "ChangePIN:" + ex.Message;
  138. return rtn;
  139. }
  140. }
  141. public int ReadSFZ(out string OutBuff, out string SignBuff)
  142. {
  143. OutBuff = ""; SignBuff = "";
  144. int rtn = -1;
  145. try
  146. {
  147. StringBuilder sbOutBuff = new StringBuilder(1024);
  148. StringBuilder sbSignBuff = new StringBuilder(1024);
  149. rtn = ReadSFZ(sbOutBuff, 1024, sbSignBuff, 1024);
  150. OutBuff = sbOutBuff.ToString();
  151. SignBuff = sbSignBuff.ToString();
  152. return rtn;
  153. }
  154. catch (Exception ex)
  155. {
  156. OutBuff = "ReadSFZ 异常:" + ex.Message;
  157. return rtn;
  158. }
  159. }
  160. public int GetQRBase(int timeout, out string OutBuff, out string SignBuff)
  161. {
  162. OutBuff = ""; SignBuff = "";
  163. int rtn = -1;
  164. try
  165. {
  166. StringBuilder sbOutBuff = new StringBuilder(1024);
  167. StringBuilder sbSignBuff = new StringBuilder(1024);
  168. rtn = GetQRBase(timeout, sbOutBuff, 1024, sbSignBuff, 1024);
  169. OutBuff = sbOutBuff.ToString();
  170. SignBuff = sbSignBuff.ToString();
  171. return rtn;
  172. }
  173. catch (Exception ex)
  174. {
  175. OutBuff = "GetQRBase 异常:" + ex.Message;
  176. return rtn;
  177. }
  178. }
  179. public string NationEcTrans(string URL, string InData, out string OutData)
  180. {
  181. OutData = "";
  182. try
  183. {
  184. StringBuilder sbURL = new StringBuilder(URL);
  185. StringBuilder sbInData = new StringBuilder(InData);
  186. StringBuilder sbOutData = new StringBuilder(1024);
  187. IntPtr pRtn = NationEcTrans(sbURL, sbInData, sbOutData);
  188. OutData = sbOutData.ToString();
  189. string rtn = Marshal.PtrToStringAnsi(pRtn);
  190. return rtn;
  191. }
  192. catch (Exception ex)
  193. {
  194. OutData = "NationEcTrans 异常:" + ex.Message;
  195. return "-1";
  196. }
  197. finally
  198. {
  199. Global.writeLog("电子凭证(" + URL + ")", InData, OutData);
  200. }
  201. }
  202. }
  203. class CardReader_HLJ
  204. {
  205. string progID = "SCardDriverHLJ.SCard";
  206. System.Type ComType;
  207. object ComInstance;
  208. public CardReader_HLJ()
  209. {
  210. ComType = Type.GetTypeFromProgID(progID);
  211. // 创建Com的实例
  212. if (ComType != null)
  213. {
  214. //创建实例
  215. ComInstance = Activator.CreateInstance(ComType);
  216. }
  217. }
  218. public string readCardBas(int type, string hospNO)
  219. {
  220. if (ComType == null)
  221. {
  222. return "ComType为空!";
  223. }
  224. if (ComInstance == null)
  225. {
  226. return "ComInstance为空!";
  227. }
  228. try
  229. {
  230. //设置需要设置的参数值
  231. object[] ParamArray = new object[2];
  232. ParamArray[0] = type;
  233. ParamArray[1] = hospNO;
  234. ParameterModifier[] ParamMods = new ParameterModifier[1];
  235. ParamMods[0] = new ParameterModifier(2); // 初始化为接口参数的个数
  236. ParamMods[0][0] = true;
  237. ParamMods[0][1] = true; // 设置第二个参数为返回参数,调用含有ParameterModifier数组的重载函数
  238. object o = ComType.InvokeMember("iReadCardBas", // 接口函数名
  239. BindingFlags.Default | BindingFlags.InvokeMethod,
  240. null,
  241. ComInstance, // 调用的COM组件
  242. ParamArray, // 参数数组
  243. ParamMods, // 指定返回参数的ParameterModifier数组
  244. null,
  245. null);
  246. //string Msg = "加载成功:" + ParamArray[1].ToString();
  247. //Global.inf.writeLog(Msg + "___" + ParamArray[0].ToString());
  248. return o.ToString();
  249. }
  250. catch (Exception ex)
  251. {
  252. return "异常:" + ex.Message;
  253. }
  254. }
  255. }
  256. class ChangChun_DRG
  257. {
  258. //长春市DRG付费管理
  259. #region【长春东软DRG微服务版动态库相关调用】
  260. [DllImport("HmaSiInterface.dll", EntryPoint = "INIT", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)]
  261. public static extern int INIT_DRG(ref StringBuilder pErrMsg);
  262. //BASE64 编码函数
  263. [DllImport("HmaSiInterface.dll", EntryPoint = "PASCAL EXPORT FileToBase64", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)]
  264. public static extern int PASCALEXPORTFileToBase64_DRG(StringBuilder filePath, ref StringBuilder OutData, int len);
  265. //交易函数
  266. [DllImport("HmaSiInterface.dll", EntryPoint = "BUSINESS_HANDLE", CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)]
  267. public static extern int BUSINESS_HANDLE_DRG(string InData, StringBuilder OutData);
  268. /// <summary>
  269. /// DRG动态库初始化-INIT
  270. /// </summary>
  271. /// <param name="Msg"></param>
  272. /// <returns></returns>
  273. public int Init_DRG(out string Msg)
  274. {
  275. string errMsg = ""; Msg = "";
  276. int rnt = -1;
  277. JObject joRtn = new JObject();
  278. try
  279. {
  280. StringBuilder sbReMsg = new StringBuilder(2048);
  281. rnt = INIT_DRG(ref sbReMsg);
  282. Msg = sbReMsg.ToString();
  283. return rnt;
  284. }
  285. catch (Exception ex)
  286. {
  287. if (joRtn["infcode"] == null)
  288. { joRtn.Add("infcode", -1); }
  289. if (joRtn["err_msg"] == null)
  290. { joRtn.Add("err_msg", "INIT_DRG异常:" + ex.Message); }
  291. Msg = JsonHelper.Compress(joRtn);
  292. return rnt;
  293. }
  294. finally
  295. {
  296. Global.writeLog("Init_DRG初始化", "", rnt.ToString() + ": 无入参!");
  297. }
  298. }
  299. /// <summary>
  300. /// DRG动态库交易函数调用-BUSINESS_HANDLE
  301. /// </summary>
  302. /// <param name="Input"></param>
  303. /// <param name="OutPut"></param>
  304. /// <returns></returns>
  305. public int Business_DRG(string Input, out string OutPut)
  306. {
  307. string errMsg = ""; OutPut = "";
  308. int rnt = -1;
  309. JObject joRtn = new JObject();
  310. try
  311. {
  312. StringBuilder sbOutInfo = new StringBuilder(1024);
  313. MessageBox.Show("业务入参:"+Input);
  314. rnt = BUSINESS_HANDLE_DRG(Input, sbOutInfo);
  315. MessageBox.Show("返回值:"+ rnt.ToString()+ ", "+sbOutInfo.ToString());
  316. OutPut = sbOutInfo.ToString();
  317. return rnt;
  318. }
  319. catch (Exception ex)
  320. {
  321. if (joRtn["infcode"] == null)
  322. { joRtn.Add("infcode", -1); }
  323. if (joRtn["err_msg"] == null)
  324. { joRtn.Add("err_msg", "BUSINESS_HANDLE_DRG异常:" + ex.Message); }
  325. OutPut = JsonHelper.Compress(joRtn);
  326. return rnt;
  327. }
  328. finally
  329. {
  330. Global.writeLog("BUSINESS_HANDLE_DRG业务调用", Input, OutPut);
  331. }
  332. }
  333. /// <summary>
  334. /// DRG动态库交易函数调用-BUSINESS_HANDLE
  335. /// </summary>
  336. /// <param name="filePath"></param>
  337. /// <param name="OutPut"></param>
  338. /// <param name="DataLen"></param>
  339. /// <returns></returns>
  340. public int FileToBase64_DRG(string filePath, out string OutPut, int DataLen)
  341. {
  342. string errMsg = ""; OutPut = "";
  343. int rnt = -1, retLen = 0;
  344. JObject joRtn = new JObject();
  345. try
  346. {
  347. StringBuilder sbInputInfo = new StringBuilder(filePath);
  348. StringBuilder sbOutInfo = new StringBuilder(1024);
  349. retLen = DataLen;
  350. rnt = PASCALEXPORTFileToBase64_DRG(sbInputInfo, ref sbOutInfo, retLen);
  351. OutPut = sbOutInfo.ToString();
  352. return rnt;
  353. }
  354. catch (Exception ex)
  355. {
  356. if (joRtn["infcode"] == null)
  357. { joRtn.Add("infcode", -1); }
  358. if (joRtn["err_msg"] == null)
  359. { joRtn.Add("err_msg", "PASCALEXPORTFileToBase64_DRG异常:" + ex.Message); }
  360. OutPut = JsonHelper.Compress(joRtn);
  361. return rnt;
  362. }
  363. finally
  364. {
  365. Global.writeLog("PASCALEXPORTFileToBase64_DRG业务调用", filePath, OutPut);
  366. }
  367. }
  368. #endregion
  369. }
  370. class CardReader_JIL
  371. { //吉林基线版东软读卡
  372. #region
  373. //初始化
  374. [DllImport("HeaSecReadInfo.dll", EntryPoint = "Init", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)]
  375. public static extern int Init([MarshalAs(UnmanagedType.LPArray)] byte[] pInitInfo, [MarshalAs(UnmanagedType.LPArray)] byte[] pErrMsg);
  376. [DllImport("HeaSecReadInfo.dll", EntryPoint = "ReadCardBas", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)]
  377. public static extern int ReadCardBas([MarshalAs(UnmanagedType.LPArray)] byte[] pCardInfo, [MarshalAs(UnmanagedType.LPArray)] byte[] pBusiCardInfo);
  378. //[DllImport("NationECCode.dll", EntryPoint = "NationEcTrans", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
  379. //public static extern long NationEcTrans(string strUrl, string InData, [MarshalAs(UnmanagedType.LPArray)] byte[] OutData);
  380. [DllImport("NationECCode.dll", EntryPoint = "NationEcTrans", CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)]
  381. static extern IntPtr NationEcTrans(StringBuilder strUrl, StringBuilder InData, StringBuilder OutData);
  382. [DllImport("HeaSecReadInfo.dll", EntryPoint = "VerifyPIN", CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
  383. public static extern int VerifyPIN([MarshalAs(UnmanagedType.LPArray)] byte[] pOutBuff);
  384. [DllImport("HeaSecReadInfo.dll", EntryPoint = "ReadSFZ", CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)]
  385. public static extern int ReadSFZ([MarshalAs(UnmanagedType.LPArray)] byte[] pPath, [MarshalAs(UnmanagedType.LPArray)] byte[] pOutBuff, [MarshalAs(UnmanagedType.LPArray)] byte[] pOutBusiBuff);
  386. [DllImport("HeaSecReadInfo.dll", EntryPoint = "GetClientID", CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)]
  387. public static extern int GetClientID([MarshalAs(UnmanagedType.LPArray)] byte[] pOutBuff);
  388. // [DllImport("NationECCode.dll", EntryPoint = "NationEcTrans", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
  389. // public static extern long NationEcTrans([MarshalAs(UnmanagedType.LPArray)] byte[] strUrl, [MarshalAs(UnmanagedType.LPArray)] byte[] InData, [MarshalAs(UnmanagedType.LPArray)] byte[] OutData);
  390. #endregion
  391. public int initCard()
  392. {
  393. int rtn = 0;
  394. try
  395. {
  396. string str = "{\"IP\":\"ddjk.jlhs.gov.cn\",\"PORT\":20215,\"TIMEOUT\":60,\"LOG_PATH\":\"C:/neu_log/\",\"SFZ_DRIVER_TYPE\":1}";
  397. byte[] input = System.Text.Encoding.Default.GetBytes(str);
  398. byte[] output = new byte[300];
  399. rtn = Init(input, output);
  400. }
  401. catch (Exception e)
  402. {
  403. rtn = -1;
  404. MessageBox.Show(e.Message);
  405. }
  406. return rtn;
  407. }
  408. public int readCard(out string Instr, out string outstr)
  409. {
  410. int rtn = 0;
  411. Instr = "";
  412. outstr = "";
  413. try
  414. {
  415. if (initCard() != 0)
  416. {
  417. rtn = -1;
  418. return rtn;
  419. }
  420. byte[] rin = new byte[500];
  421. byte[] rout = new byte[500];
  422. if (ReadCardBas(rin, rout) != 0)
  423. {
  424. rtn = -1;
  425. MessageBox.Show(System.Text.Encoding.Default.GetString(rin));
  426. return rtn;
  427. }
  428. Instr = System.Text.Encoding.Default.GetString(rin);
  429. outstr = System.Text.Encoding.Default.GetString(rout);
  430. }
  431. catch (Exception e)
  432. {
  433. rtn = -1; MessageBox.Show(e.Message);
  434. }
  435. return rtn;
  436. }
  437. //读身份证
  438. public int readSFZ(out string Instr, out string outstr)
  439. {
  440. int rtn = 0;
  441. Instr = "";
  442. outstr = "";
  443. string pth = @"D:/";
  444. try
  445. {
  446. if (initCard() != 0)
  447. {
  448. rtn = -1;
  449. return rtn;
  450. }
  451. byte[] Pth = new byte[500];
  452. byte[] rin = new byte[500];
  453. byte[] rout = new byte[500];
  454. Pth = System.Text.Encoding.Default.GetBytes(pth);
  455. if (ReadSFZ(Pth,rin, rout) != 0)
  456. {
  457. rtn = -1;
  458. MessageBox.Show(System.Text.Encoding.Default.GetString(rin));
  459. return rtn;
  460. }
  461. Instr = System.Text.Encoding.Default.GetString(rin);
  462. outstr = System.Text.Encoding.Default.GetString(rout);
  463. }
  464. catch (Exception e)
  465. {
  466. rtn = -1; MessageBox.Show(e.Message);
  467. }
  468. return rtn;
  469. }
  470. public int getCid(out string outstr)
  471. {
  472. int rtn = 0;
  473. outstr = "";
  474. try
  475. {
  476. if (initCard() != 0)
  477. {
  478. rtn = -1;
  479. return rtn;
  480. }
  481. byte[] rout = new byte[500];
  482. GetClientID(rout);
  483. outstr = System.Text.Encoding.Default.GetString(rout);
  484. }
  485. catch (Exception e)
  486. {
  487. rtn = -1; MessageBox.Show(e.Message);
  488. }
  489. return rtn;
  490. }
  491. //public int InsuQRCodeQuery(string url,string instr,out string outpar)
  492. //{
  493. // int rtn = 0;
  494. // string data = "{\"data\": {\"operatorId\": \"008\", \"operatorName\": \"TEST\", \"officeId\": \"01\",\"officeName\": \"内科\",\"orgId\": \"1234567\",\"businessType\": \"01101\", \"deviceType\": \"SelfService\"},\"orgId\": \"1234567\",\"transType\": \"ec.query\"}";
  495. // url = "";
  496. // JObject input = new JObject();
  497. // byte[] str = new byte[500];
  498. // //outstr = "";
  499. // try
  500. // {
  501. // NationEcTrans(url, data, str);
  502. // outpar = System.Text.Encoding.Default.GetString(str);
  503. // dynamic outputObj = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(outpar);
  504. // MessageBox.Show(outpar);
  505. // }
  506. // catch (Exception e)
  507. // {
  508. // rtn = -1; MessageBox.Show(e.Message);
  509. // outpar = "";
  510. // }
  511. // return rtn;
  512. //}
  513. public string InsuQRCodeQuery(string URL, string InData, out string OutData)
  514. {
  515. // MessageBox.Show("进入医保电子凭读卡");
  516. // MessageBox.Show("入参:" + URL + ":" + InData);
  517. OutData = "";
  518. try
  519. {
  520. StringBuilder sbURL = new StringBuilder(URL);
  521. StringBuilder sbInData = new StringBuilder(InData);
  522. StringBuilder sbOutData = new StringBuilder(2048);
  523. IntPtr pRtn = NationEcTrans(sbURL, sbInData, sbOutData);
  524. OutData = sbOutData.ToString();
  525. string rtn = Marshal.PtrToStringAnsi(pRtn);
  526. return rtn;
  527. }
  528. catch (Exception ex)
  529. {
  530. OutData = "NationEcTrans 异常:" + ex.Message;
  531. return "-1";
  532. }
  533. finally
  534. {
  535. Global.writeLog("电子凭证(" + URL + ")", InData, OutData);
  536. }
  537. }
  538. //public string InsuQRCodeQuery(string url, string instr, out string outpar)
  539. //{
  540. // string code = "0", message = "成功", outResult = "";
  541. // //dynamic inputEmpParamsObj = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(inParams);
  542. // int initFlag = 0;
  543. // MessageBox.Show("进入医保电子凭读卡");
  544. // MessageBox.Show("入参:"+ url + ":"+ instr);
  545. // try
  546. // {
  547. // MessageBox.Show("进入try");
  548. // //string strUrl = inputEmpParamsObj.url.ToString(); // "http://10.38.22.15:8081/localcfc/api/hsecfc/localQrCodeQuery";
  549. // string strUrl = url;
  550. // byte[] strUrlData = System.Text.Encoding.Default.GetBytes(strUrl);
  551. // //string inputStr = inputEmpParamsObj.inputData.ToString();
  552. // string inputStr = instr;
  553. // //"{\"data\":{\"businessType\":\"01101\",\"deviceType\":\"\",\"officeId\":\"32760\",\"officeName\":\"消化内科\",\"operatorId\":\"test001\",\"operatorName\":\"超级管理员\",\"orgId\":\"3502031900111\"},\"orgId\":\"35020319001\",\"transType\":\"ec.query\"}";
  554. // byte[] inputData = new byte[2048];
  555. // byte[] ecUrl = new byte[2048];
  556. // ecUrl= System.Text.Encoding.Default.GetBytes(strUrl);
  557. // inputData = System.Text.Encoding.Default.GetBytes(instr);
  558. // MessageBox.Show("进入try1");
  559. // byte[] outputData = new byte[2048];
  560. // string outputStr = "";
  561. // long retData = NationEcTrans(ecUrl, inputData, outputData);
  562. // MessageBox.Show("进入try2");
  563. // outputStr = System.Text.Encoding.Default.GetString(outputData);
  564. // outputStr = CheckStr(outputStr);
  565. // dynamic outputObj = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(outputStr);
  566. // MessageBox.Show("进入try3");
  567. // if (outputObj.code != "0")
  568. // {
  569. // code = "-100";
  570. // message = "读取医保电子凭证失败:" + outputObj.message;
  571. // MessageBox.Show("进入try4");
  572. // }
  573. // else
  574. // {
  575. // MessageBox.Show("进入try5");
  576. // message = ""; //ecQrCode
  577. // string ecToken = outputObj.data.ecToken;
  578. // string ecQrCode = outputObj.data.ecQrCode;
  579. // string ecIndexNo = outputObj.data.ecIndexNo;
  580. // var result = new { ecToken = ecToken, ecQrCode = ecQrCode, ecIndexNo = ecIndexNo };
  581. // var resultObj = new { errorCode = "0", errorMessage = "", result = result };
  582. // string resultStr = JsonConvert.SerializeObject(resultObj);
  583. // MessageBox.Show("进入try6");
  584. // outpar = resultStr;
  585. // MessageBox.Show("电子凭证返参:"+ outpar);
  586. // return resultStr;
  587. // }
  588. // }
  589. // catch (Exception error)
  590. // {
  591. // code = "-1000";
  592. // message = "产生异常" + error.ToString();
  593. // }
  594. // var outlist = new { errorCode = code, errorMessage = message };
  595. // string outSerialize = JsonConvert.SerializeObject(outlist);
  596. // outpar = "";
  597. // return outSerialize;
  598. //}
  599. public static string CheckStr(string str)
  600. {
  601. int len = str.Length;
  602. string newStr = "";
  603. for (var i = 0; i < len; i++)
  604. {
  605. if ((int)System.Text.Encoding.Default.GetBytes(str.Substring(i, 1))[0] > 0)
  606. {
  607. string ret = str.Substring(i, 1);
  608. newStr = newStr + ret;
  609. }
  610. }
  611. return newStr;
  612. }
  613. }
  614. }