ECTokenReader.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. using Newtonsoft.Json.Linq;
  2. using PTMedicalInsurance.Helper;
  3. using PTMedicalInsurance.Variables;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Runtime.InteropServices;
  8. using System.Security.Policy;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. namespace PTMedicalInsurance.Common
  12. {
  13. class ECTokenReader
  14. {
  15. //static string URL = "https://fuwu-test.nhsa.gov.cn/localcfc/api/hsecfc/localQrCodeQuery";
  16. [DllImport("NationECCode.dll", EntryPoint = "NationEcTrans", CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)]
  17. static extern string NationEcTrans(string strUrl,string InData,out string OutData);
  18. public static string ECQuery(string EcCertDecodeType) {
  19. Random rd = new Random();
  20. int iNum = rd.Next();
  21. string bizNo = DateTime.Now.ToString("YYYYMMDDHHNNSS") + Global.inf.hospitalNO + iNum.ToString().Substring(0, 5);
  22. ECTokenData eCToken = new ECTokenData();
  23. eCToken.orgId = Global.inf.hospitalNO;
  24. eCToken.operatorId = Global.user.ID;
  25. eCToken.operatorName = Global.user.name;
  26. eCToken.officeId = Global.user.officeID;
  27. eCToken.officeName = Global.user.officeName;
  28. eCToken.businessType = Global.businessType ;
  29. eCToken.outBizNo = bizNo;
  30. eCToken.extData = "";
  31. //认证方式
  32. //二维码
  33. if (EcCertDecodeType == "0")
  34. {
  35. eCToken.deviceType = Global.businessType;
  36. }
  37. //电子凭证
  38. else if (EcCertDecodeType == "1")
  39. {
  40. eCToken.outBizNo = bizNo;
  41. }
  42. //刷脸、先授权后解码
  43. else if (EcCertDecodeType == "2") //刷脸
  44. {
  45. //成功返回授权信息
  46. string auth = "";
  47. faceAuth(out auth, bizNo);
  48. if (!string.IsNullOrEmpty(auth))
  49. {
  50. eCToken.authNo = auth;
  51. }
  52. else {
  53. return "";
  54. }
  55. }
  56. //调用电子凭证动态库NationECCode.dll获取身份信息
  57. string sOutPar = "";
  58. callECQuery(eCToken,"ec.query",out sOutPar);
  59. if (!string.IsNullOrEmpty(sOutPar))
  60. {
  61. Global.pat.ecToken = JsonHelper.getDestValue(JObject.Parse(sOutPar), "data.ecToken");
  62. Global.pat.name = JsonHelper.getDestValue(JObject.Parse(sOutPar), "data.userName");
  63. Global.pat.IDType = JsonHelper.getDestValue(JObject.Parse(sOutPar), "data.idType");
  64. Global.pat.IDNO = JsonHelper.getDestValue(JObject.Parse(sOutPar), "data.idNo");
  65. Global.pat.insuplc_admdvs = JsonHelper.getDestValue(JObject.Parse(sOutPar), "data.insuOrg");
  66. Global.pat.mdtrtcertNO = Global.pat.ecToken;
  67. Global.pat.certType = Global.pat.IDType;
  68. Global.pat.certNO = Global.pat.IDNO;
  69. }
  70. return sOutPar;
  71. }
  72. public static void faceAuth(out string outParam,string bizNo)
  73. {
  74. ECTokenData data = new ECTokenData();
  75. data.outBizNo = bizNo;
  76. data.extData = "";
  77. callECQuery(data, "cn.nhsa.ec.auth", out outParam);
  78. }
  79. private static void callECQuery(ECTokenData eCToken,string transType,out string sOutPar)
  80. {
  81. var input = new ECTokenInput();
  82. input.data = eCToken;
  83. input.orgId = eCToken.orgId;
  84. input.transType = transType; // "ec.query";
  85. input.extra = "";
  86. NationEcTrans(Global.inf.ecURL, JsonHelper.toJsonString(input), out sOutPar);
  87. if (JsonHelper.getDestValue(JObject.Parse(sOutPar), "code") != "0")
  88. {
  89. Global.writeLog("调用认证接口"+transType+"失败:" + sOutPar);
  90. sOutPar = "";
  91. }
  92. }
  93. }
  94. class ECTokenInput
  95. {
  96. /// <summary>
  97. /// 机构代码
  98. /// </summary>
  99. public string orgId { get; set; }
  100. /// <summary>
  101. /// 交易类型
  102. /// </summary>
  103. public string transType { get; set; }
  104. /// <summary>
  105. /// 请求参数
  106. /// </summary>
  107. public ECTokenData data { get; set; }
  108. /// <summary>
  109. /// 扩展参数
  110. /// </summary>
  111. public string extra { get; set; }
  112. }
  113. class ECTokenData
  114. {
  115. /// <summary>
  116. /// 医保定点机构代码
  117. /// </summary>
  118. public string orgId { get; set; }
  119. /// <summary>
  120. /// 用码业务类型
  121. /// </summary>
  122. public string businessType { get; set; }
  123. /// <summary>
  124. /// 收款员编号
  125. /// </summary>
  126. public object operatorId { get; set; }
  127. /// <summary>
  128. /// 收款员姓名
  129. /// </summary>
  130. public string operatorName { get; set; }
  131. /// <summary>
  132. /// 医保科室编号
  133. /// </summary>
  134. public string officeId { get; set; }
  135. /// <summary>
  136. /// 科室名称
  137. /// </summary>
  138. public string officeName { get; set; }
  139. public string outBizNo { get; set; }
  140. public string authNo { get; set; }
  141. public string deviceType { get; set; }
  142. public string extData { get; set; }
  143. }
  144. }