Beispiel #1
0
        protected PayResponseModel Send(byte[] preMsg, string mac, out Iso8583 Res_iso8583)
        {
            Bitmap map = new Bitmap();

            map[64] = true;
            Iso8583 iso8583 = new Iso8583(map);

            iso8583[64].Content = mac;
            iso8583[64].Pack().CopyTo(preMsg, preMsg.Length - 8);
            Res_iso8583 = new Iso8583();
            Message Res_Msg = new Message(Res_iso8583);

            Res_Msg.Unpack(Utilities.Send(Settings.BankIp, Convert.ToInt32(Settings.BankPort), preMsg));
            Settings.SysTraceNum = (Convert.ToInt32(Settings.SysTraceNum) >= 999999 ? 1 : Convert.ToInt32(Settings.SysTraceNum) + 1).ToString();
            #region 组织返回数据
            PayResponseModel resultModel = new PayResponseModel();
            resultModel.ResponseCode         = Res_iso8583[39].Content;
            resultModel.Pan                  = Res_iso8583[2].Content;
            resultModel.Money                = Res_iso8583[4].Content;
            resultModel.TransactionSerialNum = Res_iso8583[11].Content;
            resultModel.TransactionTime      = Res_iso8583[12].Content + Res_iso8583[13].Content;
            resultModel.ExtendInfo           = Res_iso8583[54].Content;
            #endregion
            return(resultModel);
        }
Beispiel #2
0
        /// <summary>
        /// 撤销
        /// </summary>
        /// <returns></returns>
        public PayResponseModel Cancel()
        {
            try
            {
                if (this.LatestPreMsg == null)
                {
                    throw new ApplicationException("无撤销可用数据!");
                }
                if (M100.CardContainer.Count < 1)
                {
                    throw new ApplicationException("撤销失败,卡机内无卡!");
                }
                //预处理
                ServiceUtil.PayPreTreatmentClient.Open();
                var tempPreMsg = ServiceUtil.PayPreTreatmentClient.CancelPay(M100.CardContainer[0], LatestPreMsg, this.LatestExtendData);
                ServiceUtil.PayPreTreatmentClient.Close();//及时关闭信道

                ServiceUtil.PayClient.Open();
                PayResponseModel result = ServiceUtil.PayClient.CancelPay(tempPreMsg, CalculateMac(tempPreMsg));
                ServiceUtil.PayClient.Close();//及时关闭信道

                return(ReBuildResultModel(result));
            }
            catch (FaultException faultEx)
            {//WCF异常
                //释放信道
                ServiceUtil.PayPreTreatmentClient.Abort();
                ServiceUtil.PayClient.Abort();
                throw new ApplicationException(string.Format("WCF服务调用出错:{0}", faultEx.Message));
            }
        }
Beispiel #3
0
 /// <summary>
 /// 重构返回的对象
 /// </summary>
 private PayResponseModel ReBuildResultModel(PayResponseModel result)
 {
     if (_creditCardPayType == CreditCardPayType.AllInPay)
     {
         result.Pan = this.M100.CacheCard.CardNo;//通联支付返回正常卡号非加密卡号
     }
     if (result.ResponseCode == "00")
     {
         string[] extendData = result.ExtendInfo.Split(',');
         this.LatestExtendData = extendData.Length > 1 ? string.Format("{0},{1}", extendData[0], extendData[1]) : extendData[0];//交易流水号
         result.ExtendInfo     = extendData[0];
     }
     return(result);
 }
Beispiel #4
0
        protected PayResponseModel Send(byte[] preMsg, string mac)
        {
            Bitmap map = new Bitmap();

            map[64] = true;
            Iso8583 iso8583 = new Iso8583(map);

            iso8583[64].Content = mac;
            iso8583[64].Pack().CopyTo(preMsg, preMsg.Length - 8);
            Iso8583 Res_iso8583 = new Iso8583();
            Message Res_Msg     = new Message(Res_iso8583);

            Res_Msg.Unpack(Utilities.Send(Settings.BankIp, Convert.ToInt32(Settings.BankPort), preMsg));
            Settings.SysTraceNum = (Convert.ToInt32(Settings.SysTraceNum) >= 999999 ? 1 : Convert.ToInt32(Settings.SysTraceNum) + 1).ToString();
            #region 组织返回数据
            PayResponseModel resultModel = new PayResponseModel();
            resultModel.ResponseCode         = Res_iso8583[39].Content;
            resultModel.Pan                  = Res_iso8583[2].Content;
            resultModel.Money                = Res_iso8583[4].Content;
            resultModel.TransactionSerialNum = Res_iso8583[11].Content;
            string transactionTimeStr = Res_iso8583[13].Content + Res_iso8583[12].Content;
            resultModel.TransactionTime = string.Format("{0}-{1}-{2} {3}:{4}:{5}",
                                                        DateTime.Now.Date.Year.ToString(),
                                                        transactionTimeStr.Substring(0, 2),
                                                        transactionTimeStr.Substring(2, 2),
                                                        transactionTimeStr.Substring(4, 2),
                                                        transactionTimeStr.Substring(6, 2),
                                                        transactionTimeStr.Substring(8, 2));
            if (Res_iso8583.Keys.Contains(38))
            {
                //附加数据
                //假如38域授权码存在时返回
                resultModel.ExtendInfo = string.Format("{0},{1}", Res_iso8583[37].Content, Res_iso8583[38].Content);
            }
            else
            {
                //假如38域不存在则只返回37域交易参考号用于撤销交易
                resultModel.ExtendInfo = string.Format("{0}", Res_iso8583[37].Content);
            }
            #endregion
            return(resultModel);
        }
