Esempio n. 1
0
        private void btnQueryOrder_Click(object sender, EventArgs e)
        {
            //创建支付通道
            UnionPayChannel channel = new UnionPayChannel()
            {
                CertificateFilePassword = ConfigurationManager.AppSettings["IVREncryptCertificateFilePassword"]
                ,
                CertificateFilePath = ConfigurationManager.AppSettings["IVREncryptCertificateFilePath"]
                ,
                MerchantID = ConfigurationManager.AppSettings["IVRMerchantID"]
                ,
                PacketEncryptKey = "654321"
            };
            //查询订单
            QueryOrderRequest req = new QueryOrderRequest();

            req.SendTime          = DateTime.Now;
            req.SendSeqID         = Guid.NewGuid().ToString("N");
            req.TransType         = IVRTransTypes.PreAuthorization;
            req.MerchantID        = channel.MerchantID;
            req.MerchantOrderID   = this.Session["MerchantOrderID"] as string;
            req.MerchantOrderTime = this.Session["MerchantOrderTime"] as DateTime?;
            //
            try
            {
                var rsp = IVRGateway.QueryOrder(channel, req);
                this.txtOrderInfo.Text = rsp.ToJSON();
            }
            catch (Exception ex)
            {
                this.txtOrderInfo.Text = "执行失败:" + Environment.NewLine + ex.Message;
            }
        }
Esempio n. 2
0
        public void TestParseTransactionNotificationRequest()
        {
            string encrypedReq1 = "MjY3MDk5NjMzMjE4|Aa/qpl2e+s6+kfKQY0H9rYQTbA6n0o1k/JlBTQezC81hXdIXjZLohIF1lOGTtC6q1luGeXrSHHxusCZdg5gHCz79gEQkdq4eHWN6aZPryu/DbvNv7jXVxnors+ZqFqJE2zeWp0Lr5Fu9S3zXl0w7unAxfz766Kltruy+4MXYKr4=|oIUNRpv1nzvfQQunMn70rG260iepVSeX8UmvVFxewcSjdiFPEoqP1LcMevlQBj+6wk8yKWtH8V3A51/JVgA4mWQoqYtaSrsne5wUN0wvb8ejbjgSiyu00wg3EDHSW+enaHNg399iPu+DQ929XVGyHvDYrpXqv3eZwROP+LKZ/2QR5zGZGqPYxiZu6N1rAyK4ZqZvabWLC6rlDLnmA23lXXL4eGhRixbKSmXuTJ7AsIsQbVEi5mkIMM5LIncQDVUqmYzLPNQHESv07WoWjzAb01dox1//kxzVj1k90p7uPaczkhjort48xdoasbqeixSMVA49oa52qgFkDPUTbxioOVdox1//kxzV47Uzt3uucC0ocl1rZ3TPEV0L7rqTMTY2m+KOz89IscKqR7zrrDujO+qPccNnwwSG0Os8Aeb0DoeVhiyjpWW4lrErBXrLWx/HdbHN9FH31ayW2PFVxfFzysochNP2S/1ONE1bx6WsJ2VaUoGP4ptUTzRr7QOQKKfDBUQ/uOZk3QD5MYUy/JQsgDfv2YNd17NV1zESRTLwDE5sxg+BeGVAytstx6xPeBveg0PdvV1Rsh6p8/RQBVIuVxlC4kYCUfMHjiqueqWn4ovuFnT3e1qzZJ10PfG44mwdJrLSNhTPc+fc32ObyDWV4pcRqHqTOVHC8wI895/+IwpvSnVFU1KXnyay0jYUz3PndSO7nNl7cLrZMDmrTpmgJyhv/Pz3Jma7XZEYHjzXrVUUb3uOJmyEgtLSb86Nxext5aZLdb2GG9vgDCZaa9izZZkHmP5I9erDrlU+4B4wiH0=";
            var    req1         = IVRGateway.ParseTransactionNotificationRequest("D:/cer/ivr.cer", encrypedReq1);

            Assert.IsTrue(req1 != null);
        }
