Exemplo n.º 1
0
        public HttpResponseMessage PayBankOrder([FromBody] PayInfo payinfo)
        {
            //YSWL.Common.DEncrypt.DEncrypt.GetMD5FromStr
            //验证是否数据安全性
            if (payinfo.amount < 0)
            {
                return(new HttpResponseMessage {
                    Content = new StringContent("amount is illegal", Encoding.GetEncoding("UTF-8"), "text/plain")
                });
            }
            if (String.IsNullOrWhiteSpace(payinfo.order_no))
            {
                return(new HttpResponseMessage {
                    Content = new StringContent("ordercode is illegal", Encoding.GetEncoding("UTF-8"), "text/plain")
                });
            }


            ColoPay.Model.Pay.Enterprise CurrEnterprise = bll.GetEnterpriseInfo(payinfo.appid, payinfo.secrit);
            if (CurrEnterprise == null)
            {
                return(new HttpResponseMessage {
                    Content = new StringContent("appid or secrit is illegal", Encoding.GetEncoding("UTF-8"), "text/plain")
                });
            }
            //判断订单是否存在
            ColoPay.Model.Pay.Order orderInfo = orderBll.GetModelEx(payinfo.order_no, CurrEnterprise.EnterpriseID);

            if (orderInfo == null)
            {
                //创建订单
                orderInfo              = new Model.Pay.Order();
                orderInfo.Agentd       = CurrEnterprise.AgentId;
                orderInfo.Amount       = payinfo.amount;
                orderInfo.AppId        = CurrEnterprise.AppId;
                orderInfo.AppReturnUrl = String.IsNullOrWhiteSpace(payinfo.return_url) ? CurrEnterprise.AppReturnUrl : payinfo.return_url;
                orderInfo.AppSecrit    = CurrEnterprise.AppSecrit;
                orderInfo.AppUrl       = HttpContext.Current.Request.Url.ToString();
                orderInfo.CreatedTime  = DateTime.Now;
                orderInfo.EnterOrder   = payinfo.order_no;
                orderInfo.EnterpriseID = CurrEnterprise.EnterpriseID;
                orderInfo.OrderCode    = "P" + CurrEnterprise.EnterpriseID + "_" + DateTime.Now.ToString("yyyyMMddHHmmssfff");
                //获取支付方式
                ColoPay.Model.Pay.PaymentTypes typeInfo = typeBll.GetPaymentInfo(payinfo.paytype);
                if (typeInfo == null)
                {
                    return(new HttpResponseMessage {
                        Content = new StringContent("paytype is illegal", Encoding.GetEncoding("UTF-8"), "text/plain")
                    });
                }
                //获取支付费率

                ColoPay.Model.Pay.EnterprisePayFee feeInfo = feeBll.GetModel(CurrEnterprise.EnterpriseID, typeInfo.ModeId);
                if (feeInfo == null)
                {
                    return(new HttpResponseMessage {
                        Content = new StringContent("paytype is illegal", Encoding.GetEncoding("UTF-8"), "text/plain")
                    });
                }
                orderInfo.FeeRate         = feeInfo.FeeRate;
                orderInfo.PaymentFee      = payinfo.amount * (feeInfo.FeeRate / 100);
                orderInfo.OrderAmount     = payinfo.amount - orderInfo.PaymentFee;
                orderInfo.PaymentGateway  = typeInfo.Gateway;
                orderInfo.PaymentStatus   = 0;
                orderInfo.AppNotifyUrl    = CurrEnterprise.AppReturnUrl;
                orderInfo.PaymentTypeName = typeInfo.Name;
                orderInfo.PayModeId       = typeInfo.ModeId;
                orderInfo.OrderInfo       = String.IsNullOrWhiteSpace(payinfo.remark) ? "" : payinfo.remark;
                orderInfo.OrderId         = orderBll.Add(orderInfo);
                if (orderInfo.OrderId == 0)//创建订单失败
                {
                    return(new HttpResponseMessage {
                        Content = new StringContent("payorder is error", Encoding.GetEncoding("UTF-8"), "text/plain")
                    });
                }
            }
            else //订单已经存在了
            {
                if (orderInfo.Amount != payinfo.amount)//金额不一样,说明订单不一样
                {
                    return(new HttpResponseMessage {
                        Content = new StringContent("order_no has exist", Encoding.GetEncoding("UTF-8"), "text/plain")
                    });
                }
                if (orderInfo.PaymentStatus == 2)
                {
                    return(new HttpResponseMessage {
                        Content = new StringContent("order has paid", Encoding.GetEncoding("UTF-8"), "text/plain")
                    });
                }
            }

            string resullt = ColoPay.WebApi.PayApi.DaDaBank.PayRequest(orderInfo.OrderCode, payinfo.amount, payinfo.bankcode, orderInfo.OrderInfo);

            YSWL.Json.JsonObject jsonObject = JsonConvert.Import <JsonObject>(resullt);
            if (jsonObject["bxstatus"].ToString() == "SUCCESS")
            {
                string pay_url           = jsonObject["pay_url"].ToString();
                HttpResponseMessage resp = new HttpResponseMessage(HttpStatusCode.Moved);
                resp.Headers.Location = new Uri(pay_url);
                return(resp);
            }
            else
            {
                return(new HttpResponseMessage {
                    Content = new StringContent(jsonObject["bxmsg"].ToString(), Encoding.GetEncoding("UTF-8"), "text/plain")
                });
            }
        }
