コード例 #1
0
ファイル: DealRequest_.cs プロジェクト: a864610877/src
        public IResponse GetResponse()
        {
            var mac = this.Mac;
            // var key = Globals.GetKeyEntry(ShopName, PosName);
            var       PosKey = Context.AccountDealService.GetPosKey(ShopName, PosName);
            KeysEntry key    = PosKey == null ? null : new KeysEntry()
            {
                Key1 = PosKey.Key1, Key2 = PosKey.Key2, PosName = PosName, ShopName = ShopName
            };
            var rsp = base.GetResponse <DealResponse_>(2, 3, 11, 12, 13, 14, 25, 32, 41, 42, 44, 49, 53, 54, 60, 64);

            rsp.Result = ResponseCode.Success;
            if (key == null)
            {
                rsp.Result = ResponseCode.NeedSignIn;
            }
            else
            {
                if (!LCDES.MACDecrypt(_data.ToArray(), key.Key2, mac))
                {
                    rsp.Result = ResponseCode.MacError;
                }
                else
                {
                    //rsp.AccountName = AccountName;
                    rsp.DealAmount = DealAmount;
                }
            }

            return(rsp);
        }
コード例 #2
0
        protected string GetPassword(string accountName)
        {
            int len = accountName.Length;

            accountName = accountName.Remove(len - 1);
            _log.Debug(string.Format("卡号:{0}", accountName));
            len = accountName.Length;
            int len1 = len - 12;
            //var key1 = GetCurrentKey().Key1;
            var       PosKey = Context.AccountDealService.GetPosKey(ShopName, PosName);
            KeysEntry key    = PosKey == null ? null : new KeysEntry()
            {
                Key1 = PosKey.Key1, Key2 = PosKey.Key2, PosName = PosName, ShopName = ShopName
            };

            _log.Debug(string.Format("key1:{0}", key.Key1));
            var value1 = accountName.Remove(0, len1);

            _log.Debug(string.Format("解密参数:{0}", value1));
            _log.Debug(string.Format("pos密码:{0}", this.Password));
            //var key1 = GetCurrentKey().Key1;
            //var value1 = AccountName.Substring(AccountName.Length - 13, 12);

            if (string.IsNullOrEmpty(this.Password))
            {
                return("");
            }
            var    d  = LCDES.DesDecryptB(this.Password, key.Key1);
            string gg = BitConverter.ToString(d.ToArray());

            _log.Debug(string.Format("三轨解密密码:{0}", gg));
            _log.Debug(string.Format("二轨解密密码:{0}", GetPasswordFromDecrypt(d, value1)));
            return(GetPasswordFromDecrypt(d, value1));
        }
コード例 #3
0
ファイル: PrePayRequest.cs プロジェクト: a864610877/src
        public IResponse GetResponse()
        {
            var mac = this.Mac;
            // var key = Globals.GetKeyEntry(ShopName, PosName);
            var       PosKey = Context.AccountDealService.GetPosKey(ShopName, PosName);
            KeysEntry key    = PosKey == null ? null : new KeysEntry()
            {
                Key1 = PosKey.Key1, Key2 = PosKey.Key2, PosName = PosName, ShopName = ShopName
            };
            ResponseBase rsp      = null;
            string       dealType = _i8583.gettabx_data(2);

            if (dealType.StartsWith("31"))
            {
                rsp = base.GetResponse <QueryShopResponse>(3, 4, 11, 22, 25, 26, 35, 36, 41, 42, 49, 52, 53, 60, 61, 64);
            }
            if (dealType.StartsWith("03"))
            {
                rsp = base.GetResponse <PrePayResponse>(3, 4, 11, 22, 25, 26, 35, 36, 41, 42, 49, 52, 53, 60, 61, 64);

                rsp.DealAmount = DealAmount;
                if (DealAmount <= 0)
                {
                    rsp.Result = ResponseCode.InvalidateAmount;
                }
            }
            else if (dealType.StartsWith("20"))
            {
                rsp = base.GetResponse <PrePayCancelResponse>(2, 3, 4, 11, 25, 41, 42, 49, 52, 53, 60, 61, 64);
                //rsp = base.GetResponse<PrePayCancelResponse>(ids.ToArray());

                rsp.DealAmount = DealAmount;
                if (DealAmount <= 0)
                {
                    rsp.Result = ResponseCode.InvalidateAmount;
                }
            }
            rsp.Result = ResponseCode.Success;
            if (key == null)
            {
                rsp.Result = ResponseCode.NeedSignIn;
            }
            else
            {
                if (!LCDES.MACDecrypt(_data.ToArray(), key.Key2, mac))
                {
                    rsp.Result = ResponseCode.MacError;
                }
                else
                {
                    rsp.Password    = Password;
                    rsp.AccountName = AccountName;
                    rsp.ShopNameTo  = ShopNameTo;
                }
            }

            return(rsp);
        }
