Exemple #1
0
        /// <summary>
        /// 公交签到
        /// </summary>
        /// <returns></returns>
        public static BusRegisterInfo BusRegister()
        {
            SysBLL.Authcode = BusLogin();
            string reqsn = SysBLL.getSerialNum();
            //公交卡签到
            BusInterface     access = new BusInterface();
            BusRegisterParam param  = new BusRegisterParam();

            param.authcode     = SysBLL.Authcode;                // 认证码 not nullA
            param.servicename  = "DL002";                        //交易类型编号 not nullA
            param.trandateTime = SysBLL.getYYYYMMDDHHMMSSTime(); //交易日期 YYYYMMDDHHMMSS not nullA
            param.resqn        = reqsn;                          //请求流水号  not nullA
            param.btype        = "0010";                         //业务类型 not nullA
            param.terno        = SysBLL.getMac();                //终端编号  not nullA
            param.tradeno      = SysBLL.getHHMMSSITime10();      //交易流水号 not nullA
            param.loginId      = SysBLL.getCpuNo();              //设备ID
            BusRegisterInfo busRegisterInfo1 = access.BusRegister(param);

            param.btype    = "0011";                              //业务类型 not nullA
            param.authcode = busRegisterInfo1.msgrsp.authcode;    // 认证码 not nullA
            param.opno     = busRegisterInfo1.cpumsg.OUTPUT.OPNO; //操作员卡号 null
            param.random   = busRegisterInfo1.cpumsg.OUTPUT.RANDOM;
            BusRegisterInfo busRegisterInfo2 = access.BusRegister(param);

            busRegisterInfo2.msgrsp             = new BusRegisterMsgrsp();
            busRegisterInfo2.msgrsp.authcode    = busRegisterInfo1.msgrsp.authcode;
            busRegisterInfo2.cpumsg.OUTPUT.OPNO = busRegisterInfo1.cpumsg.OUTPUT.OPNO;
            return(busRegisterInfo2);
        }
