コード例 #1
0
        public override bool Process(PayChannelEntity pChannel, HttpContext pContext, out Entity.AppOrderEntity pEntity)
        {
            pContext.Response.ContentType = "text/plain";
            try
            {
                var orderId    = pContext.Request["outTradeNo"];
                var outTradeNo = pContext.Request.QueryString["outTradeNo"];
                Loggers.Debug(new DebugLogInfo()
                {
                    Message = "outTradeNo:" + outTradeNo
                });
                Loggers.Debug(new DebugLogInfo()
                {
                    Message = "ChannelID:104&OrderId:" + orderId
                });
                AppOrderBLL bll = new AppOrderBLL(new Utility.BasicUserInfo());
                //根据订单号从数据库中找到记录
                pEntity = bll.GetByID(orderId);


                #region 更新订单状态
                pEntity.Status       = 2;
                pEntity.ErrorMessage = "";
                bll.Update(pEntity);
                #endregion

                return(true);
            }
            catch (Exception ex)
            {
                pEntity = null;
                Loggers.Exception(new ExceptionLogInfo(ex));
                return(false);
            }
        }
コード例 #2
0
        public override bool Process(PayChannelEntity pChannel, HttpContext pContext, out Entity.AppOrderEntity pEntity)
        {
            pContext.Response.ContentType = "text/plain";
            try
            {
                //var WXChannel = pChannel.ChannelParameters.DeserializeJSONTo<WeiXinPayChannel>();

                byte[] buffer = new byte[pContext.Request.InputStream.Length];
                pContext.Request.InputStream.Read(buffer, 0, (int)pContext.Request.InputStream.Length);
                string str = Encoding.UTF8.GetString(buffer);
                Loggers.Debug(new DebugLogInfo()
                {
                    Message = "WeiXinNotify:" + str
                });                                                                   //微信回调返回的信息*****可用于本地测试
                //构建通知对象(反序列化)
                WeiXinPayHelper.NotifyResult result = new XmlSerializer(typeof(WeiXinPayHelper.NotifyResult)).Deserialize(new MemoryStream(Encoding.UTF8.GetBytes(str.Replace("xml>", "NotifyResult>")))) as WeiXinPayHelper.NotifyResult;

                Loggers.Debug(new DebugLogInfo()
                {
                    Message = "交易状态:" + result.result_code + Environment.NewLine + result.ToJSON()
                });                                                                                                                  //把反序列化的数据转换成json数据
                //根据通知结果更新订单
                AppOrderBLL bll = new AppOrderBLL(new Utility.BasicUserInfo());

                Loggers.Debug(new DebugLogInfo()
                {
                    Message = "WeiXinNotify_result.out_trade_no:" + result.out_trade_no
                });

                //根据订单号从数据库中找到记录
                pEntity = bll.GetByID(result.out_trade_no);

                if (result.result_code == "SUCCESS")
                {
                    #region 更新订单状态
                    pEntity.Status       = 2;
                    pEntity.ErrorMessage = "";
                    bll.Update(pEntity);
                    #endregion
                    pContext.Response.Write("<xml><return_code><![CDATA[SUCCESS]]></return_code></xml>");
                    return(true);
                }
                else
                {
                    pEntity.ErrorMessage = result.err_code_des;
                    bll.Update(pEntity);
                    pContext.Response.Write("<xml><return_code><![CDATA[FAIL]]></return_code></xml>");
                    return(false);
                }
            }
            catch (Exception ex)
            {
                pEntity = null;
                Loggers.Exception(new ExceptionLogInfo(ex));
                pContext.Response.Write("<xml><return_code><![CDATA[FAIL]]></return_code></xml>");
                return(false);
            }
        }
