ECTokenReader.cs 5.3 KB

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