Beispiel #1
0
        public void TestPreOrder()
        {
            UnionPayChannel channel = new UnionPayChannel()
            {
                CertificateFilePassword = "******", CertificateFilePath = "D:/cer/630056832596.pfx", MerchantID = "630056832596", PacketEncryptKey = "654321"
            };
            PreOrderRequest req = new PreOrderRequest();

            req.SendTime          = DateTime.Now;
            req.SendSeqID         = Guid.NewGuid().ToString("N");
            req.FrontUrl          = "http://www.jitmarketing.cn:8090/TranNotification.ashx";
            req.MerchantOrderDesc = "呵呵";
            req.Misc = string.Empty;
            //req.GatewayType = GatewayTypes.WAP;
            req.TransTimeout          = DateTime.Now.AddHours(1);
            req.BackUrl               = "http://www.jitmarketing.cn:8090/TranNotification.ashx";
            req.MerchantOrderCurrency = Currencys.RMB;
            req.MerchantOrderAmt      = 1;
            req.MerchantID            = "630056832596";
            req.MerchantOrderTime     = DateTime.Now.AddMinutes(-5);
            req.MerchantOrderID       = Guid.NewGuid().ToString("N");
            req.MerchantUserID        = string.Empty;
            req.MobileNum             = "15388157741";
            req.CarNum = string.Empty;

            var rsp = WapGateway.PreOrder(channel, req);

            Assert.IsTrue(rsp.IsSuccess);
        }
Beispiel #2
0
        private void btnQueryOrder_Click(object sender, EventArgs e)
        {
            //创建支付通道
            UnionPayChannel channel = new UnionPayChannel()
            {
                CertificateFilePassword = ConfigurationManager.AppSettings["WAPEncryptCertificateFilePassword"]
                , CertificateFilePath   = ConfigurationManager.AppSettings["WAPEncryptCertificateFilePath"]
                , MerchantID            = ConfigurationManager.AppSettings["WAPMerchantID"]
                , PacketEncryptKey      = "654321"
            };
            //查询订单
            QueryOrderRequest req = new QueryOrderRequest();

            req.SendTime          = DateTime.Now;
            req.SendSeqID         = Guid.NewGuid().ToString("N");
            req.TransType         = WapTransTypes.PreAuthorization;
            req.MerchantID        = channel.MerchantID;
            req.MerchantOrderID   = this.Session["MerchantOrderID"] as string;
            req.MerchantOrderTime = this.Session["MerchantOrderTime"] as DateTime?;
            //
            try
            {
                var rsp = WapGateway.QueryOrder(channel, req);
                this.txtOrderInfo.Text = rsp.ToString();
            }
            catch (Exception ex)
            {
                this.txtOrderInfo.Text = "执行失败:" + Environment.NewLine + ex.Message;
            }
        }
Beispiel #3
0
        private void btnOrder_Click(object sender, EventArgs e)
        {
            //创建支付通道
            UnionPayChannel channel = new UnionPayChannel()
            {
                CertificateFilePassword = ConfigurationManager.AppSettings["WAPEncryptCertificateFilePassword"]
                ,
                CertificateFilePath = ConfigurationManager.AppSettings["WAPEncryptCertificateFilePath"]
                ,
                MerchantID = ConfigurationManager.AppSettings["WAPMerchantID"]
                ,
                PacketEncryptKey = "654321"
            };
            //下订单
            PreOrderRequest req = new PreOrderRequest();

            req.SendTime          = DateTime.Now;
            req.SendSeqID         = Guid.NewGuid().ToString("N");
            req.FrontUrl          = ConfigurationManager.AppSettings["WAPFrontUrl"]; //商户平台的页面,用户支付完毕后跳转的页面
            req.MerchantOrderDesc = "呵呵";
            req.Misc                  = string.Empty;
            req.TransTimeout          = DateTime.Now.AddHours(1);
            req.BackUrl               = ConfigurationManager.AppSettings["WAPBackUrl"]; //当用户支付完成后,支付平台回调的交易通知的页面
            req.MerchantOrderCurrency = Currencys.RMB;
            req.MerchantOrderAmt      = 1;
            req.MerchantID            = channel.MerchantID;
            req.MerchantOrderTime     = DateTime.Now.AddMinutes(-5);
            req.MerchantOrderID       = Guid.NewGuid().ToString("N");
            req.MerchantUserID        = string.Empty;
            req.MobileNum             = this.txtMobileNO.Text; //消费者的手机号,支付平台会将验证码发送到该手机
            req.CarNum                = string.Empty;
            //记录支付请求日志
            Loggers.Debug(new DebugLogInfo()
            {
                Message = string.Format("[Wap]PreOrder Request={0}", req.GetContent())
            });
            //支付平台成功接收
            var rsp = WapGateway.PreOrder(channel, req);

            //重定向到支付页面
            if (rsp.IsSuccess)
            {
                //
                this.Session["MerchantOrderID"]   = rsp.MerchantOrderID;
                this.Session["MerchantOrderTime"] = rsp.MerchantOrderTime;
                //
                this.ltGotoPay.Text = string.Format("<a href=\"{0}\">去支付</>", rsp.RedirectURL);
                this.ltGotoPay.Mode = LiteralMode.PassThrough;
            }
        }