Exemple #2
0
        public static BusPayresInfo BusPayres(BusPayresParam param)
        {
            BusInterface access = new BusInterface();

            param.authcode     = SysBLL.Authcode;
            param.servicename  = "DD004";
            param.trandateTime = SysBLL.getYYYYMMDDHHMMSSTime();;
            param.reqsn        = SysBLL.getSerialNum();
            param.loginId      = SysBLL.getCpuNo();
            param.payCode      = "Z000000004";
            param.trandeNo     = SysBLL.getHHMMSSITime10();;
            return(access.BusPayres(param));
        }
        private void pay()
        {
            log.Write("--------------------交易开始--------------------");
            log.Write("----------缴费类型:公交");
            try
            {
                WantongBLL wt           = new WantongBLL();
                string     wtCard       = "";
                string     icParamsJson = "";

                string order        = "";
                string orderparam   = "";
                string serialStr    = "";
                string reconcStr    = "";
                string result       = "";
                string jsonPayParam = "";

                string busCard = "";

                string batchNo  = "";
                string payMoney = "";

                //交易日志,订单编号
                string orderNo = "";
                //交易日志,商户类型
                string shopType = "";

                string shopNo = "";

                string trandNo = "";

                PasswordBLL pwdBLL = new PasswordBLL();
                Dictionary <string, string> map = null;
                string payCode = "Z000000003";//payCode = "Z000000005";

                string ClientNo = "";

                string terminalNo = SysConfigHelper.readerNode("ClientNo");

                if (icParams != null)
                {
                    payCode    = "Z000000005";
                    terminalNo = SysConfigHelper.readerNode("LklClientNo");
                }

                WintopPayParam witonPay = new WintopPayParam();

                witonPay.price = payParam.UserInputMoney;
                witonPay.pwd   = payParam.Pwd;
                busCard        = Payment.BusPayParam.BusNo;
                BusReChangeParam busReChangeParam = new BusReChangeParam();
                busReChangeParam.appsid       = payParam.Output.APPSID;
                busReChangeParam.paymentAmout = payParam.UserInputMoney;
                busReChangeParam.paymentno    = busCard;
                busReChangeParam.wmoney       = payParam.Output.WMONEY;
                busReChangeParam.trandeNo     = SysBLL.getHHMMSSITime10();
                //busReChangeParam.orderno = orderNo;
                log.Write("发起公交充值");

                BusCpuCardParam param          = new BusCpuCardParam();
                BusCpuCardInfo  busCpuCardInfo = BusAccess.GetOrder(busReChangeParam, param, payCode);
                Payment.BusPayParam.BusCpuCardInfo = busCpuCardInfo;
                string cloudNo = busCpuCardInfo.msgrsp.orderno;

                //向后台发送订单记录
                if (icParams == null)
                {
                    orderNo = Wanton.GetOrderNo();
                    //tradeRecord.branch_termail_no = SysConfigHelper.readerNode("ClientNo");
                    ClientNo = BusPayParam.busShopNo + "|" + SysConfigHelper.readerNode("ClientNo");
                }
                else
                {
                    orderNo  = LKLProcedure.GetOrderNo();
                    ClientNo = BusPayParam.busShopNo + "|" + BusPayParam.busClient;
                }
                //支付
                try
                {
                    if (icParams == null)
                    {
                        log.Write("交易类型:万通交易");
                        //万通卡号
                        //orderNo = SysBLL.GetRnd(6, true, false, false, false, "");
                        shopNo            = orderNo + "|" + SysConfigHelper.readerNode("ClientNo") + "|" + SysConfigHelper.readerNode("ShopNo");
                        witonPay.orderNo  = orderNo;
                        witonPay.price    = payParam.UserInputMoney;
                        wtCard            = wt.GetCardNo();
                        witonPay.wintopNo = wtCard;
                        pwdBLL.SetCryptMode(1);//万通卡加密方式
                        log.Write("万通卡号:" + witonPay.wintopNo);
                        log.Write("交易金额:" + witonPay.price);
                        log.Write("终端交易流水号" + orderNo);
                        log.Write("开始支付");
                        witonPay.pwd = payParam.Pwd;
                        map          = Wanton.pay(witonPay, BusPayParam.busShopNo);
                        shopType     = "1";
                        jsonPayParam = JsonConvert.SerializeObject(witonPay);
                        map.Add("payParam", jsonPayParam);
                    }
                    else
                    {
                        log.Write("交易类型:拉卡拉交易");
                        //银行卡
                        //orderNo = SysBLL.GetOrderNo();
                        shopNo  = orderNo + "|" + SysConfigHelper.readerNode("ClientNo") + "|" + SysConfigHelper.readerNode("ShopNo");
                        batchNo = SysBLL.GetBatchNo();
                        pwdBLL.SetCryptMode(0);//银行卡加密方式
                        payMoney = payParam.UserInputMoney;
                        log.Write("银行卡号:" + icParams["cardNo"]);
                        log.Write("交易金额:" + payMoney);
                        log.Write("终端交易流水号" + orderNo);
                        log.Write("开始支付");
                        map          = wtPayBLL.LKLProcedure.PayOrder(payParam.Pwd, payMoney, icParams, orderNo, batchNo, BusPayParam.busShopNo, BusPayParam.busClient);
                        shopType     = "0";
                        icParamsJson = JsonConvert.SerializeObject(icParams);
                        map.Add("bankParam", icParamsJson);
                    }
                    map.Add("orderType", "5");    //1、广电 2、水务3、燃气4、电力5、公交6、万通卡7、热力
                    map.Add("payType", shopType); //拉卡拉是0,万通是1
                    map.Add("payOrderNo", orderNo);
                    map.Add("busCardNo", busCard);

                    //如果万通支付成功
                    if (!map["recode"].Equals("00"))
                    {
                        if ("55".Equals(map["recode"]))
                        {
                            SysBLL.PasswordErrorInfo = "密码错误,请重新输入!";
                            log.Write("密码错误");
                            log.Write("--------------------交易结束--------------------");
                            if (icParams == null)
                            {
                                pwdBLL.OpenKeyboard(SysConfigHelper.readerNode("ZT598Port"), "9600", wtCard);
                                this.Dispatcher.Invoke(new Action(() => { Util.JumpUtil.jumpCommonPage("FormInputPassword"); }));
                                return;
                            }
                            else
                            {
                                pwdBLL.OpenKeyboard(SysConfigHelper.readerNode("ZT598Port"), "9600", icParams["cardNo"]);
                                this.Dispatcher.Invoke(new Action(() => { Util.JumpUtil.jumpCommonPage("FormInputPassword"); }));
                                return;
                            }
                        }
                        else if ("51".Equals(map["recode"]))
                        {
                            log.Write("余额不足");
                            exit("余额不足");
                            return;
                        }
                        else
                        {
                            log.Write("支付失败:返回码:" + map["recode"]);
                            exit("充值失败,请重新缴费,或退卡");
                            return;
                        }
                    }
                }
                catch (Exception ex)
                {
                    log.Write("支付异常,发起冲正:" + ex.Message);
                    //冲正
                    if (icParams == null)
                    {
                        //万通冲正
                        for (int i = 1; i <= 3; i++)
                        {
                            try
                            {
                                Dictionary <string, string> mapCor = Wanton.correct(witonPay, BusPayParam.busShopNo);
                                if (mapCor == null)
                                {
                                    mapCor = new Dictionary <string, string>();
                                }
                                mapCor.Add("payParam", jsonPayParam);
                                mapCor.Add("orderType", "5");    //1、广电 2、水务3、燃气4、电力5、公交6、万通卡7、热力
                                mapCor.Add("payType", shopType); //拉卡拉是0,万通是1
                                mapCor.Add("payOrderNo", orderNo);
                                mapCor.Add("busCardNo", busCard);


                                if (mapCor["recode"].Equals("00"))
                                {
                                    log.Write("冲正成功");
                                    break;
                                }
                                else
                                {
                                    log.Write("冲正失败,返回码:" + mapCor["recode"]);
                                }
                            }
                            catch (Exception)
                            {
                                log.Write("冲正失败");
                            }
                            finally { Thread.Sleep(wtPayUtils.Fibonacci(i) * 1000); }
                        }
                        exit("充值失败,请重新缴费,或退卡");
                        return;
                    }
                    else
                    {
                        for (int i = 1; i <= 3; i++)
                        {
                            try
                            {
                                //拉卡拉冲正
                                Dictionary <string, string> ret = LKLProcedure.correct(icParams, payMoney, orderNo, batchNo);
                                if (ret == null)
                                {
                                    ret = new Dictionary <string, string>();
                                }
                                ret.Add("payParam", jsonPayParam);
                                ret.Add("orderType", "5");    //1、广电 2、水务3、燃气4、电力5、公交6、万通卡7、热力
                                ret.Add("payType", shopType); //拉卡拉是0,万通是1
                                ret.Add("payOrderNo", orderNo);
                                ret.Add("busCardNo", busCard);

                                if (ret["recode"].Equals("00"))
                                {
                                    log.Write("冲正成功");
                                    break;
                                }
                                else
                                {
                                    log.Write("冲正失败,返回码:" + ret["recode"]);
                                }
                            }
                            catch (Exception ex8) { log.Write("冲正失败"); }
                            finally { Thread.Sleep(wtPayUtils.Fibonacci(i) * 1000); }
                        }
                        exit("充值失败,请重新缴费,或退卡");
                        return;
                    }
                }
                string busOrderNo = "";
                string recode     = "";
                //发送订单,充值
                try
                {
                    trandNo        = map["cloudOrderNo"];
                    busCpuCardInfo = BusAccess.ReCharge(busCpuCardInfo, param);


                    if (busCpuCardInfo.cpumsg.OUTPUT != null)
                    {
                        try
                        {
                            order = JsonConvert.SerializeObject(busCpuCardInfo);
                            map.Add("payres", order);
                            orderparam = JsonConvert.SerializeObject(busReChangeParam);
                            map.Add("payresparam", orderparam);
                            map.Add("state", "消费成功");
                            map.Add("type", "1");//1消费,2冲正,3消费撤销
                            serialStr = JsonConvert.SerializeObject(map);
                            reconcStr = busCpuCardInfo.msgrsp.orderno + "|" + busCard + "|" + busCpuCardInfo.msghead.reqsn + "|" + orderNo + "|" + busCpuCardInfo.msgrsp.paymentAmout + "|" + SysBLL.getYYYYMMDDHHMMSSTime() + "|" + busCpuCardInfo.msgrsp.Tac + "|" + busCpuCardInfo.msghead.reqsn + "|" + payParam.Output.WMONEY + "";


                            result = HttpHelper.sendPaymentLog(serialStr, reconcStr, shopNo, shopType, "1");
                        }
                        catch (Exception ex) { log.Write("发送对账信息异常:" + ex.Message); }
                        finally
                        {
                            log.Write("交易成功,交易信息:" + reconcStr);
                            log.Write("--------------------交易结束--------------------");
                            //支付成功
                            this.Dispatcher.Invoke(new Action(() => { Util.JumpUtil.jumpCommonPage("FormBusStep08_success"); }));
                        }
                        return;
                    }
                    throw new Exception();
                }
                catch (Exception ex3)
                {
                    log.Write("支付通知交易异常:" + ex3.Message);
                    //string refund = map["_2"] + "|" + map["_4"] + "|" + map["_59"] + "|" + "";
                    //退款
                    string conName = "公交卡退费申请";
                    //string payOrderNo = busCpuCardInfo.msgrsp.orderno;
                    //tring payOrderNo = busOrderNo.ToString();
                    string payOrderNo  = cloudNo;
                    string transType   = "02";
                    string serviceName = "TK001";

                    try
                    {
                        if (icParams == null)
                        {
                            //string sendPaymentLogResult = HttpHelper.sendPaymentLog(serialStr, reconcStr, shopNo, shopType);
                            //JObject paymentLogObject = JObject.Parse(sendPaymentLogResult);//用于获取后台生成的ID
                            string refundRequestState = "0";//是否需要向云平台发起退款申请
                        }
                        else
                        {
                            //string sendPaymentLogResult = HttpHelper.sendPaymentLog(serialStr, reconcStr, shopNo, shopType);
                            //JObject paymentLogObject = JObject.Parse(sendPaymentLogResult);//用于获取后台生成的ID
                            string refundRequestState = "1";//是否需要向云平台发起退款申请
                        }
                    }
                    catch (Exception ex) { log.Write("退款异常:" + ex.Message); }
                    finally
                    {
                        payFail("充值失败,请重新缴费,或退卡");
                    }
                    return;
                }
            }
            catch (Exception ex5)
            {
                log.Write("交易异常:" + ex5.Message);
                exit("充值失败,请重新缴费,或退卡");
                return;
            }
        }