コード例 #4
0
        protected override byte[] OnGetData()
        {
            if (this.Result == ResponseCode.Success && !BadDeals.Check(BatchNo, SerialNo, ShopName, PosName))
            {
                ShopNameTo = (ShopNameTo ?? "").Trim();
                lock (string.Intern(string.IsNullOrWhiteSpace(ShopNameTo) ? ShopName : ShopNameTo))
                {
                    string accountName = this.AccountName.Substring(0, AccountNameLength);
                    string token       = GetToken();
                    _i8583.settabx_data(1, accountName);

                    // KeysEntry key = GetCurrentKey();
                    var       PosKey = Context.AccountDealService.GetPosKey(ShopName, PosName);
                    KeysEntry key    = PosKey == null ? null : new KeysEntry()
                    {
                        Key1 = PosKey.Key1, Key2 = PosKey.Key2, PosName = PosName, ShopName = ShopName
                    };
                    if (Result == ResponseCode.Success)
                    {
                        var    seriaNo  = BatchNo + SerialNo;
                        string passwrod = "";
                        if (this.AccountName.IndexOf("d") > -1)
                        {
                            passwrod = GetPassword(accountName);//磁条卡
                        }
                        else
                        {
                            passwrod = GetPassword(this.AccountName);//IC卡
                        }
                        //string passwrod = GetPassword(this.AccountName);//IC卡

                        var rsp = GetResponse(token, seriaNo, passwrod, accountName);

                        Result = rsp.Code;
                        if (Result == ResponseCode.Success)
                        {
                            SerialServerNo = rsp.SerialServerNo;

                            Amount     = rsp.Amount;     //返回余额
                            DealAmount = rsp.DealAmount; //返回实际交易金额(不能大于上送的交易金额)
                            var theCode = GetTheCode();
                            base.SetAccount(theCode, rsp.ThisTimePoint, 0, rsp.Point);
                            var i8583 = _i8583.Clone();

                            i8583.settabx_data(63, "");

                            var    data = i8583.Pack8583("0210");
                            string mac  = LCDES.MACEncrypt(data, key.Key2, 2);
                            mac = Helper.WrapMac("deal", mac);
                            _i8583.settabx_data(63, mac);
                        }
                    }
                }
            }
            return(_i8583.Pack8583("0210"));
        }
