Sfoglia il codice sorgente

pref: 移动支付退费优化

zhengjie 1 anno fa
parent
commit
e300d00412
4 ha cambiato i file con 98 aggiunte e 25 eliminazioni
  1. 35 18
      Business/Local/LocalMobilePayProcess.cs
  2. 54 5
      Helper/InvokeHelper.cs
  3. 8 2
      InsuBusiness.cs
  4. 1 0
      Variables/Struct.cs

+ 35 - 18
Business/Local/LocalMobilePayProcess.cs

@@ -117,6 +117,13 @@ namespace PTMedicalInsurance.Business
             MSettl.clearingWay = JsonHelper.getDestValue(joInsuAdmObj, "psnSetlway");
             MSettl.settlID = JsonHelper.getDestValue(joInsuAdmObj, "payOrdId");
             MSettl.payOrdId = JsonHelper.getDestValue(joInsuAdmObj, "payOrdId");
+            MSettl.onlineYBFalg = JsonHelper.getDestValue(joInsuAdmObj, "onlineYBFalg");
+
+            string medOrdId = JsonHelper.getDestValue(joParam, "med_org_ord");
+            if(!string.IsNullOrEmpty(medOrdId))
+            {
+                MSettl.medins_setl_id = medOrdId;
+            }
         }
 
         public void setPatientByInPar()
@@ -124,6 +131,10 @@ namespace PTMedicalInsurance.Business
             MPat.adm_Dr = int.Parse(JsonHelper.getDestValue(joParam, "admID"));
             Global.pat.adm_Dr = MPat.adm_Dr;
             MPat.name = JsonHelper.getDestValue(joInsuAdmObj, "patName");
+            if (string.IsNullOrEmpty(MPat.name)) {
+                MPat.name = JsonHelper.getDestValue(joInsuAdmObj, "psn_name");
+            }
+            MPat.IDNO = JsonHelper.getDestValue(joInsuAdmObj, "idNo");
             MPat.recordID = JsonHelper.getDestValue(joParam, "recordID");
             MPat.billID = JsonHelper.getDestValue(joParam, "billID");
             MPat.medType = JsonHelper.getDestValue(joInsuAdmObj, "medType");
@@ -218,9 +229,11 @@ namespace PTMedicalInsurance.Business
                 JObject joInput = JObject.Parse(errMsg);
                 // 调用his服务(移动支付院内退款服务)
                 JObject jo6203Rtn = invoker.invokeHISService(JsonHelper.setIrisInpar("05110036", joInput).ToString(), "移动支付退费");
+                //JObject jo6203Rtn = invoker.invokeServiceAsync(JsonHelper.setIrisInpar("05110036", joInput).ToString());
+                Global.writeLog("异步调用返回:"+JsonHelper.toJsonString(jo6203Rtn));
                 if (JsonHelper.parseIrisRtnValue(jo6203Rtn, out errMsg) != 0)
                 {
-                    outPar = errMsg;
+                    outPar = JsonHelper.setIrisReturnValue(-1, errMsg, null).ToString(); ;
                     return -1;
                 }
                 else
@@ -302,11 +315,13 @@ namespace PTMedicalInsurance.Business
             try
             {
                 PatientService patientService = new PatientService();
-                int ret = patientService.trade1161(out outPar);
+                int ret = patientService.readCard(out outPar);
                 if (ret != 0)
                 {
                     return -1;
                 }
+                MPat.ecCardNo = Global.pat.ecCardNo;
+                MPat.ecToken = Global.pat.ecToken;
                 return 0;
             }
             catch (Exception ex)
@@ -626,8 +641,8 @@ namespace PTMedicalInsurance.Business
                 joSetlinfo.Add("AccountPaySumamt", MSettl.accountPaySumamt);//个人账户支出
                 joSetlinfo.Add("PersonCashPay", MSettl.personCashPay);//个人现金支出
                 joSetlinfo.Add("Balance", MSettl.balance);// 余额
-                joSetlinfo.Add("AccountMutualAidAmount", "");//个人账户共济支付金额
-                joSetlinfo.Add("OrganSettlementID", "");//医药机构结算ID
+                joSetlinfo.Add("AccountMutualAidAmount", "0");//个人账户共济支付金额
+                joSetlinfo.Add("OrganSettlementID", MSettl.medins_setl_id);//医药机构结算ID);//医药机构结算ID
                 joSetlinfo.Add("ClearingOrgan", MSettl.clearingOrgan);//清算经办机构
                 joSetlinfo.Add("ClearingWay", MSettl.clearingWay);//清算方式
                 joSetlinfo.Add("ClearingType", MSettl.clearingType);//清算类别