コード例 #3
0
ファイル: OrderQueryBLL.cs プロジェクト: radtek/crm
        /// <summary>
        /// 第三方支付通知失败处理
        /// </summary>
        public void SetNotificationFailed()
        {
            AppOrderBLL   appOrderBLL   = new AppOrderBLL(new BasicUserInfo());
            PayChannelBLL payChannelBLL = new PayChannelBLL(new BasicUserInfo());

            WeiXinOrderQuery orderQuery      = new WeiXinOrderQuery();
            PayChannelEntity payChannelEntiy = null;

            WeiXinOrderQuery.OrderQueryPara para = null;

            try
            {
                //获取当天未支付成功的订单
                AppOrderEntity[] appOrderList = appOrderBLL.GetUnpaidOrder();
                Loggers.Debug(new DebugLogInfo()
                {
                    Message = string.Format("找到{0}条通知失败或未支付成功数据", appOrderList.Count())
                });
                foreach (var order in appOrderList)
                {
                    //读取微信微信配置信息
                    payChannelEntiy = payChannelBLL.GetByID(order.PayChannelID);
                    if (payChannelEntiy != null)
                    {
                        if (payChannelEntiy.PayType == 6)//微信公众号支付
                        {
                            para = new WeiXinOrderQuery.OrderQueryPara();
                            para = payChannelEntiy.ChannelParameters.DeserializeJSONTo <WeiXinOrderQuery.OrderQueryPara>();
                            para.out_trade_no = order.OrderID.ToString();
                            WeiXinOrderQuery.OrderQueryInfo result = orderQuery.OrderQuery(para);

                            if (result.return_code == "SUCCESS" && result.result_code == "SUCCESS")
                            {
                                if (result.trade_state == "SUCCESS") //交易状态=支付成功
                                {
                                    order.Status = 2;                //付款成功
                                    appOrderBLL.Update(order);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Loggers.Exception(new ExceptionLogInfo(ex));
            }
        }
コード例 #4
0
ファイル: UnionPayIVRNotify.ashx.cs プロジェクト: radtek/crm
        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);
                }
            }
        }
コード例 #5
0
 /// <summary>
 /// 更新
 /// </summary>
 /// <param name="pEntity">实体实例</param>
 /// <param name="pTran">事务实例,可为null,如果为null,则不使用事务来更新</param>
 public void Update(PayChannelEntity pEntity, IDbTransaction pTran)
 {
     _currentDAO.Update(pEntity, pTran);
 }
コード例 #6
0
 /// <summary>
 /// 创建一个新实例
 /// </summary>
 /// <param name="pEntity">实体实例</param>
 public void Create(PayChannelEntity pEntity)
 {
     _currentDAO.Create(pEntity);
 }
コード例 #7
0
 /// <summary>
 /// 分页根据实体条件查询实体
 /// </summary>
 /// <param name="pQueryEntity">以实体形式传入的参数</param>
 /// <param name="pOrderBys">排序组合</param>
 /// <returns>符合条件的实体集</returns>
 public PagedQueryResult <PayChannelEntity> PagedQueryByEntity(PayChannelEntity pQueryEntity, OrderBy[] pOrderBys, int pPageSize, int pCurrentPageIndex)
 {
     return(_currentDAO.PagedQueryByEntity(pQueryEntity, pOrderBys, pPageSize, pCurrentPageIndex));
 }
コード例 #8
0
 /// <summary>
 /// 根据实体条件查询实体
 /// </summary>
 /// <param name="pQueryEntity">以实体形式传入的参数</param>
 /// <param name="pOrderBys">排序组合</param>
 /// <returns>符合条件的实体集</returns>
 public PayChannelEntity[] QueryByEntity(PayChannelEntity pQueryEntity, OrderBy[] pOrderBys)
 {
     return(_currentDAO.QueryByEntity(pQueryEntity, pOrderBys));
 }
コード例 #9
0
 /// <summary>
 /// 删除
 /// </summary>
 /// <param name="pEntity"></param>
 public void Delete(PayChannelEntity pEntity)
 {
     _currentDAO.Delete(pEntity);
 }
コード例 #10
0
 /// <summary>
 /// 更新
 /// </summary>
 /// <param name="pEntity">实体实例</param>
 public void Update(PayChannelEntity pEntity)
 {
     _currentDAO.Update(pEntity);
 }
コード例 #11
0
ファイル: TradeAPI.cs プロジェクト: radtek/crm
        /// <summary>
        /// 设置支付渠道
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        internal static object SetPayChannel(TradeRequest request)
        {
            var paras = request.GetParameter <SetPayChannel>();

            var payChannelResponsList = new PayChannelResponsList();
            var payChannelList        = new PayChannelResponse();

            payChannelResponsList.PayChannelIdList = new List <PayChannelResponse>();
            foreach (var para in paras.AddPayChannelData)
            {
                var payType          = para.PayType;
                var notifyUrl        = para.NotifyUrl;
                var payChannelBll    = new PayChannelBLL(new Utility.BasicUserInfo());
                var payChannelEntity = new PayChannelEntity();

                var channelId = para.ChannelId;

                if (payType == 0)
                {
                    throw new Exception("支付类型不能为空");
                }

                #region 银联支付
                if (payType == 1 || payType == 2)
                {
                    var unionPayData = para.UnionPayData;

                    if (unionPayData.MerchantID == null || string.IsNullOrEmpty(unionPayData.MerchantID))
                    {
                        throw new Exception("缺少参数【MerchantID】");
                    }
                    if (unionPayData.DecryptCertificateFilePath == null || string.IsNullOrEmpty(unionPayData.DecryptCertificateFilePath))
                    {
                        throw new Exception("缺少参数【DecryptCertificateFilePath】");
                    }
                    if (unionPayData.PacketEncryptKey == null || string.IsNullOrEmpty(unionPayData.PacketEncryptKey))
                    {
                        throw new Exception("缺少参数【PacketEncryptKey】");
                    }
                    if (unionPayData.CertificateFilePath == null || string.IsNullOrEmpty(unionPayData.CertificateFilePath))
                    {
                        throw new Exception("缺少参数【CertificateFilePath】");
                    }
                    if (unionPayData.CertificateFilePassword == null || string.IsNullOrEmpty(unionPayData.CertificateFilePassword))
                    {
                        throw new Exception("缺少参数【CertificateFilePassword】");
                    }

                    var unionpay = new UnionPayInfo();

                    #region 解密
                    var decFilePath = unionPayData.DecryptCertificateFilePath;

                    var decFileName = decFilePath.Substring(decFilePath.LastIndexOf('/') + 1, decFilePath.Length - decFilePath.LastIndexOf('/') - 1);

                    var uploadFilePath = HttpContext.Current.Server.MapPath("/PayCenter/");

                    FileSystem.CreateDirectoryIfNotExists(uploadFilePath);

                    SaveFiles(decFilePath, uploadFilePath + decFileName);
                    #endregion

                    #region 加密

                    var creFilePath = unionPayData.CertificateFilePath;

                    var creFileName = creFilePath.Substring(creFilePath.LastIndexOf('/') + 1, creFilePath.Length - creFilePath.LastIndexOf('/') - 1);

                    FileSystem.CreateDirectoryIfNotExists(uploadFilePath);

                    SaveFiles(creFilePath, uploadFilePath + creFileName);

                    #endregion


                    unionpay.MerchantID                 = unionPayData.MerchantID;
                    unionpay.PacketEncryptKey           = unionPayData.PacketEncryptKey;
                    unionpay.DecryptCertificateFilePath = uploadFilePath + decFileName;
                    unionpay.CertificateFilePath        = uploadFilePath + creFileName;
                    unionpay.CertificateFilePassword    = unionPayData.CertificateFilePassword;

                    payChannelEntity.ChannelParameters = unionpay.ToJSON();
                }
                #endregion

                #region 支付宝

                if (payType == 3)
                {
                    var wapData = para.WapData;

                    if (wapData.Partner == null || string.IsNullOrEmpty(wapData.Partner))
                    {
                        throw new Exception("缺少参数【Partner】");
                    }
                    if (wapData.SellerAccountName == null || string.IsNullOrEmpty(wapData.SellerAccountName))
                    {
                        throw new Exception("缺少参数【SellerAccountName】");
                    }
                    //if (wapData.MD5Key == null || string.IsNullOrEmpty(wapData.MD5Key))
                    //{
                    //    throw new Exception("缺少参数【MD5Key】");
                    //}
                    if (wapData.RSA_PublicKey == null || string.IsNullOrEmpty(wapData.RSA_PublicKey))
                    {
                        throw new Exception("缺少参数【RSA_PublicKey】");
                    }
                    if (wapData.RSA_PrivateKey == null || string.IsNullOrEmpty(wapData.RSA_PrivateKey))
                    {
                        throw new Exception("缺少参数【RSA_PrivateKey】");
                    }
                    payChannelEntity.ChannelParameters = wapData.ToJSON();
                }
                if (payType == 4)
                {
                    var wapData = para.WapData;

                    if (wapData.Partner == null || string.IsNullOrEmpty(wapData.Partner))
                    {
                        throw new Exception("缺少参数【Partner】");
                    }
                    if (wapData.MD5Key == null || string.IsNullOrEmpty(wapData.MD5Key))
                    {
                        throw new Exception("缺少参数【MD5Key】");
                    }

                    wapData.AgentID = "8582928j2";
                    payChannelEntity.ChannelParameters = wapData.ToJSON();
                }
                #endregion

                #region 微信
                if (payType == 5 || payType == 6)
                {
                    var wxPayData = para.WxPayData;
                    if (wxPayData.AppID == null || string.IsNullOrEmpty(wxPayData.AppID))
                    {
                        throw new Exception("缺少参数【AppID】");
                    }
                    //if (wxPayData.AppSecret == null || string.IsNullOrEmpty(wxPayData.AppSecret))
                    //{
                    //    throw new Exception("缺少参数【AppSecret】");
                    //}
                    //if (wxPayData.ParnterID == null || string.IsNullOrEmpty(wxPayData.ParnterID))
                    //{
                    //    throw new Exception("缺少参数【ParnterID】");
                    //}
                    //if (wxPayData.ParnterKey == null || string.IsNullOrEmpty(wxPayData.ParnterKey))
                    //{
                    //    throw new Exception("缺少参数【ParnterKey】");
                    //}
                    //if (wxPayData.PaySignKey == null || string.IsNullOrEmpty(wxPayData.PaySignKey))
                    //{
                    //    throw new Exception("缺少参数【PaySignKey】");
                    //}
                    if (wxPayData.Mch_ID == null || string.IsNullOrEmpty(wxPayData.Mch_ID))
                    {
                        throw new Exception("缺少参数【Mch_ID】");
                    }
                    if (wxPayData.SignKey == null || string.IsNullOrEmpty(wxPayData.SignKey))
                    {
                        throw new Exception("缺少参数【SignKey】");
                    }
                    if (wxPayData.Trade_Type == null || string.IsNullOrEmpty(wxPayData.Trade_Type))
                    {
                        throw new Exception("缺少参数【Trade_Type】");
                    }
                    payChannelEntity.ChannelParameters = wxPayData.ToJSON();
                }
                #endregion

                channelId = payChannelBll.GetMaxChannelId();
                payChannelEntity.ChannelID = channelId;
                payChannelEntity.IsTest    = false;
                payChannelEntity.NotifyUrl = notifyUrl;
                payChannelEntity.PayType   = payType;
                payChannelBll.Create(payChannelEntity);

                payChannelList.ChannelId = channelId;

                payChannelResponsList.PayChannelIdList.Add(payChannelList);
            }
            return(payChannelResponsList);
        }
コード例 #12
0
ファイル: TradeAPI.cs プロジェクト: radtek/crm
        /// <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);
        }