Exemple #4
0
        /// <summary>
        /// 公交卡查询
        /// </summary>
        /// <returns></returns>
        public static BusQueryThatInfo QueryBus()
        {
            bool isSuccess = false;
            //签到
            BusRegisterInfo busRegisterInfo = BusAccess.BusRegister();

            if (busRegisterInfo.cpumsg != null)
            {
                isSuccess = true;
            }
            //公交卡签到未成功
            if (isSuccess == false)
            {
                throw new Exception("公交卡签到未成功");
            }
            isSuccess = false;
            BusQueryInfo busQueryInfo = new BusQueryInfo();

            //公交卡查询
            BusInterface  access       = new BusInterface();
            BusQueryParam param        = new BusQueryParam();
            string        inapdu       = "";
            string        trandateTime = SysBLL.getYYYYMMDDHHMMSSTime();
            string        reqsn        = SysBLL.getSerialNum();
            string        APDUDATA     = "";
            string        APDUSW       = "";
            string        RETDATA      = "";
            int           APDUSUM      = 0;
            string        step         = "0";

            param.authcode     = SysBLL.Authcode;
            param.servicename  = "DS001";
            param.trandateTime = trandateTime;
            param.reqsn        = reqsn;
            param.opno         = busRegisterInfo.cpumsg.OUTPUT.OPNO;
            param.scode        = busRegisterInfo.cpumsg.OUTPUT.SCODE;
            param.terno        = SysBLL.getMac();
            param.tradeno      = SysBLL.getHHMMSSITime10();
            param.btype        = "1900";
            param.inapdu       = inapdu;
            param.step         = step;
            param.loginId      = SysBLL.getCpuNo(); //设备ID
            busQueryInfo       = access.BusQuery1(param);


            if (busQueryInfo.cpumsg.OUTPUT.OUTAPDU.APDU != null)
            {
                isSuccess = true;
            }
            //公交查询未成功
            if (isSuccess == false)
            {
                throw new Exception("公交查询未成功");
            }
            isSuccess = false;

            step = busQueryInfo.cpumsg.OUTPUT.STEP;
            string     status = busQueryInfo.cpumsg.OUTPUT.OUTAPDU.LASTAPDU;
            BusCardBLL bus    = new BusCardBLL();

            string port = SysConfigHelper.readerNode("CRT603Port");
            //int openRet = CRT603.CRT603Vx_OpenConnection(Int32.Parse(port), 19200);
            //上电
            int iOutAtrLen = 0;

            byte[] byOutAtrData      = new byte[1024];
            int    chipRet           = CRT603.CRT603Vx_RF_chipPower(ref iOutAtrLen, byOutAtrData);
            string apduData          = "";
            List <BusQueryApdu> apdu = busQueryInfo.cpumsg.OUTPUT.OUTAPDU.APDU;
            string result            = "";
            string last = "";

            for (int i = 0; i < apdu.Count; i++)
            {
                APDUDATA = APDUDATA + apdu[i].APDUDATA + "|";

                result = bus.sendApdu(apdu[i].APDUDATA);

                last   = result.Substring(result.Length - 4);
                APDUSW = APDUSW + last + "|";
                result = result.Remove(result.Length - 4, 4);
                if (apduData != null)
                {
                    RETDATA = RETDATA + result + "|";
                }
                Thread.Sleep(20);
                APDUSUM++;
            }
            //CRT603.CRT603Vx_CloseConnection();
            APDUDATA = APDUDATA.Remove(APDUDATA.Length - 1, 1);
            APDUSW   = APDUSW.Remove(APDUSW.Length - 1, 1);
            RETDATA  = RETDATA.Remove(RETDATA.Length - 1, 1);
            BusQueryThatInfo busQueryInfo2 = null;

            while (true)
            {
                param.inapdu   = "yes";
                param.step     = step;
                param.APDUSUM  = APDUSUM.ToString();
                param.APDUDATA = APDUDATA;
                param.APDUSW   = APDUSW;
                param.RETDATA  = RETDATA;
                //表示最后一条
                if (status.Equals("01"))
                {
                    //结果
                    busQueryInfo2 = access.BusQuery2(param);
                    //处理结果
                    return(busQueryInfo2);
                }
                //继续查询
                busQueryInfo2 = access.BusQuery2(param);
                if (busQueryInfo2.cpumsg.OUTPUT != null)
                {
                    isSuccess = true;
                }
                //公交查询未成功
                if (isSuccess == false)
                {
                    throw new Exception("公交查询未成功");
                }
                isSuccess = false;
                APDUDATA  = "";
                APDUSW    = "";
                RETDATA   = "";
                List <BusQueryApdu> apdu2 = busQueryInfo.cpumsg.OUTPUT.OUTAPDU.APDU;

                for (int i = 0; i < apdu.Count; i++)
                {
                    APDUDATA = APDUDATA + apdu2[i].APDUDATA + "|";
                    result   = bus.sendApdu(apdu2[i].APDUDATA);
                    last     = result.Substring(result.Length - 4);
                    result   = result.Remove(result.Length - 4, 4);
                    APDUSW   = last + APDUSW + "|";
                    //执行apdu
                    RETDATA = RETDATA + result + "|";
                }
                APDUDATA = APDUDATA.Remove(APDUDATA.Length - 1, 1);
                APDUSW   = APDUSW.Remove(APDUSW.Length - 1, 1);
                RETDATA  = RETDATA.Remove(RETDATA.Length - 1, 1);
                step     = busQueryInfo.cpumsg.OUTPUT.STEP;
                status   = busQueryInfo.cpumsg.OUTPUT.OUTAPDU.LASTAPDU;
            }
        }