/// <summary> /// 更新一条数据 /// </summary> public bool Update(ColoPay.Model.Pay.EnterprisePayFee model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Pay_EnterprisePayFee set "); strSql.Append("FeeRate=@FeeRate"); strSql.Append(" where EnterpriseID=@EnterpriseID and PayModeId=@PayModeId "); SqlParameter[] parameters = { new SqlParameter("@FeeRate", SqlDbType.Decimal, 9), new SqlParameter("@EnterpriseID", SqlDbType.Int, 4), new SqlParameter("@PayModeId", SqlDbType.Int, 4) }; parameters[0].Value = model.FeeRate; parameters[1].Value = model.EnterpriseID; parameters[2].Value = model.PayModeId; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(ColoPay.Model.Pay.EnterprisePayFee model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Pay_EnterprisePayFee("); strSql.Append("EnterpriseID,PayModeId,FeeRate)"); strSql.Append(" values ("); strSql.Append("@EnterpriseID,@PayModeId,@FeeRate)"); SqlParameter[] parameters = { new SqlParameter("@EnterpriseID", SqlDbType.Int, 4), new SqlParameter("@PayModeId", SqlDbType.Int, 4), new SqlParameter("@FeeRate", SqlDbType.Decimal, 9) }; parameters[0].Value = model.EnterpriseID; parameters[1].Value = model.PayModeId; parameters[2].Value = model.FeeRate; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public ColoPay.Model.Pay.EnterprisePayFee GetModel(int EnterpriseID, int PayModeId) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 EnterpriseID,PayModeId,FeeRate from Pay_EnterprisePayFee "); strSql.Append(" where EnterpriseID=@EnterpriseID and PayModeId=@PayModeId "); SqlParameter[] parameters = { new SqlParameter("@EnterpriseID", SqlDbType.Int, 4), new SqlParameter("@PayModeId", SqlDbType.Int, 4) }; parameters[0].Value = EnterpriseID; parameters[1].Value = PayModeId; ColoPay.Model.Pay.EnterprisePayFee model = new ColoPay.Model.Pay.EnterprisePayFee(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
/// <summary> /// 得到一个对象实体 /// </summary> public ColoPay.Model.Pay.EnterprisePayFee DataRowToModel(DataRow row) { ColoPay.Model.Pay.EnterprisePayFee model = new ColoPay.Model.Pay.EnterprisePayFee(); if (row != null) { if (row["EnterpriseID"] != null && row["EnterpriseID"].ToString() != "") { model.EnterpriseID = int.Parse(row["EnterpriseID"].ToString()); } if (row["PayModeId"] != null && row["PayModeId"].ToString() != "") { model.PayModeId = int.Parse(row["PayModeId"].ToString()); } if (row["FeeRate"] != null && row["FeeRate"].ToString() != "") { model.FeeRate = decimal.Parse(row["FeeRate"].ToString()); } } return(model); }
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)); }
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") }); } }