コード例 #13
0
ファイル: PaySuccessBaseNotify.cs プロジェクト: radtek/crm
 public abstract bool Process(PayChannelEntity pChannel, HttpContext pContext, out AppOrderEntity pEntity);
コード例 #14
0
ファイル: AliPayWapNotify.ashx.cs プロジェクト: radtek/crm
 public override bool Process(PayChannelEntity pChannel, HttpContext context, out Entity.AppOrderEntity entity)
 {
     context.Response.ContentType = "text/plain";
     try
     {
         var channel = pChannel.ChannelParameters.DeserializeJSONTo <AliPayChannel>();
         Dictionary <string, string> sPara = new Dictionary <string, string>();
         foreach (var item in context.Request.Form.AllKeys)
         {
             sPara[item] = context.Request.Form[item];
         }
         WapNotify notify = new WapNotify();
         notify.Load(sPara);
         var data = notify.GetNotifyData(channel);
         Loggers.Debug(new DebugLogInfo()
         {
             Message = "交易状态:" + data.TradeStatus
         });
         AppOrderBLL bll = new AppOrderBLL(new Utility.BasicUserInfo());
         entity = bll.GetByID(data.OutTradeNo);
         Loggers.Debug(new DebugLogInfo()
         {
             Message = "AppOrder:" + entity.ToJSON()
         });
         if (data.TradeStatus == TradeStatus.TRADE_FINISHED.ToString() || data.TradeStatus == TradeStatus.TRADE_SUCCESS.ToString())
         {
             #region 分润
             //PayChannelBLL pbll = new PayChannelBLL(new Utility.BasicUserInfo());
             //var channel = pbll.GetByID(entity.PayChannelID).ChannelParameters.DeserializeJSONTo<AliPayWapChannel>();
             //RoyaltyRequest royaltyrequest = new RoyaltyRequest()
             //{
             //    TradeNo = data.TradeNo,
             //    OutTradeNo = data.OutTradeNo,
             //    OutBillNo = Helper.GetDataRandom(),
             //    Partner = AliPayConfig.Partner,
             //    RoyaltyType = "10",
             //    RoyaltyParameters = "[email protected]^0.01^Test",
             //};
             //if (!string.IsNullOrEmpty(channel.GetRoyaltyStr()))
             //{
             //    royaltyrequest.RoyaltyParameters = channel.GetRoyaltyStr();
             //}
             //try
             //{
             //    var royalReaponse = AliPayWapGeteway.GetRoyaltyResponse(royaltyrequest);
             //    Loggers.Debug(new DebugLogInfo() { Message = royalReaponse.ToJSON() });
             //    if (royalReaponse.IsSuccess == "T")
             //    {
             //        Loggers.Debug(new DebugLogInfo() { Message = "分润成功" });
             //    }
             //    else
             //    {
             //        Loggers.Debug(new DebugLogInfo() { Message = "分润失败" });
             //    }
             //    context.Response.Write("successss");
             //    Loggers.Debug(new DebugLogInfo() { Message = "交易成功" });
             //}
             //catch (Exception ex)
             //{
             //    context.Response.Write("fail");
             //    Loggers.Exception(new ExceptionLogInfo(ex));
             //}
             #endregion
             #region 更新订单状态
             entity.Status       = 2;
             entity.ErrorMessage = "";
             bll.Update(entity);
             Loggers.Debug(new DebugLogInfo()
             {
                 Message = "更新订单状态成功!"
             });
             #endregion
             context.Response.Write("success");
             return(true);
         }
         else
         {
             entity.ErrorMessage = data.TradeStatus;
             bll.Update(entity);
             context.Response.Write("fail");
             return(false);
         }
     }
     catch (Exception ex)
     {
         Loggers.Exception(new ExceptionLogInfo(ex));
         entity = null;
         context.Response.Write("fail");
         return(false);
     }
 }
