Example #1
0
        /// <summary>
        /// 从rd节点获取支付信息
        /// </summary>
        /// <param name="bankVerInfo"></param>
        /// <param name="rdString"></param>
        /// <returns></returns>
        private PaymentInfo getPaymentInfofromRd(BankVersionInfo bankVerInfo, string rdString)
        {
            //获得支付信息
            PaymentInfo pInfo  = new PaymentInfo();
            XML_EASY    xmlPay = new XML_EASY(rdString);

            pInfo.response = rdString;

            pInfo.iSeqno    = xmlPay.GetXMLNode("iSeqno"); //支付序号
            pInfo.result    = xmlPay.GetXMLNode("Result");
            pInfo.payState  = (int)getPaymentStateByResultCode(pInfo.result);
            pInfo.resultMsg = getMsgByResultCode(pInfo.result);

            if (pInfo.result != "7")
            {
                string iRetCode = xmlPay.GetXMLNode("iRetCode");
                string iRetMsg  = xmlPay.GetXMLNode("iRetMsg");
                if (!string.IsNullOrEmpty(iRetCode) || !string.IsNullOrEmpty(iRetMsg))
                {
                    if (iRetCode != "0")
                    {
                        pInfo.resultMsg += ":" + iRetCode + " " + iRetMsg;
                    }
                    else
                    {
                        pInfo.resultMsg += ":" + xmlPay.GetXMLNode("instrRetCode") + " " + xmlPay.GetXMLNode("instrRetMsg");
                    }
                }
            }

            pInfo.amount     = this.getYuanMoney(xmlPay.GetXMLNode("PayAmt"));
            pInfo.postScript = xmlPay.GetXMLNode("PostScript");

            pInfo.currency   = xmlPay.GetXMLNode("CurrType");
            pInfo.explantion = xmlPay.GetXMLNode("Summary");
            pInfo.usage      = xmlPay.GetXMLNode("UseCN");
            pInfo.sameCity   = (int)(xmlPay.GetXMLNode("IsSameCity") == "1" ? enumYesNo.Yes : enumYesNo.No);
            pInfo.sameBank   = (int)(xmlPay.GetXMLNode("SysIOFlg") == "1" ? enumYesNo.Yes : enumYesNo.No);
            pInfo.isUrgent   = (int)(xmlPay.GetXMLNode("PayType") == "1" ? enumYesNo.Yes : enumYesNo.No);
            string retTime = xmlPay.GetXMLNode("BankRetTime");

            if (!string.IsNullOrEmpty(retTime))
            {
                pInfo.submitDate = this.convertToDateTime(retTime);
            }

            pInfo.bankAcnt                 = new BankAcnt();
            pInfo.bankAcnt.acntName        = xmlPay.GetXMLNode("PayAccNameCN");
            pInfo.bankAcnt.acntName        = xmlPay.GetXMLNode("PayAccNo");
            pInfo.bankAcnt.bankVersionInfo = bankVerInfo;

            pInfo.oppoBankAcnt          = new BankAcnt();
            pInfo.oppoBankAcnt.acntName = xmlPay.GetXMLNode("RecAccNameCN");
            pInfo.oppoBankAcnt.acntNo   = xmlPay.GetXMLNode("RecAccNo");

            return(pInfo);
        }
Example #2
0
        public bool TryNextTag(out string reqID, out string result)
        {
            reqID  = null;
            result = null;
            XML_EASY xML_EASY    = new XML_EASY(outputXML);
            string   lastNextTag = xML_EASY.GetXMLNode("NextTag");

            if (xML_EASY.GetXMLNode("RetCode") != "0" || lastNextTag == null || lastNextTag.Trim().Length == 0)
            {
                return(false);
            }
            XML_EASY readLastInput = new XML_EASY(inputXML);

            readLastInput.SetXMLNode("NextTag", lastNextTag);
            Run(readLastInput.GetXML(), out reqID, out result);
            return(true);
        }