Beispiel #4
0
        public void TestQueryOrder()
        {
            //先发预订单请求
            UnionPayChannel channel = new UnionPayChannel()
            {
                CertificateFilePassword = "******", CertificateFilePath = "D:/cer/630056832596.pfx", MerchantID = "630056832596", PacketEncryptKey = "654321"
            };
            PreOrderRequest req = new PreOrderRequest();

            req.SendTime          = DateTime.Now;
            req.SendSeqID         = Guid.NewGuid().ToString("N");
            req.FrontUrl          = "http://www.jitmarketing.cn:8090/TranNotification.ashx";
            req.MerchantOrderDesc = "呵呵";
            req.Misc = string.Empty;
            //req.GatewayType = GatewayTypes.WAP;
            req.TransTimeout          = DateTime.Now.AddHours(1);
            req.BackUrl               = "http://www.jitmarketing.cn:8090/TranNotification.ashx";
            req.MerchantOrderCurrency = Currencys.RMB;
            req.MerchantOrderAmt      = 1;
            req.MerchantID            = "630056832596";
            req.MerchantOrderTime     = DateTime.Now.AddMinutes(-5);
            req.MerchantOrderID       = Guid.NewGuid().ToString("N");
            req.MerchantUserID        = string.Empty;
            req.MobileNum             = "15388157741";
            req.CarNum = string.Empty;

            var rsp = WapGateway.PreOrder(channel, req);

            Assert.IsTrue(rsp.IsSuccess);
            //跳转到支付平台页面
            WebClient wc          = new WebClient();
            string    strResponse = wc.UploadString(rsp.RedirectURL, string.Empty);
            //在查询
            QueryOrderRequest req2 = new QueryOrderRequest();

            req2.SendTime          = DateTime.Now;
            req2.SendSeqID         = Guid.NewGuid().ToString("N");
            req2.TransType         = WapTransTypes.PreAuthorization;
            req2.MerchantID        = "630056832596";
            req2.MerchantOrderID   = req.MerchantOrderID;
            req2.MerchantOrderTime = req.MerchantOrderTime;

            var rsp2 = WapGateway.QueryOrder(channel, req2);

            Assert.IsTrue(rsp2.IsSuccess);
        }
Beispiel #5
0
        public void TestParseTransactionNotificationRequest()
        {
            string encrypedReq1 = null;

            using (var s = ReflectionUtils.GetEmbeddedResource("JIT.TestUtility.TestPay.TestMaterial.notification_req1.txt"))
            {
                TextReader reader = new StreamReader(s);
                encrypedReq1 = reader.ReadToEnd();
            }
            var req1 = WapGateway.ParseTransactionNotificationRequest("D:/cer/5101200070003100001.cer", encrypedReq1);

            Assert.IsTrue(req1.ConverRate == null);
            Assert.IsTrue(req1.CupsQid == "201312261540170019212");
            Assert.IsTrue(req1.CupsRespCode == "40");
            Assert.IsTrue(req1.CupsRespDesc == string.Empty);
            Assert.IsTrue(req1.CupsTraceNum == "001921");
            Assert.IsTrue(req1.MerchantID == "630056832596");
            Assert.IsTrue(req1.MerchantOrderAmt == 1);
            Assert.IsTrue(req1.MerchantOrderID == "dc10ae3119014d8180b9f8780398af45");
            Assert.IsTrue(req1.SetlAmt == 1);
            Assert.IsTrue(req1.SetlCurrency == Currencys.RMB);
            Assert.IsTrue(req1.SettleDate == "1226");
            Assert.IsTrue(req1.TransType == WapTransTypes.Consumption);
        }
