zhengjie 1 year ago
parent
commit
bf03044a43
2 changed files with 88 additions and 54 deletions
  1. 76 45
      Helper/InvokeHelper.cs
  2. 12 9
      InsuBusiness.cs

+ 76 - 45
Helper/InvokeHelper.cs

@@ -27,7 +27,6 @@ using PTMedicalInsurance.Common;
 using PTMedicalInsurance.Variables;
 using System.Runtime.InteropServices;
 using PTMedicalInsurance.Forms;
-using PTMedicalInsurance.Common;
 
 namespace PTMedicalInsurance.Helper
 {
@@ -184,21 +183,47 @@ namespace PTMedicalInsurance.Helper
         private JObject invokeCenterService(string data)
         {
             JObject joRtn = new JObject();
-            IInvokeCenter center = InvokeCenterFactory.create();
-            string outputData = "";
-            string errMsg = "";
-            int iInt = center.Init(ref errMsg);
-            if (iInt == 0)
+            try
             {
-                iInt = center.Business(data, ref outputData, ref errMsg);
-                joRtn = JObject.Parse(outputData);
-                return joRtn;
+                IInvokeCenter center = InvokeCenterFactory.create();
+                string outputData = "";
+                string errMsg = "";
+                int iInt = center.Init(ref errMsg);
+                if (iInt == 0)
+                {
+                    iInt = center.Business(data, ref outputData, ref errMsg);
+                    if (iInt == 0 && !string.IsNullOrEmpty(outputData))
+                    {
+                        try
+                        {
+                            joRtn = JObject.Parse(outputData);
+                        }
+                        catch (Exception ex)
+                        {
+                            joRtn.Add("infcode", iInt);
+                            joRtn.Add("err_msg", "返回参数异常:" + outputData);
+                        }
+                    }
+                    else
+                    {
+                        joRtn.Add("infcode", iInt);
+                        joRtn.Add("err_msg", outputData);
+                        return joRtn;
+                    }
+                    return joRtn;
+                }
+                else
+                {
+                    joRtn.Add("infcode", -1);
+                    joRtn.Add("err_msg", "医保动态库初始化失败invokeInitByDLL:" + errMsg);
+                    return joRtn;
+                }
             }
-            else
+            finally
             {
-                joRtn.Add("infcode", -1);
-                joRtn.Add("err_msg", "医保动态库初始化失败invokeInitByDLL:" + errMsg);
-                return joRtn;
+                Global.writeLog("调用中心:", JsonHelper.Compress(data), joRtn.ToString());
+                // 保存到服务器
+                this.saveCenterLog(JsonHelper.Compress(data), joRtn.ToString(), JsonHelper.Compress(data), joRtn.ToString());
             }
         }
 
@@ -351,45 +376,51 @@ namespace PTMedicalInsurance.Helper
                     }
                 }
 
-                InvokeRestCenter mobileCenter = new InvokeRestCenter();
-                int iInt = mobileCenter.Business(data, ref outputData, ref errMsg);
-                joRtn = JObject.Parse(outputData);
-                
-                Global.writeLog(funNO + "【密文出参】:\r\n" + joRtn.ToString());
-
-                string encData = JsonHelper.getDestValue(joRtn, "encData");
-                string signData = JsonHelper.getDestValue(joRtn, "signData");
-                if (!string.IsNullOrEmpty(encData) && !string.IsNullOrEmpty(signData))
+                try
                 {
-                    joRtn.Remove("encData");
-                    joRtn.Remove("signData");
-                    joRtn.Remove("data");
-                    //解密
-                    string decData = encrypt.decrypt(encData);
-                    // 验签
-                    JsonConvert.DefaultSettings = () => new JsonSerializerSettings
-                    {
-                        FloatParseHandling = FloatParseHandling.Decimal
-                    };
-                    joRtn.Add("data", JToken.FromObject(JsonConvert.DeserializeObject(decData)));
+                    InvokeRestCenter mobileCenter = new InvokeRestCenter();
+                    int iInt = mobileCenter.Business(data, ref outputData, ref errMsg);
+                    joRtn = JObject.Parse(outputData);
 
-                    bool rtn = encrypt.verify(joRtn, signData);
-                    if (rtn)
-                    {
-                        Global.writeLog(funNO + "【明文出参】:\r\n" + decData);
+                    Global.writeLog(funNO + "【密文出参】:\r\n" + joRtn.ToString());
 
-                        joRtn = JObject.Parse(decData);
-                        joRtn.Add("success", "True");
-                    }
-                    else
+                    string encData = JsonHelper.getDestValue(joRtn, "encData");
+                    string signData = JsonHelper.getDestValue(joRtn, "signData");
+                    if (!string.IsNullOrEmpty(encData) && !string.IsNullOrEmpty(signData))
                     {
-                        Global.writeLog("验签失败,请核查!");
+                        joRtn.Remove("encData");
+                        joRtn.Remove("signData");
+                        joRtn.Remove("data");
+                        //解密
+                        string decData = encrypt.decrypt(encData);
+                        // 验签
+                        JsonConvert.DefaultSettings = () => new JsonSerializerSettings
+                        {
+                            FloatParseHandling = FloatParseHandling.Decimal
+                        };
+                        joRtn.Add("data", JToken.FromObject(JsonConvert.DeserializeObject(decData)));
+
+                        bool rtn = encrypt.verify(joRtn, signData);
+                        if (rtn)
+                        {
+                            Global.writeLog(funNO + "【明文出参】:\r\n" + decData);
+
+                            joRtn = JObject.Parse(decData);
+                            joRtn.Add("success", "True");
+                        }
+                        else
+                        {
+                            Global.writeLog("验签失败,请核查!");
+                        }
                     }
-                }
 
-                return joRtn;
+                    return joRtn;
 
-                
+                }
+                finally
+                {
+                    this.saveCenterLog(JsonHelper.Compress(data), joRtn.ToString(), JsonHelper.Compress(data), joRtn.ToString());
+                }
 
             }
             catch (Exception ex)

+ 12 - 9
InsuBusiness.cs

@@ -401,15 +401,18 @@ namespace PTMedicalInsurance
                             if (cBus.cancleRegister("2404", out outParam) != 0)
                             {
                                 //如果医保中心没有HIS所传的医保登记信息则默认撤销HIS登记信息
-                                int i = outParam.IndexOf("不存在有效的就诊登记信息");
-                                if (i != 0)
-                                {
-                                    if (DialogResult.Yes != MessageBox.Show("医保中心提示:" + outParam+ ",是否强制撤销HIS医保登记信息?", "提示", MessageBoxButtons.YesNo))
-                                    {
-                                        rtnResult = JsonHelper.setExceptionJson(-1, "中心取消登记失败,", outParam).ToString();
-                                        return rtnResult;
-                                    }
-                                }
+                                //int i = outParam.IndexOf("不存在有效的就诊登记信息");
+                                //if (i != 0)
+                                //{
+                                //    if (DialogResult.Yes != MessageBox.Show("医保中心提示:" + outParam+ ",是否强制撤销HIS医保登记信息?", "提示", MessageBoxButtons.YesNo))
+                                //    {
+
+                                //        return rtnResult;
+                                //    }
+                                //}
+                                rtnResult = JsonHelper.setExceptionJson(-1, "中心取消登记失败,", outParam).ToString();
+                                return rtnResult;
+
                             }
 
                             //取消医保平台登记