示例#1
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);
        }
示例#2
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);
        }