Beispiel #6
0
        public void ProcessRequest(HttpContext context)
        {
            using (StreamReader sr = new StreamReader(context.Request.InputStream))
            {
                try
                {
                    //读取支付平台发送的交易通知密文
                    string strReq = sr.ReadToEnd();
                    Loggers.Debug(new DebugLogInfo()
                    {
                        Message = "[Wap]Encrypted Transaction Notification Request=" + strReq
                    });
                    //解析交易通知密文,获得交易通知请求的内容
                    var req = WapGateway.ParseTransactionNotificationRequest(ConfigurationManager.AppSettings["WAPDecryptCertificateFilePath"], strReq);
                    Loggers.Debug(new DebugLogInfo()
                    {
                        Message = "[Wap]Decrypted Transaction Notification Request=" + req.GetContent()
                    });
                    if (req.IsPayOK)
                    {//用户支付成功
                        try
                        {
                            //TODO:业务系统自身的订单处理逻辑(通常为:更新订单状态为支付成功)


                            //业务处理完成后,告诉支付平台处理成功
                            var rsp = TransactionNotificationResponse.OK.GetContent();
                            Loggers.Debug(new DebugLogInfo()
                            {
                                Message = string.Format("[Wap]Transaction Notification Response={0}", rsp)
                            });
                            context.Response.Write(rsp);
                        }
                        catch (Exception ex)
                        {//业务处理时如果出现异常
                            //记录日志
                            Loggers.Exception(new ExceptionLogInfo(ex));
                            //告诉支付前置,业务处理失败,支付平台会在一定的时间范围内重发交易通知
                            var rsp = TransactionNotificationResponse.FAILED.GetContent();
                            Loggers.Debug(new DebugLogInfo()
                            {
                                Message = string.Format("[Wap]Transaction Notification Response={0}", rsp)
                            });
                            context.Response.Write(rsp);
                        }
                    }
                    else
                    {//用户支付失败
                        try
                        {
                            //TODO:业务系统自身的订单处理逻辑(通常为:更新订单状态为支付失败)

                            //业务处理完成后,告诉支付平台处理成功
                            var rsp = TransactionNotificationResponse.OK.GetContent();
                            Loggers.Debug(new DebugLogInfo()
                            {
                                Message = string.Format("[Wap]Transaction Notification Response={0}", rsp)
                            });
                            context.Response.Write(rsp);
                        }
                        catch (Exception ex)
                        {//业务处理时如果出现异常
                            //记录日志
                            Loggers.Exception(new ExceptionLogInfo(ex));
                            //告诉支付前置,业务处理失败,支付平台会在一定的时间范围内重发交易通知
                            var rsp = TransactionNotificationResponse.FAILED.GetContent();
                            Loggers.Debug(new DebugLogInfo()
                            {
                                Message = string.Format("[Wap]Transaction Notification Response={0}", rsp)
                            });
                            context.Response.Write(rsp);
                        }
                    }
                }
                catch (Exception ex)
                {//出错
                    Loggers.Exception(new ExceptionLogInfo(ex));
                    context.Response.Write(TransactionNotificationResponse.FAILED.GetContent());
                }
            }
        }