Esempio n. 3
0
        public void TestPreOrder()
        {
            UnionPayChannel channel = new UnionPayChannel()
            {
                CertificateFilePassword = "******", CertificateFilePath = "D:/cer/700000000000001.pfx", MerchantID = "267099633218", 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.Mode = IVRModes.Callback;
            //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            = channel.MerchantID;
            req.MerchantOrderTime     = DateTime.Now.AddMinutes(-5);
            req.MerchantOrderID       = Guid.NewGuid().ToString("N").Substring(0, 30);
            req.MerchantUserID        = string.Empty;
            req.MobileNum             = "18019438327";
            req.CarNum = string.Empty;

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

            Assert.IsTrue(rsp.IsSuccess);
        }
Esempio n. 4
0
        private void btnOrder_Click(object sender, EventArgs e)
        {
            //创建支付通道
            UnionPayChannel channel = new UnionPayChannel()
            {
                CertificateFilePassword = ConfigurationManager.AppSettings["IVREncryptCertificateFilePassword"]
                ,
                CertificateFilePath = ConfigurationManager.AppSettings["IVREncryptCertificateFilePath"]
                ,
                MerchantID = ConfigurationManager.AppSettings["IVRMerchantID"]
                ,
                PacketEncryptKey = "654321"
            };
            //下订单
            PreOrderRequest req = new PreOrderRequest();

            req.SendTime          = DateTime.Now;
            req.SendSeqID         = Guid.NewGuid().ToString("N");
            req.FrontUrl          = ConfigurationManager.AppSettings["IVRFrontUrl"]; //商户平台的页面,用户支付完毕后跳转的页面
            req.MerchantOrderDesc = "呵呵";
            req.Misc                  = string.Empty;
            req.Mode                  = IVRModes.Callback;
            req.TransTimeout          = DateTime.Now.AddHours(1);
            req.BackUrl               = ConfigurationManager.AppSettings["IVRBackUrl"]; //当用户支付完成后,支付平台回调的交易通知的页面
            req.MerchantOrderCurrency = Currencys.RMB;
            req.MerchantOrderAmt      = 1;
            req.MerchantID            = channel.MerchantID;
            req.MerchantOrderTime     = DateTime.Now.AddMinutes(-5);
            req.MerchantOrderID       = Guid.NewGuid().ToString("N").Substring(0, 30);
            req.MerchantUserID        = string.Empty;
            req.MobileNum             = this.txtMobileNO.Text; //消费者的手机号,支付前置会将验证码发送到该手机
            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)
            {
                //
                this.Session["MerchantOrderID"]   = rsp.MerchantOrderID;
                this.Session["MerchantOrderTime"] = rsp.MerchantOrderTime;
                //
                this.ltGotoPay.Text = "订单创建成功,请等待支付平台呼入.";
                this.ltGotoPay.Mode = LiteralMode.PassThrough;
            }
        }
Esempio n. 5
0
        public override bool Process(PayChannelEntity pChannel, HttpContext context, out Entity.AppOrderEntity entity)
        {
            using (StreamReader sr = new StreamReader(context.Request.InputStream))
            {
                try
                {
                    #region Channel
                    var UnionIVRChannel = pChannel.ChannelParameters.DeserializeJSONTo <UnionPayChannel>();
                    #endregion

                    //读取支付平台发送的交易通知密文
                    string strReq = sr.ReadToEnd();
                    Loggers.Debug(new DebugLogInfo()
                    {
                        Message = "[IVR]Encrypted Transaction Notification Request=" + strReq
                    });
                    //解析交易通知密文,获得交易通知请求的内容
                    var req = IVRGateway.ParseTransactionNotificationRequest(UnionIVRChannel.DecryptCertificateFilePath, strReq);
                    Loggers.Debug(new DebugLogInfo()
                    {
                        Message = "[IVR]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("[IVR]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("[IVR]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("[IVR]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("[IVR]Transaction Notification Response={0}", rsp)
                            });
                            context.Response.Write(rsp);
                            return(false);
                        }
                    }
                }
                catch (Exception ex)
                {//出错
                    entity = null;
                    Loggers.Exception(new ExceptionLogInfo(ex));
                    context.Response.Write(TransactionNotificationResponse.FAILED.GetContent());
                    return(false);
                }
            }
        }