Example #3
0
        /// <summary>
        /// 从rd节点获取交易明细信息
        /// </summary>
        /// <param name="bankVerInfo"></param>
        /// <param name="rdString"></param>
        /// <returns></returns>
        private DetailInfo getDetailInfofromRd(BankAcnt bankAcnt, string rdString)
        {
            //获得交易明细信息
            DetailInfo DInfo = new DetailInfo();
            XML_EASY   xml   = new XML_EASY(rdString);

            DInfo.bankAcnt = bankAcnt; //本方账号
            //DInfo.bussinessName =

            decimal amount = this.getYuanMoney(xml.GetXMLNode("Amount"));

            DInfo.bussinessRefNo = xml.GetXMLNode("Ref");
            if (xml.GetXMLNode("Drcrf") == "1")
            {
                //借方
                DInfo.crebitAmount = amount;
            }
            else
            {
                //贷方
                DInfo.debitAmount = amount;
            }

            DInfo.currency     = xml.GetXMLNode("CurrType");   //币种
            DInfo.explantion   = xml.GetXMLNode("Summary");    //摘要
            DInfo.rawTransTime = xml.GetXMLNode("TimeStamp");  //时间戳
            DInfo.usage        = xml.GetXMLNode("UseCN");      //用途
            DInfo.vouhNo       = xml.GetXMLNode("VouhNo");     //凭证号
            DInfo.cVouhType    = xml.GetXMLNode("CvouhType");  //凭证种类
            DInfo.postScript   = xml.GetXMLNode("PostScript"); //附言
            DInfo.addInfo      = xml.GetXMLNode("AddInfo");    //附件信息

            //对方账号
            DInfo.oppoBankAcnt                   = new BankAcnt();
            DInfo.oppoBankAcnt.acntName          = xml.GetXMLNode("RecipName");  //对方户明
            DInfo.oppoBankAcnt.acntNo            = xml.GetXMLNode("RecipAccNo"); //对方账号
            DInfo.oppoBankAcnt.bankInfo          = new BankInfo();
            DInfo.oppoBankAcnt.bankInfo.bankCode = xml.GetXMLNode("RecipBkNo");  //对方行号

            return(DInfo);
        }
Example #4
0
        /// <summary>
        /// 封装发送xml请求方法
        /// </summary>
        /// <param name="xml_str"></param>
        /// <param name="ver"></param>
        /// <returns></returns>
        private string ICBC_YQHL(string xml_str, string ver = "0.0.0.1")
        {
            XML_EASY xml_easy1 = new XML_EASY(xml_str);
            string   xMLNode   = xml_easy1.GetXMLNode("CIS", 0);
            string   str3      = xml_easy1.GetXMLNode("ID", 0);

            if (((xMLNode != ConfigurationManager.AppSettings["cis"]) || (str3 != ConfigurationManager.AppSettings["id"])) || (ver.Length == 0))
            {
                return("ReqID=|ReqResult=XML中CIS、ID与设定不符,或版本号信息有误!");
            }
            ICBC_NetSafeClient client = this.CreateOneNC();

            if (string.IsNullOrWhiteSpace(ver))
            {
                ver = "0.0.0.1";
            }
            client.SetInterfaceVersion(ver);

            //string path = Path.Combine(HttpRuntime.AppDomainAppPath, @"ICBC_Log\" + DateTime.Now.ToString("yyyyMMdd"));
            //bool flag1 = ConfigurationManager.AppSettings["log"].Trim().ToLower() == "on";
            //if (flag1 && !Directory.Exists(path))
            //{
            //    Directory.CreateDirectory(path);
            //}
            //if (flag1 && Directory.Exists(path))
            //{
            //    client.SetLogFilePath(path);
            //    client.SetLogSwitch(true);
            //}

            string seqNo, result;

            client.Run(xml_str, out seqNo, out result);
            client = null;

            //return ("ReqID=" + seqNo + "|ReqResult=" + Convert.ToBase64String(Encoding.GetEncoding("GBK").GetBytes(result)));
            return(result);
        }
Example #5
0
        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;
        }
Example #6
0
        /// <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);
        }
Example #7
0
        /// <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);
        }
Example #8
0
        /// <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);
        }
Example #9
0
        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);
        }
Example #10
0
        /// <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);
        }