コード例 #15
0
        public override bool Process(PayChannelEntity pChannel, HttpContext pContext, out Entity.AppOrderEntity pEntity)
        {
            pContext.Response.ContentType = "text/plain";
            try
            {
                //组织支付平台回调时回传的参数集
                Dictionary <string, string> sPara = new Dictionary <string, string>();
                foreach (var item in pContext.Request.Form.AllKeys)
                {
                    sPara[item] = pContext.Request.Form[item];
                }
                //构建通知对象
                OfflineNotify notify = new OfflineNotify();
                notify.Load(sPara);
                Loggers.Debug(new DebugLogInfo()
                {
                    Message = "交易状态:" + notify.TradeStatus + Environment.NewLine + notify.ToJSON()
                });
                //根据通知结果更新订单
                AppOrderBLL bll = new AppOrderBLL(new Utility.BasicUserInfo());
                //根据订单号从数据库中找到记录
                pEntity = bll.GetByID(notify.OutTradeNo);

                Loggers.Debug(new DebugLogInfo()
                {
                    Message = "OutTradeNo:" + notify.OutTradeNo + ", TradeStatus:" + notify.TradeStatus + ", pEntity:" + pEntity.ToJSON()
                });

                if (notify.TradeStatus == TradeStatus.TRADE_FINISHED.ToString() || notify.TradeStatus == TradeStatus.TRADE_SUCCESS.ToString())
                {
                    #region 更新订单状态
                    pEntity.Status       = 2;
                    pEntity.ErrorMessage = "";
                    bll.Update(pEntity);
                    #endregion
                    pContext.Response.Write("success");

                    Loggers.Debug(new DebugLogInfo()
                    {
                        Message = "更新订单状态成功!"
                    });

                    return(true);
                }
                else
                {
                    pEntity.ErrorMessage = notify.TradeStatus;
                    bll.Update(pEntity);
                    pContext.Response.Write("fail");

                    Loggers.Debug(new DebugLogInfo()
                    {
                        Message = "更新订单状态失败:" + notify.TradeStatus
                    });

                    return(false);
                }
            }
            catch (Exception ex)
            {
                pContext.Response.Write("fail");
                pEntity = null;
                Loggers.Exception(new ExceptionLogInfo()
                {
                    ErrorMessage = ex.Message
                });
                return(false);
            }
        }