@@ -689,43 +704,45 @@ namespace PTMedicalInsurance.Business
                 //获取医保平台结算信息
                 if (QuerySettleInfo(out errMsg) != 0)
                 {
-                    outparam = errMsg;
+                    outparam = Error(-1, errMsg).Data;
                     return -1;
                 }
                 JObject joRtn = JObject.Parse(errMsg);
                 string settlInfo = JsonHelper.getDestValue(joRtn, "result.data[0]");
                 if (string.IsNullOrEmpty(settlInfo))
                 {
-                    outparam = "没有查询到结算信息,请检查参数";
+                    outparam = Error(-1, "没有查询到结算信息,请检查参数").Data;
                     return -1;
                 }
 
                 // 组织调用参数
                 Global.curEvt.msgid = Global.inf.hospitalNO + DateTime.Now.ToString("yyyyMMddHHmmssffff");
                 JObject joSettl = JObject.Parse(settlInfo);
+                string tradeNo = JsonHelper.getDestValue(joSettl, "OrganSettlementID");
+                if(string.IsNullOrEmpty(tradeNo))
+                {
+                    outparam = Error(-1,"支付交易流水号为空,请核实").Data;
+                    return -1;
+                }
 
                 MPat.settlID = JsonHelper.getDestValue(joSettl, "SettlementID");
                 //入参
-                joInpar.Add("outtradeno", JsonHelper.getDestValue(joSettl, "PayOrdID"));//支付订单号
+                joInpar.Add("outtradeno", tradeNo);//支付订单号(采用本地ID)
                 joInpar.Add("appRefdSn", Global.curEvt.msgid);//应用退款流水号
-                string appRefdTime = JsonHelper.getDestValue(joInsuAdmObj, "appRefdTime");
-                if (string.IsNullOrEmpty(appRefdTime))
-                {
-                    appRefdTime = Utils.GetDateTimeNow();
-                }
                 joInpar.Add("businessType", "DWREFUND");//应用退费时间
-                joInpar.Add("hospitalCode", Global.inf.hospitalNO);
-                joInpar.Add("ec_code", Global.pat.ecToken);
-                joInpar.Add("patName", Global.pat.name);
+                JObject session = Global.curEvt.jaSession?[0].ToObject<JObject>();
+                joInpar.Add("hospitalCode", JsonHelper.getDestValue(session,"hospCode")); //hiscode
+                joInpar.Add("ec_code", MPat.ecToken);
+                joInpar.Add("patName", MPat.name);
                 joInpar.Add("idType", "01");
-                joInpar.Add("idCardNo", Global.pat.IDNO);
+                joInpar.Add("idCardNo", MPat.IDNO);
                 outparam = joInpar.ToString();
                 return 0;
             }
             catch (Exception ex)
             {
 
-                outparam = "Get6203Inpar:" + ex.Message;
+                outparam = Error(-1, ex.Message).Data;
                 return -1;
             }
             finally
@@ -741,7 +758,7 @@ namespace PTMedicalInsurance.Business
             try
             {
                 string sqlStr = "SELECT * FROM BS_MedInsuSettlement WHERE Hospital_Dr=  " + Global.inf.hospitalDr;
-                sqlStr = sqlStr + " and AdmType = 3 and Adm_Dr= " + MPat.adm_Dr + " and PayOrdID= '" + MPat.payOrdId + "'";
+                sqlStr = sqlStr + " and AdmType = 3 and Adm_Dr= " + MPat.adm_Dr + " and PayOrdID= '" + MPat.settlID + "'";
                 JObject joSqlstr = new JObject();
                 joSqlstr.Add("sqlStr", sqlStr);
                 JObject joRtn = mIS.DynamicQuerySettlInfo(joSqlstr);

+ 54 - 5
Helper/InvokeHelper.cs

@@ -27,6 +27,8 @@ using PTMedicalInsurance.Common;
 using PTMedicalInsurance.Variables;
 using System.Runtime.InteropServices;
 using PTMedicalInsurance.Forms;
+using System.Net.Http;
+using System.IO.Compression;
 
 namespace PTMedicalInsurance.Helper
 {
@@ -89,10 +91,8 @@ namespace PTMedicalInsurance.Helper
                 //添加头部信息
                 myRequest.Method = "POST";
                 myRequest.ContentLength = buf.Length;
-                myRequest.ContentType = "application/json";
+                myRequest.ContentType = "application/json;charset=UTF-8";
                 myRequest.Headers.Add("Authorization", authorization);
-                myRequest.MaximumAutomaticRedirections = 1;
-                myRequest.AllowAutoRedirect = true;
                 //发送请求
                 Stream stream = myRequest.GetRequestStream();
                 stream.Write(buf, 0, buf.Length);
@@ -102,15 +102,51 @@ namespace PTMedicalInsurance.Helper
                 HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
                 rtn = getResponseData(myResponse);
                 joRtn = JObject.Parse(rtn);
+                myResponse?.Close();
+                myRequest?.Abort();
+                myResponse = null;
+                myRequest = null;
                 return joRtn;
             }
             catch (Exception ex)
             {
+                Global.writeLog_Iris("访问服务器异常:" + ex.InnerException.Message);
                 joRtn = JsonHelper.setExceptionJson(-1, serviceDesc, ex.Message);
-                rtn = JsonConvert.SerializeObject(joRtn);
                 return joRtn;
             }
         }