Exemplo n.º 2
0
        public ResponseResult SubmitOrder([FromBody] PayInfo payinfo)
        {
            //YSWL.Common.DEncrypt.DEncrypt.GetMD5FromStr
            //验证是否数据安全性
            if (payinfo.amount < 0)
            {
                return(FailResult(ResponseCode.ParamError, "amount is illegal"));
            }
            if (String.IsNullOrWhiteSpace(payinfo.order_no))
            {
                return(FailResult(ResponseCode.ParamError, "ordercode is illegal"));
            }


            ColoPay.Model.Pay.Enterprise CurrEnterprise = bll.GetEnterpriseInfo(payinfo.appid, payinfo.secrit);
            if (CurrEnterprise == null)
            {
                return(FailResult(ResponseCode.ParamError, "appid or secrit is illegal"));
            }
            //判断订单是否存在
            ColoPay.Model.Pay.Order orderInfo = orderBll.GetModelEx(payinfo.order_no, CurrEnterprise.EnterpriseID);

            if (orderInfo == null)
            {
                //创建订单
                orderInfo              = new Model.Pay.Order();
                orderInfo.Agentd       = CurrEnterprise.AgentId;
                orderInfo.Amount       = payinfo.amount;
                orderInfo.AppId        = CurrEnterprise.AppId;
                orderInfo.AppReturnUrl = String.IsNullOrWhiteSpace(payinfo.return_url) ? CurrEnterprise.AppReturnUrl : payinfo.return_url;
                orderInfo.AppSecrit    = CurrEnterprise.AppSecrit;
                orderInfo.AppUrl       = HttpContext.Current.Request.Url.ToString();
                orderInfo.CreatedTime  = DateTime.Now;
                orderInfo.EnterOrder   = payinfo.order_no;
                orderInfo.EnterpriseID = CurrEnterprise.EnterpriseID;
                orderInfo.OrderCode    = DateTime.Now.ToString("yyyyMMddHHmmssfff") + CurrEnterprise.EnterpriseID;
                //获取支付方式
                ColoPay.Model.Pay.PaymentTypes typeInfo = typeBll.GetPaymentInfo(payinfo.paytype);
                if (typeInfo == null)
                {
                    return(FailResult(ResponseCode.ParamError, "paytype is illegal"));
                }
                //获取支付费率

                ColoPay.Model.Pay.EnterprisePayFee feeInfo = feeBll.GetModel(CurrEnterprise.EnterpriseID, typeInfo.ModeId);
                if (feeInfo == null)
                {
                    return(FailResult(ResponseCode.ParamError, "paytype is illegal"));
                }
                orderInfo.FeeRate         = feeInfo.FeeRate;
                orderInfo.PaymentFee      = payinfo.amount * (feeInfo.FeeRate / 100);
                orderInfo.OrderAmount     = payinfo.amount - orderInfo.PaymentFee;
                orderInfo.PaymentGateway  = typeInfo.Gateway;
                orderInfo.PaymentStatus   = 0;
                orderInfo.AppNotifyUrl    = CurrEnterprise.AppReturnUrl;
                orderInfo.PaymentTypeName = typeInfo.Name;
                orderInfo.PayModeId       = typeInfo.ModeId;
                orderInfo.OrderInfo       = String.IsNullOrWhiteSpace(payinfo.remark) ? "" : payinfo.remark;
                orderInfo.OrderId         = orderBll.Add(orderInfo);
                if (orderInfo.OrderId == 0)//创建订单失败
                {
                    return(FailResult(ResponseCode.ServiceUnavailable, "payorder is error"));
                }
            }
            else //订单已经存在了
            {
                if (orderInfo.Amount != payinfo.amount)//金额不一样,说明订单不一样
                {
                    return(FailResult(ResponseCode.OrderExists, "order_no has exist"));
                }
                if (orderInfo.PaymentStatus == 2)
                {
                    return(FailResult(ResponseCode.HasPaid, "order has paid"));
                }
            }
            string resullt = "";

            //BZ 支付金额必须要为整数,有点扯淡
            //开始支付

            if (!payinfo.istest)
            {
                //tuzh BZ_Pay 支付接口已失效
                // resullt = ColoPay.WebApi.PayApi.BZ_Pay.PayRequest(orderInfo.OrderCode, payinfo.amount, orderInfo.PaymentGateway, payinfo.get_code, orderInfo.OrderInfo);
                // 如果是网银或者快捷支付,走丰核支付
                YSWL.Log.LogHelper.AddInfoLog("支付网关", "PaymentGateway--->" + orderInfo.PaymentGateway);
                switch (orderInfo.PaymentGateway)
                {
                case "wangyin":
                case "kuaijie":
                    resullt = ColoPay.WebApi.PayApi.FengHe.PayRequest(orderInfo.OrderCode, payinfo.amount, orderInfo.PaymentGateway, orderInfo.OrderInfo);
                    break;

                case "onlinekj":
                    resullt = ColoPay.WebApi.PayApi.YiYuan.PayRequest(orderInfo.OrderCode, payinfo.amount, payinfo.bankcard, payinfo.moblie, payinfo.idcard, payinfo.realname, payinfo.remark);
                    break;

                case "wx":
                case "ali":
                case "aliwap":
                    resullt = ColoPay.WebApi.PayApi.MidoPay.PayRequest(orderInfo.OrderCode, payinfo.amount, orderInfo.PaymentGateway, payinfo.bankcard, payinfo.title, payinfo.product, orderInfo.Remark);
                    break;

                default:
                    resullt = ColoPay.WebApi.PayApi.MidoPay.PayRequest(orderInfo.OrderCode, payinfo.amount, orderInfo.PaymentGateway, payinfo.bankcard, payinfo.title, payinfo.product, orderInfo.Remark);
                    break;
                }
            }
            else //测试支付
            {
                bool isSuccess = orderBll.CompleteOrder(orderInfo);
                if (isSuccess)//成功之后需要回调商家回调地址
                {
                    try
                    {
                        orderInfo.PaymentStatus = 2;
                        ColoPay.BLL.Pay.Enterprise.Notify(orderInfo);
                    }
                    catch (Exception ex)
                    {
                        ColoPay.BLL.SysManage.LogHelp.AddErrorLog(String.Format("订单【{0}】BZPay支付回调通知失败:{1}", orderInfo.OrderCode, ex.Message), ex.StackTrace);
                    }
                }
            }

            return(SuccessResult(resullt));
        }