Esempio n. 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 = "[IVR]Encrypted Transaction Notification Request=" + strReq
                    });
                    //解析交易通知密文,获得交易通知请求的内容
                    var req = IVRGateway.ParseTransactionNotificationRequest(ConfigurationManager.AppSettings["IVRDecryptCertificateFilePath"], strReq);
                    Loggers.Debug(new DebugLogInfo()
                    {
                        Message = "[IVR]Decrypted Transaction Notification Request=" + req.GetContent()
                    });
                    if (req.IsPayOK)
                    {//用户支付成功
                        try
                        {
                            //TODO:业务系统自身的订单处理逻辑(通常为:更新订单状态为支付成功)


                            //业务处理完成后,告诉支付平台处理成功
                            var rsp = TransactionNotificationResponse.OK.GetContent();
                            Loggers.Debug(new DebugLogInfo()
                            {
                                Message = string.Format("[IVR]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("[IVR]Transaction Notification Response={0}", rsp)
                            });
                            context.Response.Write(rsp);
                        }
                    }
                    else
                    {//用户支付失败
                        try
                        {
                            //TODO:业务系统自身的订单处理逻辑(通常为:更新订单状态为支付失败)

                            //业务处理完成后,告诉支付平台处理成功
                            var rsp = TransactionNotificationResponse.OK.GetContent();
                            Loggers.Debug(new DebugLogInfo()
                            {
                                Message = string.Format("[IVR]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("[IVR]Transaction Notification Response={0}", rsp)
                            });
                            context.Response.Write(rsp);
                        }
                    }
                }
                catch (Exception ex)
                {//出错
                    Loggers.Exception(new ExceptionLogInfo(ex));
                    context.Response.Write(TransactionNotificationResponse.FAILED.GetContent());
                }
            }
        }