コード例 #5
0
        protected override byte[] OnGetData()
        {
            if (Result == ResponseCode.Success && !BadDeals.Check(BatchNo, SerialNo, ShopName, PosName))
            {
                string accountName = AccountName.Substring(0, AccountNameLength);
                string token       = GetToken();
                _i8583.settabx_data(1, accountName);

                //KeysEntry key = GetCurrentKey();
                var       PosKey = Context.AccountDealService.GetPosKey(ShopName, PosName);
                KeysEntry key    = PosKey == null ? null : new KeysEntry()
                {
                    Key1 = PosKey.Key1, Key2 = PosKey.Key2, PosName = PosName, ShopName = ShopName
                };
                if (Result == ResponseCode.Success)
                {
                    string passwrod = "";
                    if (this.AccountName.IndexOf("d") > -1)
                    {
                        passwrod = GetPassword(accountName);//´ÅÌõ¿¨
                    }
                    else
                    {
                        passwrod = GetPassword(this.AccountName);//IC¿¨
                    }
                    string seriaNo = _i8583.gettabx_data(60);
                    if (seriaNo.Length > 12)
                    {
                        seriaNo = seriaNo.Substring(0, 12);
                    }
                    AccountServiceResponse rsp =
                        Context.AccountDealService.CancelDonePrePay(new CancelPayRequest(accountName, passwrod, PosName, DealAmount,
                                                                                         BatchNo + SerialNo, seriaNo,
                                                                                         token, ShopName));
                    Result = rsp.Code;
                    //this._i8583.settabx_data(37, rsp.DealCode);

                    if (Result == ResponseCode.Success)
                    {
                        this._i8583.settabx_data(37, SerialNo);
                        SerialServerNo = rsp.SerialServerNo.PadLeft(12, '0');
                        Amount         = rsp.Amount;
                        var i8583 = _i8583.Clone();
                        i8583.settabx_data(63, "");
                        var    data = i8583.Pack8583("0210");
                        string mac  = LCDES.MACEncrypt(data, key.Key2, 2);
                        mac = Helper.WrapMac("cancel_done_prepay", mac);
                        _i8583.settabx_data(63, mac);
                    }
                }
            }
            return(_i8583.Pack8583("0210"));
        }
コード例 #6
0
        protected override byte[] OnGetData()
        {
            if (this.Result == ResponseCode.Success && !BadDeals.Check(BatchNo, SerialNo, ShopName, PosName))
            {
                string accountName = this.AccountName.Substring(0, AccountNameLength);
                string token       = GetToken();
                _i8583.settabx_data(1, accountName);

                //KeysEntry key = GetCurrentKey();
                var       PosKey = Context.AccountDealService.GetPosKey(ShopName, PosName);
                KeysEntry key    = PosKey == null ? null : new KeysEntry()
                {
                    Key1 = PosKey.Key1, Key2 = PosKey.Key2, PosName = PosName, ShopName = ShopName
                };

                if (Result == ResponseCode.Success)
                {
                    var    seriaNo  = BatchNo + SerialNo;
                    string passwrod = "";
                    if (this.AccountName.IndexOf("d") > -1)
                    {
                        passwrod = GetPassword(accountName);//´ÅÌõ¿¨
                    }
                    else
                    {
                        passwrod = GetPassword(this.AccountName);//IC¿¨
                    }
                    //var pos = _posRepository.GetPosByName(PosName);
                    AccountServiceResponse rsp =
                        Context.AccountDealService.DonePrePay(new Ecard.Infrastructure.PrePayRequest(BatchNo + this.OldSerialNo, this.OldPayDate, accountName, passwrod, PosName, DealAmount, seriaNo,
                                                                                                     token, ShopName));
                    //rsp = _accountService.Pay(pos, ShopName, accountName, passwrod, DealAmount, dealItem, token);

                    Result = rsp.Code;
                    if (Result == ResponseCode.Success)
                    {
                        this._i8583.settabx_data(37, SerialNo);
                        SerialServerNo = rsp.SerialServerNo.PadLeft(12, '0');
                        Amount         = rsp.Amount;
                        var i8583 = _i8583.Clone();
                        i8583.settabx_data(63, "");
                        var    data = i8583.Pack8583("0210");
                        string mac  = LCDES.MACEncrypt(data, key.Key2, 2);
                        mac = Helper.WrapMac("done_prepay", mac);
                        _i8583.settabx_data(63, mac);
                    }
                }
            }
            return(_i8583.Pack8583("0210"));
        }
