Beispiel #1
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);
        }
Beispiel #2
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);
        }
Beispiel #3
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);
        }