Esempio n. 7
0
        /// <summary>
        /// 记录请求支付日志信息
        /// </summary>
        /// <param name="response"></param>
        /// <param name="para"></param>
        /// <param name="bll"></param>
        /// <param name="entity"></param>
        /// <param name="channel"></param>
        /// <returns></returns>
        private static string CreatePayRecord(CreateOrderResponse response, CreateOrderParameters para, AppOrderBLL bll, AppOrderEntity entity, PayChannelEntity channel)
        {
            string url = string.Empty;


            //用于记录支付平台的请求和响应
            string requestJson  = string.Empty;
            string responseJson = string.Empty;

            var recordBll    = new PayRequestRecordBLL(new Utility.BasicUserInfo());
            var recordEntity = new PayRequestRecordEntity()
            {
                ChannelID = channel.ChannelID,
                ClientID  = entity.AppClientID,
                UserID    = entity.AppUserID
            };

            #region 根据Channel类型创建支付订单
            try
            {
                switch (channel.PayType)
                {
                case 1:
                    recordEntity.Platform = 1;
                    #region 银联Wap支付
                    UnionPayChannel unionWapPaychannel = channel.ChannelParameters.DeserializeJSONTo <UnionPayChannel>();
                    PreOrderRequest Wapreq             = new PreOrderRequest()
                    {
                        BackUrl               = ConfigurationManager.AppSettings["UnionPayWapNotifyUrl"].Trim('?') + string.Format("?ChannelID={0}", channel.ChannelID),
                        FrontUrl              = string.IsNullOrEmpty(para.ReturnUrl) ? ConfigurationManager.AppSettings["UnionPayCallBackUrl"] : para.ReturnUrl,
                        MerchantID            = unionWapPaychannel.MerchantID,
                        SendTime              = DateTime.Now,
                        MerchantOrderCurrency = Currencys.RMB,
                        MerchantOrderDesc     = entity.AppOrderDesc,
                        MerchantOrderAmt      = entity.AppOrderAmount,
                        MerchantOrderID       = entity.OrderID.ToString(),
                        SendSeqID             = Guid.NewGuid().ToString("N"),
                        MerchantOrderTime     = entity.AppOrderTime
                    };
                    requestJson = Wapreq.ToJSON();
                    var unionWapResponse = JIT.Utility.Pay.UnionPay.Interface.Wap.WapGateway.PreOrder(unionWapPaychannel, Wapreq);
                    responseJson = unionWapResponse.ToJSON();
                    if (unionWapResponse.IsSuccess)
                    {
                        entity.PayUrl = unionWapResponse.RedirectURL;
                        entity.Status = 1;
                        bll.Update(entity);
                        url = unionWapResponse.RedirectURL;
                        Loggers.Debug(new DebugLogInfo()
                        {
                            Message = string.Format("银联Wap创建订单成功{0}【请求】:{1}{0}【响应】:{2}", Environment.NewLine, Wapreq.ToJSON(), unionWapResponse.ToJSON())
                        });
                    }
                    else
                    {
                        Loggers.Debug(new DebugLogInfo()
                        {
                            Message = string.Format("银联Wap创建订单失败{0}【请求】:{1}{0}【响应】:{2}", Environment.NewLine, Wapreq.ToJSON(), unionWapResponse.ToJSON())
                        });
                        response.ResultCode = 100;
                        response.Message    = unionWapResponse.Description;
                    }
                    #endregion
                    break;

                case 2:
                    recordEntity.Platform = 1;
                    #region 银联语音支付
                    UnionPayChannel unionIVRPaychannel = channel.ChannelParameters.DeserializeJSONTo <UnionPayChannel>();
                    JIT.Utility.Pay.UnionPay.Interface.IVR.Request.PreOrderRequest IVRreq = new Utility.Pay.UnionPay.Interface.IVR.Request.PreOrderRequest()
                    {
                        SendTime          = DateTime.Now,
                        SendSeqID         = Guid.NewGuid().ToString("N"),
                        FrontUrl          = string.IsNullOrEmpty(para.ReturnUrl) ? ConfigurationManager.AppSettings["UnionPayCallBackUrl"] : para.ReturnUrl,
                        BackUrl           = ConfigurationManager.AppSettings["UnionPayIVRNotifyUrl"].Trim('?') + string.Format("?ChannelID={0}", channel.ChannelID),
                        MerchantOrderDesc = entity.AppOrderDesc,
                        Mode                  = IVRModes.Callback,
                        TransTimeout          = entity.AppOrderTime,
                        MerchantOrderCurrency = Currencys.RMB,
                        MerchantOrderAmt      = entity.AppOrderAmount,
                        MerchantID            = unionIVRPaychannel.MerchantID,
                        MerchantOrderTime     = entity.AppOrderTime,
                        MerchantOrderID       = entity.OrderID.ToString(),
                        MobileNum             = entity.MobileNO
                    };
                    requestJson = IVRreq.ToJSON();
                    var IvrResponse = IVRGateway.PreOrder(unionIVRPaychannel, IVRreq);
                    responseJson = IvrResponse.ToJSON();
                    if (IvrResponse.IsSuccess)
                    {
                        entity.Status = 1;
                        bll.Update(entity);
                        Loggers.Debug(new DebugLogInfo()
                        {
                            Message = string.Format("银联IVR创建订单成功{0}【请求】:{1}{0}【响应】:{2}", Environment.NewLine, IVRreq.ToJSON(), IvrResponse.ToJSON())
                        });
                    }
                    else
                    {
                        Loggers.Debug(new DebugLogInfo()
                        {
                            Message = string.Format("银联IVR创建订单失败{0}【请求】:{1}{0}【响应】:{2}", Environment.NewLine, IVRreq.ToJSON(), IvrResponse.ToJSON())
                        });
                        response.ResultCode = 200;
                        response.Message    = IvrResponse.Description;
                    }
                    #endregion
                    break;

                case 3:
                    recordEntity.Platform = 2;
                    #region 阿里Wap支付
                    AliPayChannel         aliPayWapChannel = channel.ChannelParameters.DeserializeJSONTo <AliPayChannel>();
                    AliPayWapTokenRequest tokenRequest     = new AliPayWapTokenRequest(aliPayWapChannel)
                    {
                        CallBackUrl       = string.IsNullOrEmpty(para.ReturnUrl) ? ConfigurationManager.AppSettings["AliPayCallBackUrl"] : para.ReturnUrl,
                        NotifyUrl         = ConfigurationManager.AppSettings["AlipayWapNotify"].Trim('?') + string.Format("?ChannelID={0}", channel.ChannelID),
                        OutTradeNo        = entity.OrderID.ToString(),
                        Partner           = aliPayWapChannel.Partner,
                        SellerAccountName = aliPayWapChannel.SellerAccountName,
                        Subject           = entity.AppOrderDesc,
                        TotalFee          = Math.Round((Convert.ToDecimal(entity.AppOrderAmount) / 100), 2).ToString(),
                        ReqID             = Guid.NewGuid().ToString().Replace("-", "")
                    };
                    requestJson = tokenRequest.ToJSON();
                    var aliPayWapResponse = AliPayWapGeteway.GetQueryTradeResponse(tokenRequest, aliPayWapChannel);
                    responseJson = aliPayWapResponse.ToJSON();
                    if (aliPayWapResponse.IsSucess)
                    {
                        entity.PayUrl = aliPayWapResponse.RedirectURL;
                        entity.Status = 1;
                        bll.Update(entity);
                        url = aliPayWapResponse.RedirectURL;
                        Loggers.Debug(new DebugLogInfo()
                        {
                            Message = string.Format("AliPayWap创建订单成功{0}【请求】:{1}{0}【响应】:{2}", Environment.NewLine, tokenRequest.ToJSON(), aliPayWapResponse.ToJSON())
                        });
                    }
                    else
                    {
                        Loggers.Debug(new DebugLogInfo()
                        {
                            Message = string.Format("AliPayWap创建订单失败{0}【请求】:{1}{0}【响应】:{2}", Environment.NewLine, tokenRequest.ToJSON(), aliPayWapResponse.ToJSON())
                        });
                        response.ResultCode = 300;
                        response.Message    = aliPayWapResponse.Message;
                    }
                    #endregion
                    break;

                case 4:
                    recordEntity.Platform = 2;
                    #region 阿里OffLine支付
                    AliPayChannel aliPayChannel = channel.ChannelParameters.DeserializeJSONTo <AliPayChannel>();
                    //根据DynamicID判断是否预定单支付,DynamicID为空或者Null时调用OffLine预订单接口
                    if (string.IsNullOrWhiteSpace(para.DynamicID))
                    {
                        OfflineQRCodePreRequest qrRequest = new OfflineQRCodePreRequest(aliPayChannel)
                        {
                            OutTradeNo = entity.OrderID.ToString(),
                            NotifyUrl  = ConfigurationManager.AppSettings["AlipayOfflineNotify"].Trim('?') + string.Format("?ChannelID={0}", channel.ChannelID),
                            Subject    = entity.AppOrderDesc,
                            TotalFee   = Math.Round((Convert.ToDecimal(entity.AppOrderAmount) / 100), 2).ToString(),
                            //下面是测试数据,正式须更改
                            ExtendParams = new
                            {
                                MACHINE_ID  = "BJ_001", //?
                                AGENT_ID    = aliPayChannel.AgentID,
                                STORE_TYPE  = "0",      //?
                                STORE_ID    = "12314",  //?
                                TERMINAL_ID = "111",    //?
                                SHOP_ID     = "only"    //?
                            }.ToJSON()
                        };
                        requestJson = qrRequest.ToJSON();
                        var offlineQrResponse = AliPayOffLineGeteway.OfflineQRPay(qrRequest);
                        responseJson = offlineQrResponse.ToJSON();
                        if (offlineQrResponse.IsSucess)
                        {
                            entity.Status = 1;
                            entity.PayUrl = offlineQrResponse.PicUrl;
                            bll.Update(entity);
                            response.QrCodeUrl = offlineQrResponse.PicUrl;
                            Loggers.Debug(new DebugLogInfo()
                            {
                                Message = string.Format("AliPayOffline二维码支付创建订单成功{0}【请求】:{1}{0}【响应】:{2}", Environment.NewLine, qrRequest.ToJSON(), offlineQrResponse.ToJSON())
                            });
                        }
                        else
                        {
                            Loggers.Debug(new DebugLogInfo()
                            {
                                Message = string.Format("AliPayOffline二维码支付创建订单失败{0}【请求】:{1}{0}【响应】:{2}", Environment.NewLine, qrRequest.ToJSON(), offlineQrResponse.ToJSON())
                            });
                            response.ResultCode = 400;
                            response.Message    = offlineQrResponse.DetailErrorCode + ":" + offlineQrResponse.DetailErrorDes;
                        }
                    }
                    else
                    {
                        CreateAndPayRequest createAndPayrequest = new CreateAndPayRequest(aliPayChannel)
                        {
                            Subject       = entity.AppOrderDesc,
                            TotalFee      = Math.Round((Convert.ToDecimal(entity.AppOrderAmount) / 100), 2).ToString(),
                            NotifyUrl     = ConfigurationManager.AppSettings["AlipayOfflineNotify"].Trim('?') + string.Format("?ChannelID={0}", channel.ChannelID),
                            OutTradeNo    = entity.OrderID.ToString(),
                            DynamicIDType = para.DynamicIDType,
                            DynamicID     = para.DynamicID,
                        };
                        if (!string.IsNullOrEmpty(aliPayChannel.AgentID))
                        {
                            createAndPayrequest.ExtendParams = (new
                            {
                                AGENT_ID = aliPayChannel.AgentID,
                                MACHINE_ID = "BJ_001",
                                STORE_TYPE = "0",
                                STORE_ID = "BJ_ZZ_001",
                                TERMINAL_ID = "A80001",
                                SHOP_ID = "only"
                            }).ToJSON();
                        }
                        requestJson = createAndPayrequest.ToJSON();
                        var offlineCreateAndPayResponse = AliPayOffLineGeteway.OfflineCreateAndPay(createAndPayrequest);
                        responseJson = offlineCreateAndPayResponse.ToJSON();
                        if (offlineCreateAndPayResponse.IsSuccess)
                        {
                            entity.Status = 2;
                            bll.Update(entity);
                            Loggers.Debug(new DebugLogInfo()
                            {
                                Message = string.Format("AliPayOffline即支付创建订单成功{0}【请求】:{1}{0}【响应】:{2}", Environment.NewLine, createAndPayrequest.ToJSON(), offlineCreateAndPayResponse.ToJSON())
                            });
                        }
                        else if (offlineCreateAndPayResponse.ResultCode == ResultCodes.ORDER_SUCCESS_PAY_FAIL.ToString())
                        {
                            entity.Status = 1;
                            bll.Update(entity);
                            Loggers.Debug(new DebugLogInfo()
                            {
                                Message = string.Format("AliPayOffline即支付创建订单成功{0},支付失败【请求】:{1}{0}【响应】:{2}", Environment.NewLine, createAndPayrequest.ToJSON(), offlineCreateAndPayResponse.ToJSON())
                            });
                        }
                        else if (offlineCreateAndPayResponse.ResultCode == ResultCodes.ORDER_SUCCESS_PAY_INPROCESS.ToString())
                        {
                            entity.Status = 1;
                            bll.Update(entity);
                            Loggers.Debug(new DebugLogInfo()
                            {
                                Message = string.Format("AliPayOffline即支付创建订单成功{0},支付处理中【请求】:{1}{0}【响应】:{2}", Environment.NewLine, createAndPayrequest.ToJSON(), offlineCreateAndPayResponse.ToJSON())
                            });
                        }
                        else
                        {
                            Loggers.Debug(new DebugLogInfo()
                            {
                                Message = string.Format("AliPayOffline即支付创建订单失败{0}【请求】:{1}{0}【响应】:{2}", Environment.NewLine, createAndPayrequest.ToJSON(), offlineCreateAndPayResponse.ToJSON())
                            });
                            response.ResultCode = 400;
                            response.Message    = offlineCreateAndPayResponse.DetailErrorCode + ":" + offlineCreateAndPayResponse.DetailErrorDes;
                        }
                    }
                    #endregion
                    break;

                case 5:    //Native
                case 6:    //微信JS
                case 7:    //微信App
                    recordEntity.Platform = 3;
                    #region 微信Native支付,JS支付
                    //把channel里的参数传了过去
                    WeiXinPayHelper helper = new WeiXinPayHelper(channel.ChannelParameters.DeserializeJSONTo <WeiXinPayHelper.Channel>());
                    entity.PayUrl    = ConfigurationManager.AppSettings["WeiXinPrePay"];
                    entity.NotifyUrl = ConfigurationManager.AppSettings["WeiXinPayNotify"];
                    WeiXinPayHelper.PrePayResult result = null;

                    if (para.PaymentMode == 1)    //PaymentMode=1标示微信扫码支付进入
                    {
                        helper.channel.trade_type = "NATIVE";
                        channel.PayType           = 5; //走扫码回调返回参数
                    }

                    Loggers.Debug(new DebugLogInfo()
                    {
                        Message = "isSpPay:" + helper.channel.isSpPay
                    });

                    if (helper.channel.isSpPay == "1")     //isSpPay=1 服务商支付
                    {
                        result = helper.serPrePay(entity); //统一下单,服务商支付
                    }
                    else
                    {
                        result = helper.prePay(entity);    //统一下单,获取微信网页支付的预支付信息,app支付和js支付是一样的
                    }

                    Loggers.Debug(new DebugLogInfo()
                    {
                        Message = "微信支付_预支付返回结果:" + result.ToJSON()
                    });
                    requestJson  = helper.prePayRequest;
                    responseJson = helper.prePayResponse;
                    if (result.return_code == "SUCCESS" && result.result_code == "SUCCESS")
                    {
                        if (channel.PayType == 6)
                        {
                            response.WXPackage = helper.getJsParamater(result);
                        }
                        else if (channel.PayType == 7)    //后面传的参数和js支付的就不一样了
                        {
                            response.WXPackage = helper.getAppParamater(result);
                            response.OrderID   = entity.OrderID;
                        }
                        else    //Native
                        {
                            response.WXPackage = result.ToJSON();
                            response.QrCodeUrl = result.code_url;
                        }
                        Loggers.Debug(new DebugLogInfo()
                        {
                            Message = "WXPackage:" + response.WXPackage
                        });
                    }
                    else
                    {
                        response.ResultCode = 101;                    //支付失败
                        if (!string.IsNullOrEmpty(result.return_msg)) //不同错误,错误信息位置不同
                        {
                            response.Message = result.return_msg;
                        }
                        else
                        {
                            response.Message = result.err_code_des;
                        }
                    }

                    #endregion
                    break;

                case 8:    //旺财支付
                    return(string.Empty);

                case 9:    //新版支付宝扫码支付
                    #region
                    AliPayChannel     aliPayScanChannel = channel.ChannelParameters.DeserializeJSONTo <AliPayChannel>();
                    RequestScanEntity scRequest         = new RequestScanEntity(aliPayScanChannel);
                    scRequest.notify_url = "" + ConfigurationManager.AppSettings["AlipayOfflineNotify"];

                    RequstScanDetail scanDetail = new RequstScanDetail();
                    scanDetail.out_trade_no = "" + entity.OrderID;
                    scanDetail.total_amount = "" + Math.Round((Convert.ToDecimal(entity.AppOrderAmount) / 100), 2);
                    scanDetail.seller_id    = aliPayScanChannel.Partner;
                    scanDetail.subject      = entity.AppOrderDesc;

                    var scResponseJson = AliPayScanGeteway.GetResponseStr(scRequest, scanDetail.ToJSON(), aliPayScanChannel.RSA_PrivateKey);
                    var scResponse     = scResponseJson.DeserializeJSONTo <ResponsetScanEntity>();

                    if (scResponse.alipay_trade_precreate_response.code == "10000")
                    {
                        response.QrCodeUrl = scResponse.alipay_trade_precreate_response.qr_code;
                        Loggers.Debug(new DebugLogInfo()
                        {
                            Message = string.Format("aliPayScanChannel二维码支付创建订单成功{0}【请求】:{1}{0}【响应】:{2}", Environment.NewLine, requestJson, scResponseJson)
                        });
                    }
                    else
                    {
                        Loggers.Debug(new DebugLogInfo()
                        {
                            Message = string.Format("AliPayOffline二维码支付创建订单失败{0}【请求】:{1}{0}【响应】:{2}", Environment.NewLine, requestJson, scResponseJson)
                        });
                        response.ResultCode = 400;
                        response.Message    = scResponse.alipay_trade_precreate_response.code + ":" + scResponse.alipay_trade_precreate_response.msg;
                    }
                    #endregion
                    break;

                default:
                    break;
                }
                recordEntity.RequestJson  = requestJson;
                recordEntity.ResponseJson = responseJson;
                recordBll.Create(recordEntity);
            }
            catch (Exception ex)
            {
                recordEntity.RequestJson  = requestJson;
                recordEntity.ResponseJson = responseJson;
                recordBll.Create(recordEntity);
                throw ex;
            }
            #endregion
            return(url);
        }
Esempio n. 8
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;
            }
        }