Example #1
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 #2
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 #3
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 #4
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 #5
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);
        }