Beispiel #5
0
 /// <summary>
 /// 查询
 /// </summary>
 /// <returns></returns>
 public PayResponseModel Query(string pin)
 {
     try
     {
         if (M100.CardContainer.Count < 1)
         {
             throw new ApplicationException("查询失败,卡机内无卡!");
         }
         string pinBlock = "";
         if (string.IsNullOrEmpty(pin))
         {
             pinBlock = this.IEncry.GetPinBlock();
         }
         else
         {
             pinBlock = CalculatePinBlock(M100.CacheCard.CardNo, pin);
         }
         //2磁道数据加密
         M100.CardContainer[0].Msg2 = CalculateTrackBlock(M100.CacheCard.Msg2);
         //主账号数据加密
         M100.CardContainer[0].CardNo = CalculateTrackBlock(M100.CacheCard.CardNo);
         //虚拟设备对象
         VisualSelfServiceEquipment equipment = new VisualSelfServiceEquipment()
         {
             creditCard = M100.CardContainer[0],
             TerminalNo = Settings.TerminalNo,
             PinBlock   = pinBlock,
             PayMoney   = "000000000000"
         };
         //针对查询交易存储临时交易预处理信息,无需冲正
         var tempPreMsg          = ServiceUtil.PayPreTreatmentClient.Query(equipment);
         PayResponseModel result = ServiceUtil.PayClient.Query(tempPreMsg, CalculateMac(tempPreMsg));
         return(ReBuildResultModel(result));
     }
     catch (FaultException faultEx)
     {//WCF异常
         //释放信道
         ServiceUtil.PayPreTreatmentClient.Abort();
         ServiceUtil.PayClient.Abort();
         throw new ApplicationException(string.Format("WCF服务调用出错:{0}", faultEx.Message));
     }
 }
Beispiel #6
0
        /// <summary>
        /// 支付
        /// </summary>
        /// <returns></returns>
        public PayResponseModel Pay(string pin = "")
        {
            try
            {
                if (M100.CardContainer.Count < 1)
                {
                    throw new ApplicationException("支付失败,卡机内无卡!");
                }
                string pinBlock = "";
                if (string.IsNullOrEmpty(pin))
                {
                    pinBlock = this.IEncry.GetPinBlock();
                }
                else
                {
                    pinBlock = CalculatePinBlock(M100.CacheCard.CardNo, pin);
                }
                //string paymoney = (money * 100).ToString("f0").PadLeft(12, '0');
                switch (_creditCardPayType)
                {
                case CreditCardPayType.AllInPay:
                    //2磁道数据加密
                    M100.CardContainer[0].Msg2 = CalculateTrackBlock(M100.CacheCard.Msg2);
                    //主账号数据加密
                    M100.CardContainer[0].CardNo = CalculateTrackBlock(M100.CacheCard.CardNo);
                    break;

                case CreditCardPayType.ChinaUnionPay:
                    M100.CardContainer[0].Msg2   = M100.CacheCard.Msg2;
                    M100.CardContainer[0].CardNo = M100.CacheCard.CardNo;
                    break;

                default:
                    break;
                }
                //虚拟设备对象
                VisualSelfServiceEquipment equipment = new VisualSelfServiceEquipment()
                {
                    creditCard = M100.CardContainer[0],
                    TerminalNo = Settings.TerminalNo,
                    PinBlock   = pinBlock,
                    PayMoney   = PublicStaticData.Money
                };

                ServiceUtil.PayPreTreatmentClient.Open();
                //保存支付信息用于撤销
                this.LatestPreMsg = ServiceUtil.PayPreTreatmentClient.Pay(equipment);
                ServiceUtil.PayPreTreatmentClient.Close();

                ServiceUtil.PayClient.Open();
                PayResponseModel result = ServiceUtil.PayClient.Pay(LatestPreMsg, CalculateMac(LatestPreMsg));
                ServiceUtil.PayClient.Close();//及时关闭信道
                return(ReBuildResultModel(result));
            }
            catch (FaultException faultEx)
            {//WCF异常
                //释放信道
                ServiceUtil.PayPreTreatmentClient.Abort();
                ServiceUtil.PayClient.Abort();
                throw new ApplicationException(string.Format("WCF服务调用出错:{0}", faultEx.Message));
            }
        }