コード例 #7
0
        protected override byte[] OnGetData()
        {
            if (this.Result == ResponseCode.Success && !BadDeals.Check(BatchNo, SerialNo, ShopName, PosName))
            {
                string accountName = this.AccountName.Substring(0, AccountNameLength);
                string token       = GetToken();
                _i8583.settabx_data(1, accountName);

                // KeysEntry key = GetCurrentKey();
                var       PosKey = Context.AccountDealService.GetPosKey(ShopName, PosName);
                KeysEntry key    = PosKey == null ? null : new KeysEntry()
                {
                    Key1 = PosKey.Key1, Key2 = PosKey.Key2, PosName = PosName, ShopName = ShopName
                };
                if (Result == ResponseCode.Success)
                {
                    lock (string.Intern(string.IsNullOrWhiteSpace(ShopNameTo) ? ShopName : ShopNameTo))
                    {
                        string passwrod = "";
                        if (this.AccountName.IndexOf("d") > -1)
                        {
                            passwrod = GetPassword(accountName);//磁条卡
                        }
                        else
                        {
                            passwrod = GetPassword(this.AccountName);//IC卡
                        }
                        var rsp = Context.AccountDealService.PrePay(new PayRequest(accountName, passwrod, PosName, DealAmount, BatchNo + SerialNo, token, ShopName, ShopName));
                        Result = rsp.Code;
                        this._i8583.settabx_data(37, SerialNo);
                        if (Result == ResponseCode.Success)
                        {
                            SerialServerNo = rsp.SerialServerNo.PadLeft(12, '0');
                            Amount         = rsp.Amount;
                            var i8583 = _i8583.Clone();
                            i8583.settabx_data(63, "");
                            var    data = i8583.Pack8583("0110");
                            string mac  = LCDES.MACEncrypt(data, key.Key2, 2);
                            mac = Helper.WrapMac("prepay", mac);
                            _i8583.settabx_data(63, mac);
                        }
                    }
                }
            }
            return(_i8583.Pack8583("0110"));
        }
コード例 #8
0
        protected override byte[] OnGetData()
        {
            if (this.Result == ResponseCode.Success)
            {
                //string accountName = this.AccountName.Substring(0, 16);
                //string token = GetToken();
                //_i8583.settabx_data(1, accountName);

                //KeysEntry key = GetCurrentKey();
                var       PosKey = Context.AccountDealService.GetPosKey(ShopName, PosName);
                KeysEntry key    = PosKey == null ? null : new KeysEntry()
                {
                    Key1 = PosKey.Key1, Key2 = PosKey.Key2, PosName = PosName, ShopName = ShopName
                };
                if (Result == ResponseCode.Success)
                {
                    var shoptoName = ShopNameTo ?? "";
                    shoptoName = shoptoName.Trim();
                    //var pos = _posRepository.GetPosByName(PosName);

                    AccountServiceResponse rsp = Context.AccountDealService.QueryShop(PosName, ShopName, shoptoName);
                    //rsp = _accountService.Pay(pos, ShopName, accountName, passwrod, DealAmount, dealItem, token);

                    Result = rsp.Code;
                    if (Result == ResponseCode.Success)
                    {
                        Amount = rsp.Amount;

                        SerialServerNo = rsp.SerialServerNo;
                        var array = BuildForShop(rsp);
                        //_i8583.settabx_data(47, array);
                        var i8583 = _i8583.Clone();
                        i8583.settabx_data(63, "");
                        var    data = i8583.Pack8583("0110");
                        string mac  = LCDES.MACEncrypt(data, key.Key2, 2);
                        mac = Helper.WrapMac("deal", mac);
                        _i8583.settabx_data(63, mac);
                    }
                }
            }
            return(_i8583.Pack8583("0110"));
        }