Exemplo n.º 3
0
        /// <summary>
        /// 验证请求是否合法
        /// </summary>
        protected override bool VerifySendPayment(System.Web.HttpContext context)
        {
            #region 验证请求是否合法
            string[] orderIds = YSWL.Payment.OrderProcessor.GetQueryString4OrderIds(context.Request);
            if (orderIds == null || orderIds.Length < 1)
            {
                return(false);
            }
            int orderId = YSWL.Common.Globals.SafeInt(orderIds[0], -1);
            if (orderId < -1)
            {
                return(false);
            }


            Model.Pay.Order orderInfo = _orderManage.GetModel(orderId);


            YSWL.Payment.Model.PaymentModeInfo paymentMode =
                YSWL.Payment.BLL.PaymentModeManage.GetPaymentModeById(orderInfo.PaymentTypeId);
            if (paymentMode == null)
            {
                Web.LogHelp.AddErrorLog(string.Format(MSG_ERRORLOG, orderId, -1),
                                        "非法操作订单", "Shop >> SendPaymentHandler >> Verification >> PaymentModeInfo Is NULL");
                context.Response.Redirect("/");
                return(false);
            }
            #endregion

            string basePath = "/";
            string u        = context.Request.ServerVariables["HTTP_USER_AGENT"];

            string area = context.Request.QueryString["Area"];
            if (!string.IsNullOrWhiteSpace(area))
            {
                basePath = string.Format("/{0}/", area);
            }
            //向网关写入请求发起源的Area
#pragma warning disable CS0612 // “SendPaymentHandlerBase<Order>.GatewayDatas”已过时
            this.GatewayDatas.Add(area);
#pragma warning restore CS0612 // “SendPaymentHandlerBase<Order>.GatewayDatas”已过时

            #region 支付宝银联

            if (paymentMode.Gateway == "alipaybank")
            {
                /**
                 * 关于银行编码:
                 * 如: 招商银行【CMB】、中国建设银行【CCB】、中国工商银行【ICBCB2C】
                 * 注意:优先使用B2C通道
                 * 混合渠道: https://doc.open.alipay.com/doc2/detail.htm?spm=0.0.0.0.Nz80L8&treeId=63&articleId=103763&docType=1
                 * 纯借记卡渠道: https://doc.open.alipay.com/doc2/detail.htm?spm=0.0.0.0.1NpxKf&treeId=63&articleId=103764&docType=1
                 **/

                string bankCode = context.Request.QueryString["BankCode"];
                if (!string.IsNullOrWhiteSpace(bankCode))
                {
                    //向网关写入用户选择的银行编码
#pragma warning disable CS0612 // “SendPaymentHandlerBase<Order>.GatewayDatas”已过时
                    this.GatewayDatas.Add(bankCode);
#pragma warning restore CS0612 // “SendPaymentHandlerBase<Order>.GatewayDatas”已过时
                }
            }

            #endregion

            //微信支付 向网关写入 APPID OPENID
            //if (paymentMode.Gateway.StartsWith("wechat"))
            //{
            //    string action = context.Request.QueryString["action"];
            //    //微信支付电脑端定向到
            //    if (action != "qr" && !u.ToLower().Contains("android") && !u.ToLower().Contains("mobile"))
            //    {
            //        context.Response.Redirect(MvcApplication.GetCurrentRoutePath(AreaRoute.Shop) + "PayWeChat/Pay/"+ orderId);
            //        return false;
            //    }

            //    //微信支付app端定向
            //    if (string.IsNullOrWhiteSpace(action) && u.ToLower().Contains("ys56"))
            //    {
            //        context.Response.Redirect($"/pay/certification{orderId}/{area}?action=app");
            //        return false;
            //    }

            //    string weChatAppId = YSWL.WeChat.BLL.Core.Config.GetValueByCache("WeChat_AppId", -1, "AA");
            //    if (string.IsNullOrWhiteSpace(weChatAppId))
            //    {
            //        context.Response.Clear();
            //        context.Response.Write("NO WECHAT_APPID > WECHAT APPID IS NULL!");
            //        return false;
            //    }
            //    this.GatewayDatas.Add(weChatAppId);

            //    if (string.IsNullOrWhiteSpace(action) || action == "show")
            //    {
            //        #region 获取微信用户OpenId
            //        //获取微信用户OpenId
            //        string weChatOpenId = YSWL.WeChat.BLL.Core.Config.GetValueByCache("WeChat_OpenId", -1, "AA");
            //        string weChatAppSercet = YSWL.WeChat.BLL.Core.Config.GetValueByCache("WeChat_AppSercet", -1, "AA");
            //        if (string.IsNullOrWhiteSpace(weChatOpenId) || string.IsNullOrWhiteSpace(weChatAppSercet))
            //        {
            //            context.Response.Clear();
            //            context.Response.Write("NO WECHATINFO > WECHAT WECHAT_OPENID OR WECHAT_APPSERCET IS NULL!");
            //            return false;
            //        }
            //        string authorizeCode = context.Request.QueryString["code"];
            //        if (string.IsNullOrWhiteSpace(authorizeCode))
            //        {
            //            string authorizeUrl =
            //               string.Format("https://open.weixin.qq.com/connect/oauth2/authorize?appid={0}&redirect_uri={1}&response_type=code&scope=snsapi_base&state={2}#wechat_redirect"
            //               , weChatAppId, Common.Globals.UrlEncode(context.Request.Url.ToString()), "YS56BEN");
            //            context.Response.Redirect(authorizeUrl);
            //            return false;
            //        }

            //        string userOpenId = YSWL.WeChat.BLL.Core.Utils.GetUserOpenId(weChatAppId, weChatAppSercet, authorizeCode);
            //        if (string.IsNullOrWhiteSpace(userOpenId))
            //        {
            //            context.Response.Clear();
            //            context.Response.Write("NO USEROPENID > WECHAT USEROPENID IS NULL!");
            //            return false;
            //        }
            //        this.GatewayDatas.Add(userOpenId);
            //        #endregion
            //    }
            //}

            if (u.ToLower().Contains("android") || u.ToLower().Contains("mobile")) //手机访问
            {
                if (!paymentMode.DrivePath.Contains("|2|"))                        //不能手机支付
                {
                    context.Session[KEY_ORDERID] = orderInfo.OrderId.ToString();
                    context.Response.Redirect("/m/PayResult/MFail");
                    return(false);
                }
            }
            else//电脑访问
            {
                if (!paymentMode.DrivePath.Contains("|1|")) //不能电脑支付
                {
                    context.Session[KEY_ORDERID] = orderInfo.OrderId.ToString();
                    context.Response.Redirect(MvcApplication.GetCurrentRoutePath(AreaRoute.Shop) + "PayResult/MFail");
                    return(false);
                }
            }
            return(true);
        }