Beispiel #7
0
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                string strRequest = context.Request.Params["ReqContent"];
                //if (string.IsNullOrEmpty(strRequest))
                //{
                //    strRequest = "{\"Token\":\"\",\"CityID\":21,\"UserID\":\"FBEE2CFA-500C-4756-BFAA-000014308165\",\"Locale\":1,\"Parameters\":{\"OrderAmount\":1,\"OrderDesc\":\"测试支付\",\"OrderTime\":\"2013-12-30 16:24:33 367\",\"OrderID\":\"57F2DB3A51EB472AED32E413AA986854\",\"MobileNO\":\"13817218367\",\"PayType\":1}}";
                //}
                var request = strRequest.DeserializeJSONTo <ALDRequest <PayOrderRequest> >();
                switch (request.Parameters.PayType.Value)
                {
                case 1:
                    #region WAP 下单
                {
                    //创建支付通道
                    UnionPayChannel channel = new UnionPayChannel()
                    {
                        CertificateFilePassword = ConfigurationManager.AppSettings["WAPEncryptCertificateFilePassword"]
                        ,
                        CertificateFilePath = ConfigurationManager.AppSettings["WAPEncryptCertificateFilePath"]
                        ,
                        MerchantID = ConfigurationManager.AppSettings["WAPMerchantID"]
                        ,
                        PacketEncryptKey = "654321"
                    };
                    //下订单
                    WAPRequest.PreOrderRequest req = new WAPRequest.PreOrderRequest();
                    req.SendTime          = DateTime.Now;
                    req.SendSeqID         = Guid.NewGuid().ToString("N");
                    req.FrontUrl          = ConfigurationManager.AppSettings["WAPFrontUrl"];   //商户平台的页面,用户支付完毕后跳转的页面
                    req.MerchantOrderDesc = request.Parameters.OrderDesc;
                    req.Misc                  = string.Empty;
                    req.TransTimeout          = DateTime.Now.AddHours(1);
                    req.BackUrl               = ConfigurationManager.AppSettings["WAPBackUrl"]; //当用户支付完成后,支付平台回调的交易通知的页面
                    req.MerchantOrderCurrency = Currencys.RMB;
                    req.MerchantOrderAmt      = request.Parameters.OrderAmount;
                    req.MerchantID            = channel.MerchantID;
                    req.MerchantOrderTime     = DateTime.ParseExact(request.Parameters.OrderTime, "yyyy-MM-dd HH:mm:ss fff", null);
                    req.MerchantOrderID       = request.Parameters.OrderID;
                    req.MerchantUserID        = string.Empty;
                    req.MobileNum             = request.Parameters.MobileNO;  //消费者的手机号,支付平台会将验证码发送到该手机
                    req.CarNum                = string.Empty;
                    //记录支付请求日志
                    Loggers.Debug(new DebugLogInfo()
                        {
                            Message = string.Format("[Wap]PreOrder Request={0}", req.GetContent())
                        });
                    //支付平台成功接收
                    var rsp = WapGateway.PreOrder(channel, req);
                    if (rsp.IsSuccess)
                    {
                        context.Response.Write(rsp.RedirectURL);
                    }
                }
                    #endregion
                    break;

                case 2:
                    #region 语音下单
                {
                    //创建支付通道
                    UnionPayChannel channel = new UnionPayChannel()
                    {
                        CertificateFilePassword = ConfigurationManager.AppSettings["IVREncryptCertificateFilePassword"]
                        ,
                        CertificateFilePath = ConfigurationManager.AppSettings["IVREncryptCertificateFilePath"]
                        ,
                        MerchantID = ConfigurationManager.AppSettings["IVRMerchantID"]
                        ,
                        PacketEncryptKey = "654321"
                    };
                    //下订单
                    IVRRequest.PreOrderRequest req = new IVRRequest.PreOrderRequest();
                    req.SendTime          = DateTime.Now;
                    req.SendSeqID         = Guid.NewGuid().ToString("N");
                    req.FrontUrl          = ConfigurationManager.AppSettings["IVRFrontUrl"];   //商户平台的页面,用户支付完毕后跳转的页面
                    req.MerchantOrderDesc = request.Parameters.OrderDesc;
                    req.Misc                  = string.Empty;
                    req.Mode                  = IVRValueObject.IVRModes.Callback;
                    req.TransTimeout          = DateTime.Now.AddHours(1);
                    req.BackUrl               = ConfigurationManager.AppSettings["IVRBackUrl"]; //当用户支付完成后,支付平台回调的交易通知的页面
                    req.MerchantOrderCurrency = Currencys.RMB;
                    req.MerchantOrderAmt      = request.Parameters.OrderAmount;
                    req.MerchantID            = channel.MerchantID;
                    req.MerchantOrderTime     = DateTime.ParseExact(request.Parameters.OrderTime, "yyyy-MM-dd HH:mm:ss fff", null);
                    req.MerchantOrderID       = request.Parameters.OrderID;
                    req.MerchantUserID        = string.Empty;
                    req.MobileNum             = request.Parameters.MobileNO;  //消费者的手机号,支付前置会将验证码发送到该手机
                    req.CarNum                = string.Empty;
                    //记录支付请求日志
                    Loggers.Debug(new DebugLogInfo()
                        {
                            Message = string.Format("[IVR]PreOrder Request={0}", req.GetContent())
                        });
                    //支付平台成功接收
                    var rsp = IVRGateway.PreOrder(channel, req);
                    //
                    if (rsp.IsSuccess)
                    {
                        context.Response.Write("OK");
                    }
                    else
                    {
                        context.Response.Write("Failed");
                    }
                }
                    #endregion
                    break;
                }
            }
            catch (Exception ex)
            {
                JIT.Utility.Log.Loggers.Exception(new ExceptionLogInfo(ex));
                throw ex;
            }
        }