+        /// <summary>
+        /// 异步请求调用并返回
+        /// </summary>
+        /// <param name="data"></param>
+        /// <returns></returns>
+        public JObject invokeServiceAsync(string data)
+        {
+            serviceURL = string.Format("{0}/{1}", Global.hisConfig.ip, Global.hisConfig.url);
+            authorization = Global.hisConfig.authorization;
+            Global.writeLog_Iris("开始调用:" + serviceURL);
+            Global.writeLog_Iris(data);
+
+            HttpClient client = new HttpClient();
+            client.Timeout = TimeSpan.FromMinutes(2);
+            client.DefaultRequestHeaders.Add("Authorization", authorization);
+            client.DefaultRequestHeaders.Add("User-Agent", "PostmanRuntime/7.26.8");
+            client.DefaultRequestHeaders.Add("Connection", "keep-alive");
+
+            HttpResponseMessage response = client.PostAsync(serviceURL, new StringContent(data,Encoding.UTF8,"application/json")).Result;
+            var rtn = response.Content.ReadAsStringAsync();
+            Global.writeLog_Iris("服务返回:" + rtn.Result);
+
+            if (response.IsSuccessStatusCode)
+            {
+                return JObject.Parse(rtn.Result);
+            } else
+            {
+                Global.writeLog_Iris("服务调用异常!");
+            }
+
+            return JsonHelper.setExceptionJson(-1, "调用HIS服务", "失败!"+ response.StatusCode);
+        }
 
         /// <summary>
         /// HIS服务调用的封装
@@ -120,6 +156,7 @@ namespace PTMedicalInsurance.Helper
         /// 
         public JObject invokeHISService(string data, string serviceDesc)
         {
+            DateTime startTime = DateTime.Now;
             JObject joRtn = new JObject();
             try
             {
@@ -127,6 +164,7 @@ namespace PTMedicalInsurance.Helper
                 serviceURL = string.Format("{0}/{1}", Global.hisConfig.ip, Global.hisConfig.url);
                 authorization = Global.hisConfig.authorization;
                 joRtn = invokeIrisService(data, serviceDesc);
+                
                 return joRtn;
             }
             catch (Exception ex)
@@ -137,6 +175,9 @@ namespace PTMedicalInsurance.Helper
             finally
             {
                 Global.writeLog_Iris(serviceDesc + "(" + serviceURL + ")" + "Authorization:" + (authorization), JsonHelper.Compress(data), JsonHelper.Compress(joRtn));
+
+                TimeSpan spendTime = DateTime.Now - startTime;
+                Global.writeLog_Iris("调用耗时:(s)" + spendTime.TotalSeconds);
             }
         }
 
@@ -182,7 +223,15 @@ namespace PTMedicalInsurance.Helper
             if (response != null)
             {
                 Stream s = response.GetResponseStream();
-                StreamReader sRead = new StreamReader(s);
+                StreamReader sRead = null;
+                if ("gzip".Equals(response.ContentEncoding))
+                {
+                    sRead = new StreamReader(new GZipStream(s, CompressionMode.Decompress), Encoding.GetEncoding("utf-8"));
+                }
+                else
+                {
+                    sRead = new StreamReader(s, Encoding.GetEncoding("utf-8"));
+                }
                 data = sRead.ReadToEnd();
                 sRead.Close();
                 response.Close();

+ 8 - 2
InsuBusiness.cs

@@ -66,10 +66,16 @@ namespace PTMedicalInsurance
 
                 businessType = JsonHelper.getDestValue(joInParam, "businessType");
                 operationType = JsonHelper.getDestValue(joInParam, "operationType");
-                if ((businessType == "M6") || (businessType == "M6C") || (businessType == "M6Confirm"))
+                if (businessType.Substring(0, 2) == "M6")
                 {
-                    Environment.CurrentDirectory = @"D:\HttpServerAPI\bin";
+                    string onlineYBFalg = JsonHelper.getDestValue(joInParam, "insuAdmObj.onlineYBFalg");
+                    //如果是Y 线上医保,其它或空不是.因WebService不能通过DLL 获取根目录,所以强制指定目录
+                    if (onlineYBFalg == "Y")
+                    {
+                        Environment.CurrentDirectory = @"D:\HttpServerAPI\bin";
+                    }
                 }
+
                 return 0;
             }
             catch (Exception ex)

+ 1 - 0
Variables/Struct.cs

@@ -228,6 +228,7 @@ namespace PTMedicalInsurance.Variables
         public int confirmFlag; //确认标志
         public string onlineYBFalg; //线上线下标志  Y  N
         public string payOrdId; //订单编号
+        public string medins_setl_id; //医疗机构结算ID
     }
 
     //当前环境实时信息