コード例 #9
0
        protected override byte[] OnGetData()
        {
            if (this.Result == ResponseCode.Success)
            {
                //var key = GetCurrentKey();
                var       PosKey = Context.AccountDealService.GetPosKey(ShopName, PosName);
                KeysEntry key    = PosKey == null ? null : new KeysEntry()
                {
                    Key1 = PosKey.Key1, Key2 = PosKey.Key2, PosName = PosName, ShopName = ShopName
                };
                if (Result == ResponseCode.Success)
                {
                    lock (string.Intern(string.IsNullOrWhiteSpace(ShopNameTo) ? ShopName : ShopNameTo))
                    {
                        //var pos = _posRepository.GetPosByName(this.PosName);
                        var serialNo = BatchNo + SerialNo;
                        BadDeals.Add(BatchNo, SerialNo, ShopName, PosName);
                        //var rsp = _accountService.Deal_(pos, ShopName, DealAmount, serialNo, this.DealTypeValue);

                        var rsp =
                            Context.AccountDealService.Roolback(new PayRequest_(AccountName, Password, PosName,
                                                                                DealAmount, serialNo,
                                                                                serialNo, "", ShopName));
                        Result = rsp.Code;
                        if (Result == ResponseCode.Success)
                        {
                            SerialServerNo = rsp.SerialServerNo;
                            Amount         = rsp.Amount;
                            var i8583 = _i8583.Clone();
                            i8583.settabx_data(63, "");
                            var    data = i8583.Pack8583("0410");
                            string mac  = LCDES.MACEncrypt(data, key.Key2, 2);
                            _i8583.settabx_data(63, mac);
                        }
                    }
                }
            }
            return(_i8583.Pack8583("0410"));
        }
コード例 #10
0
        protected override byte[] OnGetData()
        {
            if (this.Result == ResponseCode.Success)
            {
                string accountName = this.AccountName.Substring(0, AccountNameLength);
                string token       = GetToken();
                _i8583.settabx_data(1, accountName);

                //KeysEntry key = GetCurrentKey();
                var       PosKey = Context.AccountDealService.GetPosKey(ShopName, PosName);
                KeysEntry key    = PosKey == null ? null : new KeysEntry()
                {
                    Key1 = PosKey.Key1, Key2 = PosKey.Key2, PosName = PosName, ShopName = ShopName
                };
                if (Result == ResponseCode.Success)
                {
                    string passwrod = "";
                    if (this.AccountName.IndexOf("d") > -1)
                    {
                        passwrod = GetPassword(accountName);//´ÅÌõ¿¨
                    }
                    else
                    {
                        passwrod = GetPassword(this.AccountName);//IC¿¨
                    }
                    var rsp = Context.AccountDealService.Query(PosName, ShopName, accountName, passwrod, token, NewPassword, OpenCode);
                    Result = rsp.Code;
                    if (OpenCode == "000000000000000000000000000000PASSWORD")
                    {
                        if (Result == ResponseCode.Success)
                        {
                            SerialServerNo = rsp.SerialServerNo;
                            Amount         = rsp.Amount;
                            base.SetAccount("PASSWORD", rsp.Amount, 0, rsp.Point);
                            var i8583 = _i8583.Clone();
                            i8583.settabx_data(63, "");
                            var    data = i8583.Pack8583("0210");
                            string mac  = LCDES.MACEncrypt(data, key.Key2, 2);
                            mac = Helper.WrapMac("password", mac);
                            _i8583.settabx_data(63, mac);
                        }
                    }
                    else
                    {
                        if (Result == ResponseCode.Success)
                        {
                            SerialServerNo = rsp.SerialServerNo;
                            Amount         = rsp.Amount;
                            base.SetAccount("QUERY", rsp.Amount, 0, rsp.Point);
                            var i8583 = _i8583.Clone();
                            i8583.settabx_data(63, "");
                            var    data = i8583.Pack8583("0210");
                            string mac  = LCDES.MACEncrypt(data, key.Key2, 2);
                            mac = Helper.WrapMac("query", mac);
                            _i8583.settabx_data(63, mac);
                        }
                    }
                    //var rsp = Context.AccountDealService.Query(PosName, ShopName, accountName, passwrod, token,NewPassword,OpenCode);
                    //Result = rsp.Code;
                    //if (Result == ResponseCode.Success)
                    //{
                    //    SerialServerNo = rsp.SerialServerNo;
                    //    Amount = rsp.Amount;
                    //    base.SetAccount("QUERY", rsp.Amount, 0, rsp.Point);
                    //    var i8583 = _i8583.Clone();
                    //    i8583.settabx_data(63, "");
                    //    var data = i8583.Pack8583("0210");
                    //    string mac = LCDES.MACEncrypt(data, key.Key2, 2);
                    //    mac = Helper.WrapMac("query", mac);
                    //    _i8583.settabx_data(63, mac);
                    //}
                }
            }
            return(_i8583.Pack8583("0210"));
        }