Beispiel #8
0
        public override bool Process(PayChannelEntity pChannel, HttpContext context, out Entity.AppOrderEntity entity)
        {
            entity = null;
            using (StreamReader sr = new StreamReader(context.Request.InputStream))
            {
                try
                {
                    #region Channel
                    var UnionWapChannel = pChannel.ChannelParameters.DeserializeJSONTo <UnionPayChannel>();
                    #endregion

                    //读取支付平台发送的交易通知密文

                    string strReq = sr.ReadToEnd();
                    Loggers.Debug(new DebugLogInfo()
                    {
                        Message = "[Wap]Encrypted Transaction Notification Request=" + strReq
                    });
                    //解析交易通知密文,获得交易通知请求的内容
                    var req = WapGateway.ParseTransactionNotificationRequest(UnionWapChannel.DecryptCertificateFilePath, strReq);
                    Loggers.Debug(new DebugLogInfo()
                    {
                        Message = "[Wap]Decrypted Transaction Notification Request=" + req.GetContent()
                    });
                    AppOrderBLL bll = new AppOrderBLL(new Utility.BasicUserInfo());
                    entity = bll.GetByID(req.MerchantOrderID);
                    if (req.IsPayOK)
                    {//用户支付成功
                        try
                        {
                            //TODO:业务系统自身的订单处理逻辑(通常为:更新订单状态为支付成功)
                            #region 更新订单状态
                            entity.Status       = 2;
                            entity.ErrorMessage = "";
                            bll.Update(entity);
                            #endregion

                            //业务处理完成后,告诉支付平台处理成功
                            var rsp = TransactionNotificationResponse.OK.GetContent();
                            Loggers.Debug(new DebugLogInfo()
                            {
                                Message = string.Format("[Wap]Transaction Notification Response={0}", rsp)
                            });

                            context.Response.Write(rsp);
                            return(true);
                        }
                        catch (Exception ex)
                        {//业务处理时如果出现异常
                            //记录日志
                            Loggers.Exception(new ExceptionLogInfo(ex));
                            //告诉支付前置,业务处理失败,支付平台会在一定的时间范围内重发交易通知
                            var rsp = TransactionNotificationResponse.FAILED.GetContent();
                            Loggers.Debug(new DebugLogInfo()
                            {
                                Message = string.Format("[Wap]Transaction Notification Response={0}", rsp)
                            });
                            context.Response.Write(rsp);
                            return(false);
                        }
                    }
                    else
                    {//用户支付失败
                        try
                        {
                            //TODO:业务系统自身的订单处理逻辑(通常为:更新订单状态为支付失败)
                            entity.ErrorMessage = req.PayFailedReason;
                            bll.Update(entity);
                            //业务处理完成后,告诉支付平台处理成功
                            var rsp = TransactionNotificationResponse.OK.GetContent();
                            Loggers.Debug(new DebugLogInfo()
                            {
                                Message = string.Format("[Wap]Transaction Notification Response={0}", rsp)
                            });
                            context.Response.Write(rsp);
                            return(false);
                        }
                        catch (Exception ex)
                        {//业务处理时如果出现异常
                            //记录日志
                            Loggers.Exception(new ExceptionLogInfo(ex));
                            //告诉支付前置,业务处理失败,支付平台会在一定的时间范围内重发交易通知
                            var rsp = TransactionNotificationResponse.FAILED.GetContent();
                            Loggers.Debug(new DebugLogInfo()
                            {
                                Message = string.Format("[Wap]Transaction Notification Response={0}", rsp)
                            });
                            context.Response.Write(rsp);
                            return(false);
                        }
                    }
                }
                catch (Exception ex)
                {//出错
                    Loggers.Exception(new ExceptionLogInfo(ex));
                    context.Response.Write(TransactionNotificationResponse.FAILED.GetContent());
                    return(false);
                }
            }
        }