/// <summary> /// 生成rd中的支付信息 /// </summary> /// <param name="xmlRd">rd字符串</param> /// <param name="payment">支付信息</param> /// <param name="seq">支付顺序</param> /// <returns></returns> private string dealwithPaymentRd(string xmlRd, PaymentInfo payment, int seq) { string ret = string.Empty; string error = string.Empty; var acct = payment.bankAcnt.acntNo.Trim(); //工行账户,支付方 if (acct.Length < 19) { error = string.Format("账号长度错误!", payment.bankAcnt.acntNo); throw new Exception(error); } InstallContext ic = new InstallContext(); //初始化数据 string name = string.Empty; object obj = null; //本方账户 Type type = payment.bankAcnt.GetType(); PropertyInfo[] ps = type.GetProperties(); foreach (PropertyInfo i in ps) { obj = i.GetValue(payment.bankAcnt, null); name = "bankAcnt_" + i.Name; if (obj != null) { ic.Set(name, obj.ToString()); } else { ic.Set(name, " "); } } //对方账户 type = payment.oppoBankAcnt.GetType(); ps = type.GetProperties(); foreach (PropertyInfo i in ps) { obj = i.GetValue(payment.oppoBankAcnt, null); name = "oppoBankAcnt_" + i.Name; if (obj != null) { ic.Set(name, obj.ToString()); } else { ic.Set(name, " "); } } //付款单 type = payment.GetType(); ps = type.GetProperties(); foreach (PropertyInfo i in ps) { obj = i.GetValue(payment, null); name = i.Name; if (obj != null) { if (string.IsNullOrWhiteSpace(obj.ToString().Trim())) { ic.Set(name, " "); } else { ic.Set(name, obj.ToString()); } } else { ic.Set(name, " "); } } //是否加绩 if (payment.isUrgent == (int)enumYesNo.Yes) { ic.Set("isUrgent", "1"); //加急 } else { ic.Set("isUrgent", "2"); //普通 } //是否同城 if (payment.sameCity == (int)enumYesNo.Yes) { ic.Set("sameCity", "1"); //同城 } else { ic.Set("sameCity", "2"); //异地 } //是否跨行 if (payment.sameBank == (int)enumYesNo.Yes) { ic.Set("sameBank", "1"); //系统内,工行 //把跨行数据置空 ic.Set("oppoBankAcnt_city", " "); ic.Set("oppoBankAcnt_bankInfo_bankCode", " "); ic.Set("oppoBankAcnt_bankInfo_bankName", " "); } else { ic.Set("sameBank", "2"); //跨行 //跨行数据 ic.Set("oppoBankAcnt_city", payment.oppoBankAcnt.city); ic.Set("oppoBankAcnt_bankInfo_bankCode", payment.oppoBankAcnt.bankInfo.bankCode); ic.Set("oppoBankAcnt_bankInfo_bankName", payment.oppoBankAcnt.bankInfo.bankName); } //如果不写币种,则默认人民币 string currency = payment.currency; if (string.IsNullOrEmpty(currency)) { currency = "001"; //默认人名币 } payment.amount = payment.amount * 100; //工行按分来计算,元转分要乘以100 ic.Set("currency", currency); ic.Set("bankCode", payment.bankAcnt.swiftCode); //工行为 "102" ic.Set("cis", ConfigurationManager.AppSettings["cis"]); ic.Set("id", ConfigurationManager.AppSettings["id"]); ic.Set("iSeqno", seq.ToString()); //支付顺序号 //替换模板中的键为对应的值 var newXmlStr = ReplaceHelper.ReplaceStringVar(xmlRd, ic); _xmlTool.SetXML(newXmlStr); _xmlTool.SetXMLNode("PayAmt", payment.amount.ToString("f0")); //必须是整数 newXmlStr = _xmlTool.GetXML(); return(newXmlStr); }
public void Run(string xmlString, out string seqNo, out string result) { outputXML = (result = null); inputXML = xmlString; XML_EASY reqXML = new XML_EASY(xmlString); bool needSign = reqXML.GetXMLNode("SignTime") != null; string sysDateTime = DateTime.Now.ToString("yyyyMMddHHmmssfff"); string TransCode = reqXML.GetXMLNode("TransCode"); if (TransCode == null) { TransCode = ""; } seqNo = reqXML.GetXMLNode("fSeqno"); bool createSeq = false; if (seqNo == null || seqNo.Trim().Length <= 3) { seqNo = GetSeqno(sysDateTime + TransCode); createSeq = true; reqXML.SetXMLNode("fSeqno", seqNo); } logFN = null; if (logSwitch) { string LFN = createSeq ? seqNo : GetSeqno(sysDateTime + TransCode); //logFN = logDir + LFN.Substring(0, 6) + "-" + LFN.Substring(6, 4) + "-" + LFN.Substring(10, 4) + "@" + TransCode + ".log"; logFN = logDir + LFN + "@" + TransCode + ".log"; if (logFile != null) { logFile.Close(); } logFile = new StreamWriter(logFN, false, Encoding.GetEncoding("GBK")); //logFile.WriteLine(myInfo); logFile.WriteLine(DateTime.Now.ToString("[yyyy-MM-dd HH:mm:ss fff]")); logFile.WriteLine(); } if (GetGroupID() != null) { reqXML.SetXMLNode("CIS", GetGroupID()); } if (GetCertID() != null) { reqXML.SetXMLNode("ID", GetCertID()); } string url2; if (LastBankDate == null && needSign) { if (logFile != null) { logFile.WriteLine("本交易需签名,未获取过银行服务器时间。检测银行主机时间(Detect Time Info From Bank)。"); } url2 = "http://" + GetHttpsIP() + ":" + GetHttpsPort().ToString() + "/servlet/ICBCCMPAPIReqServlet?userID=" + GetCertID() + "&PackageID=" + sysDateTime + "&SendTime=" + sysDateTime; ncPost(url2, sysDateTime, GetHttpsTimeOut(), sign: false); if (logFile != null) { logFile.WriteLine(); } } string usingDateTime; if (YMDTime.ToLower() == "yyyymmdd") { if (Local_Bank.TotalMinutes >= 3.0 || Local_Bank.TotalMinutes <= -3.0) { usingDateTime = (DateTime.Now - Local_Bank).ToString("yyyyMMddHHmmssfff"); if (logFile != null) { logFile.WriteLine("时间误差较大,XML报文日期时间调整到(Follow Bank's DateTime):{0}", usingDateTime); logFile.WriteLine(); } } else { usingDateTime = sysDateTime; } } else { usingDateTime = YMDTime + sysDateTime.Substring(YMDTime.Length); } if (logFile != null) { logFile.WriteLine("xml原始报文信息(raw xml):"); logFile.WriteLine(xmlString); logFile.WriteLine(); logFile.WriteLine(); } reqXML.SetXMLNode("TranDate", usingDateTime.Substring(0, 8)); reqXML.SetXMLNode("TranTime", usingDateTime.Substring(8)); reqXML.SetXMLNode("SignTime", usingDateTime); if (reqXML.LocateString("%fSeqno%") > 0) { string tmpReq = reqXML.GetXML(); reqXML.SetXML(tmpReq.Replace("%fSeqno%", seqNo)); } string zipped = reqXML.GetXMLNode("zip"); bool needZip = zipped != null; if (logFile != null) { logFile.WriteLine("补充信息后的xml(decorated xml):"); logFile.WriteLine(reqXML.GetXML()); logFile.WriteLine(); logFile.WriteLine(); } if (needZip) { string afterZip = ZipBase64enc(zipped); reqXML.SetXMLNode("zip", afterZip); if (logFile != null) { logFile.WriteLine("存在需要压缩的信息(zip string)。"); logFile.WriteLine(); logFile.WriteLine("压缩后的信息(after zipped):"); logFile.WriteLine(afterZip); logFile.WriteLine(); logFile.WriteLine(); } } string reqData2 = ""; string ncReturn2 = "U"; if (needSign) { if (logFile != null) { logFile.WriteLine(DateTime.Now.ToString("[yyyy-MM-dd HH:mm:ss fff]")); logFile.WriteLine("签名-发送地址(sign server address):"); logFile.WriteLine("http://" + GetSignIP() + ":" + GetSignPort().ToString()); logFile.WriteLine(); logFile.WriteLine(); logFile.WriteLine("签名-发送内容(sign server content):"); logFile.WriteLine(reqXML.GetXML()); logFile.WriteLine(); logFile.WriteLine(); } XML_EASY signStr = new XML_EASY(ncPost("http://" + GetSignIP() + ":" + GetSignPort().ToString(), reqXML.GetXML(), GetSignTimeOut(), sign: true)); if (logFile != null) { logFile.WriteLine(); } reqData2 = signStr.GetXMLNode("sign"); if (reqData2 == null) { ncReturn2 = "error<error>银行签名交易失败!请检查银行签名服务是否正确!</error>"; if (logFile != null) { logFile.WriteLine(ncReturn2); } } else if (logFile != null) { logFile.WriteLine(DateTime.Now.ToString("[yyyy-MM-dd HH:mm:ss fff]")); logFile.WriteLine("签名-结果(sign server return):"); logFile.WriteLine(signStr.GetXML()); logFile.WriteLine(); logFile.WriteLine(); } } else { reqData2 = HttpUtility.UrlEncode(reqXML.GetXML(), Encoding.GetEncoding("GBK")); } if (reqData2 == null || reqData2.Length == 0) { outputXML = (result = ncReturn2); if (logFile != null) { logFile.Close(); logFile = null; } return; } url2 = "http://" + GetHttpsIP() + ":" + GetHttpsPort().ToString() + "/servlet/ICBCCMPAPIReqServlet?userID=" + GetCertID() + "&PackageID=" + seqNo + "&SendTime=" + usingDateTime; if (needZip) { url2 += "&zipFlag=1"; } string cont = "Version=" + GetInterfaceVersion() + "&TransCode=" + TransCode + "&BankCode=102&GroupCIS=" + GetGroupID() + "&ID=" + GetCertID() + "&PackageID=" + seqNo + "&Cert=&reqData=" + reqData2; if (logFile != null) { logFile.WriteLine(DateTime.Now.ToString("[yyyy-MM-dd HH:mm:ss fff]")); logFile.WriteLine("安全HTTP服务-发送地址(https server address):"); logFile.WriteLine(url2); logFile.WriteLine(); logFile.WriteLine(); logFile.WriteLine("安全HTTP服务-发送内容(https server content):"); logFile.WriteLine(cont); logFile.WriteLine(); logFile.WriteLine(); } ncReturn2 = ncPost(url2, cont, GetHttpsTimeOut(), sign: false); if (logFile != null) { logFile.WriteLine(); } if (ncReturn2 == null || ncReturn2.Length == 0) { outputXML = (result = "error<error>未接受到银行返回信息!https server failed!</error>"); if (logFile != null) { logFile.WriteLine(result); logFile.Close(); logFile = null; } return; } if (logFile != null) { logFile.WriteLine(DateTime.Now.ToString("[yyyy-MM-dd HH:mm:ss fff]")); logFile.WriteLine("银行返回结果(bank return mesage):"); logFile.WriteLine(ncReturn2); logFile.WriteLine(); logFile.WriteLine(); } BankReturnEncoding = "GBK"; string headInfo = HttpHeadString.ToUpper(); int cs = headInfo.IndexOf("CHARSET"); if (cs > 0) { int p3 = headInfo.IndexOf('=', cs); char[] endCharSet = new char[2] { ';', '<' }; int p2 = headInfo.IndexOfAny(endCharSet, p3); BankReturnEncoding = headInfo.Substring(p3 + 1, p2 - p3 - 1).Trim(); } byte[] bytes = Convert.FromBase64String(ncReturn2.Substring(ncReturn2.IndexOf('=') + 1)); if (ncReturn2.IndexOf("errorCode") >= 0) { result = "<error>errorCode=" + Encoding.GetEncoding(BankReturnEncoding).GetString(bytes) + "</error>"; } else { result = Encoding.GetEncoding(BankReturnEncoding).GetString(bytes); } if (logFile != null) { logFile.WriteLine("BASE64解码(base64dec){0}:", BankReturnEncoding); logFile.WriteLine(result); logFile.WriteLine(); logFile.WriteLine(); } XML_EASY resultXML = new XML_EASY(result); string resultZip = resultXML.GetXMLNode("zip"); if (resultZip != null) { resultXML.SetXMLNode("zip", Base64decUnzip(resultZip)); result = resultXML.GetXML(); if (logFile != null) { logFile.WriteLine("解压缩(after zipped):"); logFile.WriteLine(result); logFile.WriteLine(); logFile.WriteLine(); } } if (logFile != null) { logFile.Close(); logFile = null; } outputXML = result; }
/// <summary> /// 提交支付指令 /// </summary> /// <param name="caller">调用者</param> /// <param name="payments">支付单据数组</param> /// <returns></returns> public BankReturnModel <PaymentInfo[]> submitPayment(CallerInfo caller, PaymentInfo[] payments) { if (payments.Length < 1) { throw new Exception("没有支付信息!"); } string xmlString = ICBCNCHelper.GetXmlString("PAYENT"); XML_EASY xmlPay = new XML_EASY(xmlString); string xmlRd = xmlPay.GetXMLNode("rd"); var newXmlStr = string.Empty; decimal amount = 0; int num = 0; //支付笔数或序号 StringBuilder sb = new StringBuilder(); XML_EASY xmlTmp = new XML_EASY(); string s = string.Empty; int iseq = 0; payments = payments.OrderBy(t => t.iSeqno).ToArray(); //iSeqno 在银行端支付时按rd的顺序,不按iSeqno来,需要先按iSeqno排序后,在生成rd foreach (PaymentInfo pay in payments) { num++; iseq = string.IsNullOrEmpty(pay.iSeqno)? num : int.Parse(pay.iSeqno); sb.Append("<rd>"); sb.Append(this.dealwithPaymentRd(xmlRd, pay, iseq)); sb.Append("</rd>"); if (pay.amount != 0) { amount += pay.amount; } } xmlPay.RepXMLNode("rd", sb.ToString()); //设置头部信息 xmlPay.SetXMLNode("BankCode", string.IsNullOrEmpty(payments[0].bankAcnt.swiftCode)?"102": payments[0].bankAcnt.swiftCode); //工行为 "102" xmlPay.SetXMLNode("CIS", ConfigurationManager.AppSettings["cis"]); xmlPay.SetXMLNode("ID", ConfigurationManager.AppSettings["id"]); //设置支付信息 xmlPay.SetXMLNode("TotalNum", num.ToString("f0")); xmlPay.SetXMLNode("TotalAmt", amount.ToString("f0")); newXmlStr = xmlPay.GetXML(); string result = this.ICBC_YQHL(newXmlStr); xmlPay.SetXML(result); if (xmlPay.LocateString("<error>") >= 0) { result = xmlPay.GetXMLNode("error"); throw new Exception(result); } if (!string.IsNullOrEmpty(result)) { XML_EASY xml_easy1 = new XML_EASY(result); BankReturnModel <PaymentInfo[]> retMo = new BankReturnModel <PaymentInfo[]>(); retMo.bankCode = xml_easy1.GetXMLNode("BankCode"); retMo.transCode = xml_easy1.GetXMLNode("TransCode"); retMo.tranDate = xml_easy1.GetXMLNode("TranDate"); retMo.tranTime = xml_easy1.GetXMLNode("TranTime"); retMo.fSeqno = xml_easy1.GetXMLNode("fSeqno"); retMo.retCode = xml_easy1.GetXMLNode("RetCode"); retMo.retMsg = xml_easy1.GetXMLNode("RetMsg"); retMo.bankSerialNo = xml_easy1.GetXMLNode("SerialNo"); string resultCode = xml_easy1.GetXMLNode("Result"); if (string.IsNullOrEmpty(resultCode)) { //文件级返回 ////再次发送指令查询状态 //if (retMo.retCode == "0") //{ // Thread.Sleep(20 * 1000); //延时后再查询 // return this.getPaymentState(caller, payments[0].bankAcnt.bankVersionInfo, retMo.fSeqno); //} //直接返回结果 retMo.detailData = new BankReturnDetailModel <PaymentInfo[]>(); retMo.detailData.resultCode = resultCode; retMo.detailData.iRetCode = xml_easy1.GetXMLNode("iRetCode"); retMo.detailData.iRetMsg = xml_easy1.GetXMLNode("iRetMsg"); retMo.detailData.businessRefNo = xml_easy1.GetXMLNode("Ref"); retMo.detailData.infoData = null; //payment; return(retMo); } else { //单笔明细支付,指令级返回 //retMo.detailData = new BankReturnDetailModel<PaymentInfo[]>(); //retMo.detailData.resultCode = resultCode; //retMo.detailData.iRetCode = xml_easy1.GetXMLNode("iRetCode"); //retMo.detailData.iRetMsg = xml_easy1.GetXMLNode("iRetMsg"); //retMo.detailData.businessRefNo = xml_easy1.GetXMLNode("Ref"); //retMo.detailData.infoData = null; //payment; string rdString = xml_easy1.GetXMLNode("rd"); int rdIndex = xml_easy1.Index(); //string result = xmlPayState.GetXMLNode("Result", rdIndex); if (!string.IsNullOrEmpty(rdString)) { var states = new List <PaymentInfo>(); PaymentInfo pInfo = null; //循环获取明细 do { pInfo = getPaymentInfofromRd(payments[0].bankAcnt.bankVersionInfo, rdString); pInfo.paymentSeqNo = xml_easy1.GetXMLNode("fSeqno"); if (pInfo.submitDate == DateTime.MinValue) { pInfo.submitDate = this.convertToDateTime(xml_easy1.GetXMLNode("TranDate") + xml_easy1.GetXMLNode("TranTime")); } states.Add(pInfo); rdString = xml_easy1.GetXMLNode("rd", rdIndex); rdIndex = xml_easy1.Index(); }while (!string.IsNullOrEmpty(rdString)); retMo.detailData = new BankReturnDetailModel <PaymentInfo[]>(); retMo.detailData.infoData = states.ToArray(); return(retMo); } } return(retMo); } return(null); }
/// <summary> /// 获得对应银行账号的当前余额 /// </summary> /// <param name="caller">调用者</param> /// <param name="bankCnt">银行账户信息</param> /// <param name="currency">币种</param> /// <returns></returns> public BalanceInfo getBalance(CallerInfo caller, BankAcnt bankCnt, string currency) { string error = string.Empty; var acct = bankCnt.acntNo.Trim(); if (acct.Length < 19) { error = "账号长度错误!"; throw new Exception(error); } //ICBCNCHelper ncHelper = ICBCNCHelper.GetInstance(); string xmlString = ICBCNCHelper.GetXmlString("QACCBAL"); InstallContext ic = new InstallContext(); //初始化数据 Type type = bankCnt.GetType(); PropertyInfo[] ps = type.GetProperties(); foreach (PropertyInfo i in ps) { object obj = i.GetValue(bankCnt, null); string name = i.Name; if (obj != null) { ic.Set(i.Name, obj.ToString()); } else { ic.Set(name, " "); } } //如果不写币种,会使用账户的币种 /* * if (string.IsNullOrEmpty(currency)) { * currency = "001"; //默认人名币 * } */ ic.Set("currency", currency); ic.Set("bankCode", bankCnt.swiftCode); ic.Set("cis", ConfigurationManager.AppSettings["cis"]); ic.Set("id", ConfigurationManager.AppSettings["id"]); //替换模板中的键为对应的值 var newXmlStr = ReplaceHelper.ReplaceStringVar(xmlString, ic); ICBC_NetSafeClient iCBC_NetSafeClient = CreateOneNC(); XML_EASY balString = new XML_EASY(newXmlStr);//new XML_EASY(ResourceSet.TransCode_QACCBAL_0010); if (acct.Length == 19) { balString.SetXMLNode("AccNo", acct); } //else if (acct.Length == 29 && acct[19] == '-') //{ // balString.SetXMLNode("AccNo", acct.Substring(0, 19)); // balString.SetXMLNode("AcctSeq", acct.Substring(20, 9)); //} string seqNo, seqResult; iCBC_NetSafeClient.Run(balString.GetXML(), out seqNo, out seqResult); iCBC_NetSafeClient = null; balString.SetXML(seqResult); if (balString.LocateString("<error>") >= 0) { error = balString.GetXMLNode("error"); throw new Exception(error); } string balMoney = balString.GetXMLNode("Balance"); if (balMoney != null && balMoney.Length > 0) { BalanceInfo balInfo = new BalanceInfo(); //取余额 decimal balance = Convert.ToDecimal(balMoney) / 100.0m; //以币种的最小单位为单位,人民币的单位为分,转换为元要除以100 //昨日余额 decimal accBalance = this.getYuanMoney(balString.GetXMLNode("AccBalance")); //可用余额 decimal usableBalance = this.getYuanMoney(balString.GetXMLNode("UsableBalance")); balInfo.bankAcnt = bankCnt; //账户信息 balInfo.balance = balance; balInfo.hisBalance = accBalance; balInfo.availBalance = usableBalance; balInfo.acntType = balString.GetXMLNode("AcctProperty"); //账户属性 balInfo.currency = balString.GetXMLNode("CurrType"); //币种 string retTime = balString.GetXMLNode("QueryTime"); if (!string.IsNullOrEmpty(retTime)) { balInfo.balanceDate = this.convertToDateTime(retTime); } balInfo.fSeqno = seqNo; //balString.GetXMLNode("fSeqno"); //指令包序列号 //error = "Name=" + balString.GetXMLNode("AccName") + "|Balance=" + accBalance.ToString() + "|银行应答时间=" + balString.GetXMLNode("QueryTime"); return(balInfo); } error = "银行RetMsg:" + balString.GetXMLNode("RetMsg"); throw new Exception(error); }
/// <summary> /// 获得支付指令序列号对应的支付状态信息 /// </summary> /// <param name="caller">调用者</param> /// <param name="bankVerInfo">银行版本</param> /// <param name="paymentSeqNo">支付指令序列号(在调用支付指令后系统返回的序列号(fSeqNo))</param> /// <returns></returns> public BankReturnModel <PaymentInfo[]> getPaymentState(CallerInfo caller, BankVersionInfo bankVerInfo, String paymentSeqNo) { string error = string.Empty; string xmlString = ICBCNCHelper.GetXmlString("QPAYENT"); XML_EASY xmlPayState = new XML_EASY(xmlString); //设置头部信息 xmlPayState.SetXMLNode("BankCode", "102"); //工行为 "102" xmlPayState.SetXMLNode("CIS", ConfigurationManager.AppSettings["cis"]); xmlPayState.SetXMLNode("ID", ConfigurationManager.AppSettings["id"]); xmlPayState.SetXMLNode("QryfSeqno", paymentSeqNo); //使用fSeqno来查询 xmlPayState.SetXMLNode("QrySerialNo", ""); //值为空,则使用fSeqno来查询 ICBC_NetSafeClient iCBC_NetSafeClient = CreateOneNC(); string seqNo, seqResult; iCBC_NetSafeClient.Run(xmlPayState.GetXML(), out seqNo, out seqResult); iCBC_NetSafeClient = null; xmlPayState.SetXML(seqResult); if (xmlPayState.LocateString("<error>") >= 0) { error = xmlPayState.GetXMLNode("error"); throw new Exception(error); } string retCode = xmlPayState.GetXMLNode("RetCode"); if (retCode != "0") { //error = "error=" + xmlPayState.GetXMLNode("RetMsg"); //throw new Exception(error); BankReturnModel <PaymentInfo[]> retMo = new BankReturnModel <PaymentInfo[]>(); retMo.retCode = retCode; retMo.retMsg = xmlPayState.GetXMLNode("RetMsg"); retMo.bankCode = "102"; retMo.fSeqno = seqNo; retMo.transCode = "QPAYENT"; retMo.tranDate = xmlPayState.GetXMLNode("TranDate"); retMo.tranTime = xmlPayState.GetXMLNode("TranTime"); return(retMo); } //取支付明细信息 List <PaymentInfo> states = null; PaymentInfo pInfo = null; string rdString = xmlPayState.GetXMLNode("rd"); int rdIndex = xmlPayState.Index(); //string result = xmlPayState.GetXMLNode("Result", rdIndex); if (!string.IsNullOrEmpty(rdString)) { states = new List <PaymentInfo>(); //循环获取明细 do { pInfo = getPaymentInfofromRd(bankVerInfo, rdString); if (pInfo.submitDate == DateTime.MinValue) { pInfo.submitDate = this.convertToDateTime(xmlPayState.GetXMLNode("TranDate") + xmlPayState.GetXMLNode("TranTime")); } pInfo.paymentSeqNo = paymentSeqNo; states.Add(pInfo); rdString = xmlPayState.GetXMLNode("rd", rdIndex); rdIndex = xmlPayState.Index(); }while (!string.IsNullOrEmpty(rdString)); BankReturnModel <PaymentInfo[]> retMo = new BankReturnModel <PaymentInfo[]>(); retMo.retCode = retCode; retMo.retMsg = xmlPayState.GetXMLNode("RetMsg"); retMo.bankCode = "102"; retMo.fSeqno = seqNo; retMo.transCode = "QPAYENT"; retMo.tranDate = xmlPayState.GetXMLNode("TranDate"); retMo.tranTime = xmlPayState.GetXMLNode("TranTime"); retMo.detailData = new BankReturnDetailModel <PaymentInfo[]>(); retMo.detailData.infoData = states.ToArray(); return(retMo); } return(null); }
public BankReturnModel <DetailInfo[]> getHistoryDetails(CallerInfo caller, BankAcnt bankAcnt, DateTime beginTime, DateTime endTime, decimal minAmt, decimal maxAmt, string nextTag, string currency) { string error = string.Empty; string xmlString = ICBCNCHelper.GetXmlString("QHISD"); XML_EASY xmlQPD = new XML_EASY(xmlString); //设置头部信息 xmlQPD.SetXMLNode("BankCode", "102"); //工行为 "102" xmlQPD.SetXMLNode("CIS", ConfigurationManager.AppSettings["cis"]); xmlQPD.SetXMLNode("ID", ConfigurationManager.AppSettings["id"]); xmlQPD.SetXMLNode("AccNo", bankAcnt.acntNo); //银行账号 xmlQPD.SetXMLNode("MinAmt", (minAmt * 100).ToString()); //发生额下限,人民币分为单位,把元转换为分 xmlQPD.SetXMLNode("MaxAmt", (maxAmt * 100).ToString()); //发生额上限,人民币分为单位,把元转换为分 xmlQPD.SetXMLNode("NextTag", string.IsNullOrEmpty(nextTag) ? "" : nextTag); //下页标志 xmlQPD.SetXMLNode("BeginDate", beginTime.ToString("yyyyMMdd")); xmlQPD.SetXMLNode("EndDate", endTime.ToString("yyyyMMdd")); ICBC_NetSafeClient iCBC_NetSafeClient = CreateOneNC(); string seqNo, seqResult; iCBC_NetSafeClient.Run(xmlQPD.GetXML(), out seqNo, out seqResult); iCBC_NetSafeClient = null; xmlQPD.SetXML(seqResult); if (xmlQPD.LocateString("<error>") >= 0) { error = xmlQPD.GetXMLNode("error"); throw new Exception(error); } string retCode = xmlQPD.GetXMLNode("RetCode"); if (retCode != "0") { //error = "error=" + xmlQPD.GetXMLNode("RetMsg"); //throw new Exception(error); BankReturnModel <DetailInfo[]> retMo = new BankReturnModel <DetailInfo[]>(); retMo.retCode = retCode; retMo.retMsg = xmlQPD.GetXMLNode("RetMsg"); retMo.bankCode = "102"; retMo.fSeqno = seqNo; retMo.transCode = "QHISD"; retMo.tranDate = xmlQPD.GetXMLNode("TranDate"); retMo.tranTime = xmlQPD.GetXMLNode("TranTime"); return(retMo); } //取交易明细信息 List <DetailInfo> states = null; DetailInfo pInfo = null; string rdString = xmlQPD.GetXMLNode("rd"); int rdIndex = xmlQPD.Index(); if (!string.IsNullOrEmpty(rdString)) { states = new List <DetailInfo>(); //循环获取交易明细 do { pInfo = getDetailInfofromRd(bankAcnt, rdString); states.Add(pInfo); rdString = xmlQPD.GetXMLNode("rd", rdIndex); rdIndex = xmlQPD.Index(); }while (!string.IsNullOrEmpty(rdString)); BankReturnModel <DetailInfo[]> retMo = new BankReturnModel <DetailInfo[]>(); retMo.retCode = retCode; retMo.retMsg = xmlQPD.GetXMLNode("RetMsg"); retMo.bankCode = "102"; retMo.fSeqno = seqNo; retMo.transCode = "QPAYENT"; retMo.tranDate = xmlQPD.GetXMLNode("TranDate"); retMo.tranTime = xmlQPD.GetXMLNode("TranTime"); retMo.nextTag = xmlQPD.GetXMLNode("NextTag"); //下页标志 retMo.detailData = new BankReturnDetailModel <DetailInfo[]>(); retMo.detailData.infoData = states.ToArray(); return(retMo); } return(null); }
/// <summary> /// 检查前置机https服务以及签名服务状态 /// </summary> /// <param name="httpsState"></param> /// <param name="signState"></param> /// <returns></returns> public string CheckNetSafeClient(out bool httpsState, out bool signState) { httpsState = false; signState = false; string msg = string.Empty; #region 检查https服务 string error = string.Empty; BankAcnt bankCnt = new BankAcnt { acntNo = "1202022719927388888", acntName = "菌邢票董租氮蒸幻憨野该痼赴挥傻" }; var acct = bankCnt.acntNo.Trim(); if (acct.Length < 19) { error = "账号长度错误!"; throw new Exception(error); } string xmlString = ICBCNCHelper.GetXmlString("QACCBAL"); InstallContext ic = new InstallContext(); //初始化数据 Type type = bankCnt.GetType(); PropertyInfo[] ps = type.GetProperties(); foreach (PropertyInfo i in ps) { object obj = i.GetValue(bankCnt, null); string name = i.Name; if (obj != null) { ic.Set(i.Name, obj.ToString()); } else { ic.Set(name, " "); } } ic.Set("currency", "001"); ic.Set("bankCode", "102"); ic.Set("cis", ConfigurationManager.AppSettings["cis"]); ic.Set("id", ConfigurationManager.AppSettings["id"]); //替换模板中的键为对应的值 var newXmlStr = ReplaceHelper.ReplaceStringVar(xmlString, ic); ICBC_NetSafeClient iCBC_NetSafeClient = CreateOneNC(); XML_EASY balString = new XML_EASY(newXmlStr); if (acct.Length == 19) { balString.SetXMLNode("AccNo", acct); } string seqNo, seqResult; iCBC_NetSafeClient.Run(balString.GetXML(), out seqNo, out seqResult); balString.SetXML(seqResult); if (balString.LocateString("<error>") >= 0) { error = balString.GetXMLNode("error"); httpsState = false; msg = "前置机Https服务有问题:" + error; } else { httpsState = true; msg = "前置机Https服务OK"; } #endregion #region 检查签名服务 string signstr = iCBC_NetSafeClient.GetSignStr("www.gtdata.com"); if (!string.IsNullOrEmpty(signstr) && signstr.IndexOf("<sign>") > 0) { signState = true; msg += " 前置机签名服务OK."; } else { signState = false; msg += " 前置机签名服务有问题."; } #endregion iCBC_NetSafeClient = null; return(msg); }