コード例 #11
0
ファイル: DealRequest.cs プロジェクト: a864610877/src
        public IResponse GetResponse()
        {
            var mac = this.Mac;
            // var key = Globals.GetKeyEntry(ShopName, PosName);
            var       PosKey = Context.AccountDealService.GetPosKey(ShopName, PosName);
            KeysEntry key    = PosKey == null ? null : new KeysEntry()
            {
                Key1 = PosKey.Key1, Key2 = PosKey.Key2, PosName = PosName, ShopName = ShopName
            };                                                                                                                              //Globals.GetKeyEntry(ShopName, PosName);
            ResponseBase rsp      = null;
            string       dealType = _i8583.gettabx_data(2);

            // 查询
            if (dealType.StartsWith("31"))
            {
                rsp = base.GetResponse <QueryResponse>(2, 3, 4, 11, 12, 13, 14, 25, 32, 39, 41, 42, 44, 49, 53, 54, 60, 61, 62, 64);
                //rsp = base.GetResponse<QueryResponse>(2, 3, 11, 12, 13, 14, 25, 32, 39, 41, 42, 44, 49, 53, 54, 60, 61, 62, 64);
                byte[] by = ConvertFrom(NewPassword, NewPassword.Length % 2);
                rsp.NewPassword = System.Text.Encoding.Default.GetString(by);
            }
            // 交易
            else if (dealType.StartsWith("00"))
            {
                //rsp = base.GetResponse<DealResponse>(2, 3, 11, 12, 13, 14, 25, 32, 39, 41, 42, 44, 49, 53, 54, 60, 61, 62, 64);
                if (string.IsNullOrEmpty(this._i8583.gettabx_data(59)) || this._i8583.gettabx_data(59).Substring(0, 2) == "22")
                {
                    rsp = base.GetResponse <DealResponse>(2, 3, 11, 12, 13, 14, 25, 32, 38, 39, 41, 42, 44, 49, 53, 54, 60, 61, 62, 64);
                }

                else if (this._i8583.gettabx_data(59).Substring(0, 2) == "20")
                {
                    rsp = base.GetResponse <PrePayDoneResponse>(2, 3, 11, 12, 13, 14, 25, 32, 38, 39, 41, 42, 44, 49, 53, 54, 60, 61, 62, 64);
                }

                rsp.DealAmount = DealAmount;
                if (DealAmount <= 0)
                {
                    rsp.Result = ResponseCode.InvalidateAmount;
                }
            }
            else if (dealType.StartsWith("20"))
            {
                // rsp = base.GetResponse<DealCancelResponse>(2, 3, 11, 12, 13, 14, 25, 32, 39, 41, 42, 44, 49, 53, 54, 60, 61, 62, 64);
                if (this._i8583.gettabx_data(59).Substring(0, 2) == "23")
                {
                    rsp = base.GetResponse <DealCancelResponse>(2, 3, 11, 12, 13, 14, 25, 32, 38, 39, 41, 42, 44, 49, 53, 54, 60, 61, 62, 64);
                }

                if (this._i8583.gettabx_data(59).Substring(0, 2) == "21")
                {
                    rsp = base.GetResponse <PrePayDoneCancelResponse>(2, 3, 4, 11, 25, 38, 41, 42, 49, 52, 53, 60, 61, 62, 64);
                }
                rsp.DealAmount = DealAmount;
                if (DealAmount <= 0)
                {
                    rsp.Result = ResponseCode.InvalidateAmount;
                }
            }
            var s = Custom1;

            rsp.Result = ResponseCode.Success;
            if (key == null)
            {
                rsp.Result = ResponseCode.NeedSignIn;
            }
            else
            {
                if (!LCDES.MACDecrypt(_data.ToArray(), key.Key2, mac))
                {
                    rsp.Result = ResponseCode.MacError;
                }
                else
                {
                    rsp.Password    = Password;
                    rsp.AccountName = AccountName;
                    rsp.ShopNameTo  = ShopNameTo;
                }
            }

            return(rsp);
        }