瀏覽代碼

feat:读卡调整

zhengjie 1 年之前
父節點
當前提交
7eeff9d69e
共有 2 個文件被更改,包括 10 次插入8 次删除
  1. 9 2
      Common/CardReader.cs
  2. 1 6
      Common/ECTokenReader.cs

+ 9 - 2
Common/CardReader.cs

@@ -35,6 +35,7 @@ namespace PTMedicalInsurance.Common
     class CardReader
     {
         const string DllPath = @"HeaSecReadInfo.dll";
+        private static bool initilaized = false;
 
         [DllImport(DllPath, EntryPoint = "Init", CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)]
         static extern int Init(StringBuilder pInitInfo, StringBuilder pErrMsg);
@@ -48,13 +49,18 @@ namespace PTMedicalInsurance.Common
         [DllImport(DllPath, EntryPoint = "DailySinIn", CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)]
         static extern IntPtr DailySinIn(StringBuilder OutData);
 
+        //电子凭证
+        [DllImport("HeaSecReadInfo.dll", EntryPoint = "EcQuery", CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)]
+        public static extern int NationEcTrans(StringBuilder InData, StringBuilder OutData);
+
         public CardReader()
         {
-
+            CardReader.Init();
         }
 
-        public int Init()
+        public static int Init()
         {
+            if (initilaized) return 0;
             string errMsg = "";
             int result = -1;
             try
@@ -65,6 +71,7 @@ namespace PTMedicalInsurance.Common
                 StringBuilder sbUSER = new StringBuilder(4096);
                 sbInitInfo.Append(JsonHelper.toJsonString(initInfo));
                 result = Init(sbInitInfo, sbUSER);
+                initilaized = true;
                 return result;
             }
             catch (Exception ex)

+ 1 - 6
Common/ECTokenReader.cs

@@ -19,11 +19,6 @@ namespace PTMedicalInsurance.Common
         //[DllImport("NationECCode.dll", EntryPoint = "NationEcTrans", CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)]
         //static extern string NationEcTrans(string strUrl,string InData,StringBuilder OutData);
 
-        //电子凭证
-        [DllImport("HeaSecReadInfo.dll", EntryPoint = "EcQuery", CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)]
-        static extern int NationEcTrans(StringBuilder InData, StringBuilder OutData);
-
-
         public static string ECQuery(string EcCertDecodeType) {
             Random rd = new Random();
             int iNum = rd.Next();
@@ -120,7 +115,7 @@ namespace PTMedicalInsurance.Common
                 Global.writeLog("开始调用ECToken:"+ inputParam);
                 StringBuilder sbOut = new StringBuilder(40960);
                 //string strToken = NationEcTrans(Global.inf.ecURL, inputParam, sbOut);
-                int pInt = NationEcTrans(sbInput, sbOut);
+                int pInt = CardReader.NationEcTrans(sbInput, sbOut);
                 sOutPar = parseECTokenOutput(sbOut.ToString());
 
                 Global.writeLog("EcToken返回:"+pInt,inputParam,sOutPar);