Esempio n. 1
0
        public AlipayTradePrecreateResponse BuildNew(EAliPayApplication app, EStoreInfo store, EUserInfo AgentUI, string TotalAmt, bool needNotifyUrl = true, bool needControl = true)
        {
            string NotifyUrl = ConfigurationManager.AppSettings["Main_SiteUrl"] + "AliPay/PayNotify";

            _OrderNo = StringHelper.GenerateOrderNo();

            IAopClient aliyapClient = new DefaultAopClient("https://openapi.alipay.com/gateway.do", app.AppId,
                                                           app.Merchant_Private_Key, "json", "1.0", "RSA2", app.Merchant_Public_key, "GBK", false);

            AlipayTradePrecreateRequest request = new AlipayTradePrecreateRequest();
            AlipayTradePrecreateModel   model   = new AlipayTradePrecreateModel();

            model.SellerId = store.AliPayAccount;
            NLogHelper.InfoTxt("当面付OrderNo:" + _OrderNo);
            model.OutTradeNo   = _OrderNo;
            model.TotalAmount  = TotalAmt;
            model.Subject      = "#" + AgentUI.Name + " 收银台";
            model.Body         = app.AppName + "-商品";
            model.ExtendParams = new Aop.Api.Domain.ExtendParams();
            model.ExtendParams.SysServiceProviderId = app.AppId;
            if (needControl)
            {
                model.DisablePayChannels = "balance,moneyFund,creditCard,creditCardExpress,creditCardCartoon,debitCardExpress,point,bankPay";
            }

            request.SetBizModel(model);
            if (needNotifyUrl)
            {
                request.SetNotifyUrl(NotifyUrl);
            }

            AlipayTradePrecreateResponse response = aliyapClient.Execute(request, null, store.AliPayAuthToke);

            return(response);
        }
Esempio n. 2
0
        public AlipayTradePrecreateResponse BuildPartyPay(EAliPayApplication app, EStoreInfo store, EUserInfo AgentUI, string TotalAmt, bool needNotifyUrl = true)
        {
            string NotifyUrl = ConfigurationManager.AppSettings["Main_SiteUrl"] + "AliPay/PayNotify";

            _OrderNo = StringHelper.GenerateOrderNo();

            IAopClient aliyapClient = new DefaultAopClient("https://openapi.alipay.com/gateway.do", app.AppId,
                                                           app.Merchant_Private_Key, "json", "1.0", "RSA2", app.Merchant_Public_key, "GBK", false);

            AlipayTradePrecreateRequest request = new AlipayTradePrecreateRequest();
            AlipayTradePrecreateModel   model   = new AlipayTradePrecreateModel();

            model.SellerId                       = store.AliPayAccount;
            model.OutTradeNo                     = _OrderNo;
            model.TotalAmount                    = TotalAmt;
            model.Subject                        = "#" + AgentUI.Name + " 收银台";
            model.Body                           = app.AppName + "-商品";
            model.ExtendParams.HbFqNum           = "3";
            model.ExtendParams.HbFqSellerPercent = "0";


            request.SetBizModel(model);
            if (needNotifyUrl)
            {
                request.SetNotifyUrl(NotifyUrl);
            }

            AlipayTradePrecreateResponse response = aliyapClient.Execute(request, null, store.AliPayAuthToke);

            return(response);
        }
Esempio n. 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="qrUser"></param>
        /// <param name="store"></param>
        /// <param name="TotalAmount">订单总金额</param>
        /// <param name="orderType">订单类型:大额/小额</param>
        /// <param name="AliPayAccount">支付宝账户</param>
        /// <param name="orderNum">是否有订单,没有费率则为全局费率</param>
        /// <param name="ui">如果用户被禁用,传入</param>
        /// <param name="QRHugeTrans"></param>
        /// <returns></returns>
        public EOrderInfo InitOrder(EQRUser qrUser, EStoreInfo store, EUserStore userStore, float TotalAmount, OrderType orderType, string AliPayAccount = "", int orderNum = 0, EUserInfo ui = null, EQRHugeTrans QRHugeTrans = null)
        {
            EOrderInfo order = new EOrderInfo()
            {
                OrderNo          = _handler.OrderNo,
                OrderStatus      = BaseEnum.OrderStatus.WaitingAliPayNotify,
                QRUserId         = qrUser.ID,
                AgentName        = qrUser.UserName,
                AgentOpenId      = qrUser.OpenId,
                TotalAmount      = TotalAmount,
                Rate             = qrUser.Rate,
                RateAmount       = (float)Math.Round(TotalAmount * (qrUser.Rate / 100), 2, MidpointRounding.AwayFromZero),
                TransDate        = DateTime.Now,
                TransDateStr     = DateTime.Now.ToString("yyyy-MM-dd HH:mm"),
                SellerAliPayId   = store.AliPayAccount,
                SellerStoreId    = store.ID,
                SellerName       = store.Name,
                SellerChannel    = store.Channel,
                SellerRate       = store.Rate,
                SellerCommission = (float)Math.Round(TotalAmount * (userStore.OwnerRate) / 100, 2, MidpointRounding.ToEven),
                OrderType        = orderType,

                BuyerMarketRate     = qrUser.MarketRate,
                BuyerTransferAmount = (float)Math.Round(TotalAmount * (100 - qrUser.MarketRate) / 100, 2, MidpointRounding.AwayFromZero),
                BuyerAliPayAccount  = AliPayAccount,

                //ReceiveNo = StringHelper.GenerateReceiveNo(),
            };

            if (QRHugeTrans != null)
            {
                order.EQRHugeTransId = QRHugeTrans.ID;

                //大单用户手续费
                order.BuyerTransferAmount -= (float)RuleManager.PayRule().User_ServerFee_HQ;
            }
            else
            {
                //double FOFeeRate = RuleManager.PayRule().Agent_FOFeeRate;
                //小单用户手续费
                //if(order.TotalAmount>=199)
                //    order.BuyerTransferAmount -= (float)RuleManager.PayRule().User_ServerFee_Q;
                order.BuyerTransferAmount -= (float)RuleManager.PayRule().User_ServerFee_Q;

                ////首单费率
                //if(orderNum == 0 && (qrUser.MarketRate-qrUser.Rate)< FOFeeRate)
                //    order.RateAmount = (float)Math.Round(TotalAmount * ((qrUser.MarketRate-FOFeeRate) / 100), 2, MidpointRounding.ToEven);

                if (ui.UserStatus == UserStatus.JustRegister)
                {
                    order.RateAmount = (float)Math.Round(TotalAmount * (0.5 / 100), 2, MidpointRounding.ToEven);
                }
            }


            return(order);
        }
Esempio n. 4
0
 public void InitByStore(EStoreInfo si)
 {
     this.NeedVerification = false;
     this.InitCreate();
     this.InitModify();
     this.Level        = 1;
     this.OwnnerOpenId = si.OwnnerOpenId;
     this.Rate         = si.Rate;
     this.RecordStatus = RecordStatus.Normal;
     this.Channel      = si.Channel;
     this.Type         = QRType.StoreAuth;
 }
Esempio n. 5
0
        public void Pay()
        {
            AliPayManager payMag = new AliPayManager();
            AliPayResult  result;

            using (AliPayContent db = new AliPayContent())
            {
                EAliPayApplication app   = db.DBAliPayApp.Where(a => a.AppId == AppId).FirstOrDefault();
                EStoreInfo         store = db.DBStoreInfo.Where(a => a.ID == 119).FirstOrDefault();
                string             code  = payMag.PayTest(app, store, out result);

                Console.WriteLine("Result:" + code);
            }
        }
Esempio n. 6
0
 public void InitByStore(EStoreInfo si)
 {
     this.StoreId      = si.ID;
     this.OwnnerOpenId = si.OwnnerOpenId;
     this.Rate         = si.Rate;
     this.RecordStatus = RecordStatus.Normal;
     this.Channel      = si.Channel;
     this.StoreType    = StoreType.Small;
     this.StoreName    = si.Name;
     MaxLimitAmount    = si.MaxLimitAmount;
     MinLimitAmount    = si.MinLimitAmount;
     DayIncome         = si.DayIncome;
     RemainAmount      = 0;
 }
Esempio n. 7
0
        public string PayF2F(EAliPayApplication app, EUserInfo AgentUi, EStoreInfo storeInfo, float TotalAmount, out ResultEnum status)
        {
            string result    = "";
            string NotifyUrl = ConfigurationManager.AppSettings["Main_SiteUrl"] + "AliPay/PayNotify";

            /*
             * IAlipayTradeService serviceClient = F2FBiz.CreateClientInstance(AliPayConfig.serverUrl, AliPayConfig.appId, AliPayConfig.merchant_private_key, AliPayConfig.version,
             *             AliPayConfig.sign_type, AliPayConfig.alipay_public_key, AliPayConfig.charset);
             */
            IAlipayTradeService serviceClient = F2FBiz.CreateClientInstance(app.ServerUrl, app.AppId, app.Merchant_Private_Key, app.Version,
                                                                            app.SignType, app.Merchant_Public_key, app.Charset);

            _handler = new F2FPayHandler();

            AlipayTradePrecreateContentBuilder builder = _handler.BuildPrecreateContent(app, AgentUi, storeInfo.AliPayAccount, TotalAmount.ToString());

            AlipayF2FPrecreateResult precreateResult = serviceClient.tradePrecreate(builder, NotifyUrl);

            status = precreateResult.Status;

            switch (precreateResult.Status)
            {
            case ResultEnum.SUCCESS:
                result = _handler.CreateQR(precreateResult);
                result = _handler.DeQR(result);

                break;

            case ResultEnum.FAILED:
                result = precreateResult.response.Body;

                break;

            case ResultEnum.UNKNOWN:
                if (precreateResult.response == null)
                {
                    result = "配置或网络异常,请检查后重试";
                }
                else
                {
                    result = "系统异常,请更新外部订单后重新发起请求";
                }

                break;
            }
            return(result);
        }
Esempio n. 8
0
        public string PayF2FNew(EAliPayApplication app, EUserInfo AgentUi, EStoreInfo storeInfo, string TotalAmount, out AliPayResult status)
        {
            string result      = "";
            bool   NeedControl = false;

            /*
             * IAlipayTradeService serviceClient = F2FBiz.CreateClientInstance(AliPayConfig.serverUrl, AliPayConfig.appId, AliPayConfig.merchant_private_key, AliPayConfig.version,
             *             AliPayConfig.sign_type, AliPayConfig.alipay_public_key, AliPayConfig.charset);
             */
            IAopClient aliyapClient = new DefaultAopClient("https://openapi.alipay.com/gateway.do", app.AppId,
                                                           app.Merchant_Private_Key, "json", "1.0", "RSA2", app.Merchant_Public_key, "GBK", false);


            _handler = new F2FPayHandler();

            //if (AgentUi.UserRole == UserRole.Administrator)
            //    NeedControl = false;
            AlipayTradePrecreateResponse builder = _handler.BuildNew(app, storeInfo, AgentUi, TotalAmount, true, NeedControl);

            if (builder.Code == "10000")
            {
                result = _handler.CreateF2FQR(builder.QrCode);
                result = _handler.DeQR(result);
                status = AliPayResult.SUCCESS;
            }
            else
            {
                if (builder.Code == "20001")
                {
                    status = AliPayResult.AUTHERROR;
                    result = "授权错误!";
                }
                else
                {
                    result = "[Error Message]" + builder.Msg + "[Sub Msg]" + builder.SubMsg;
                    status = AliPayResult.FAILED;
                }
            }


            return(result);
        }
Esempio n. 9
0
        public NResult <EStoreInfo> CreateOrUpdate(EStoreInfo obj)
        {
            NResult <EStoreInfo> result = new NResult <EStoreInfo>();

            try
            {
                using (OOContent db = new OOContent())
                {
                    EStoreInfo updateObj = null;
                    if (obj.Id != 0)
                    {
                        updateObj = db.DBStoreInfo.Where(a => a.Id == obj.Id).FirstOrDefault();
                    }

                    //新增
                    if (updateObj == null)
                    {
                        db.DBStoreInfo.Add(obj);
                        db.SaveChanges();
                    }
                    //修改
                    else
                    {
                        updateObj.Name         = obj.Name;
                        updateObj.Description  = obj.Description;
                        updateObj.UserId       = obj.UserId;
                        updateObj.RecordStatus = obj.RecordStatus;

                        db.SaveChanges();
                    }
                    result.resultObj = obj;
                }
            }
            catch (Exception ex)
            {
                result.IsSuccess = false;
                result.ErrorMsg  = ex.Message;
                ErrorToDb(ex.Message);
            }
            return(result);
        }
Esempio n. 10
0
        public string PayTest(EAliPayApplication app, EStoreInfo store, out AliPayResult status)
        {
            IAopClient aliyapClient = new DefaultAopClient("https://openapi.alipay.com/gateway.do", app.AppId,
                                                           app.Merchant_Private_Key, "json", "1.0", "RSA2", app.Merchant_Public_key, "GBK", false);


            _handler = new F2FPayHandler();
            EUserInfo ui = new EUserInfo();

            ui.Name = "Check Store";
            AlipayTradePrecreateResponse builder = _handler.BuildNew(app, store, ui, "1.00");

            if (builder.Code == "10000")
            {
                status = AliPayResult.SUCCESS;
            }
            else
            {
                status = AliPayResult.FAILED;
            }
            return(builder.Code);
        }
Esempio n. 11
0
        public AlipayTradeCloseResponse CleanWaitOrder(EAliPayApplication app, EOrderInfo order, EStoreInfo store = null)
        {
            IAopClient aliyapClient = new DefaultAopClient("https://openapi.alipay.com/gateway.do", app.AppId,
                                                           app.Merchant_Private_Key, "json", "1.0", "RSA2", app.Merchant_Public_key, "GBK", false);

            AlipayTradeCloseRequest request = new AlipayTradeCloseRequest();
            AlipayTradeCloseModel   model   = new AlipayTradeCloseModel();

            model.OutTradeNo = order.OrderNo;
            request.SetBizModel(model);
            AlipayTradeCloseResponse response = null;

            if (store != null)
            {
                response = aliyapClient.Execute(request, null, store.AliPayAuthToke);
            }
            else
            {
                response = aliyapClient.Execute(request);
            }



            return(response);
        }
Esempio n. 12
0
        public AlipayTradeOrderSettleResponse DoSubAccount(EAliPayApplication app, EOrderInfo order, EStoreInfo store)
        {
            IAopClient aliyapClient = new DefaultAopClient("https://openapi.alipay.com/gateway.do", app.AppId,
                                                           app.Merchant_Private_Key, "json", "1.0", "RSA2", app.Merchant_Public_key, "GBK", false);


            AlipayTradeOrderSettleRequest request = new AlipayTradeOrderSettleRequest();

            //   string commission = (order.TotalAmount*(100-0.38)/100).ToString("0.00");
            string commission = (order.TotalAmount - order.SellerCommission).ToString("0.00");

            // string commission = "47.00";
            request.BizContent = "{" +
                                 "\"out_request_no\":\"" + StringHelper.GenerateSubAccountTransNo() + "\"," +
                                 "\"trade_no\":\"" + order.AliPayOrderNo + "\"," +
                                 "\"royalty_parameters\":[{" +
                                 "\"trans_out\":\"" + store.AliPayAccount + "\"," +
                                 "\"trans_in\":\"" + app.AccountForSub + "\"," +
                                 "\"amount\":" + commission + "," +
                                 "\"desc\":\"分账\"" +
                                 "}]" +
                                 //"\"operator_id\":" +
                                 "}";

            AlipayTradeOrderSettleResponse response = aliyapClient.Execute(request, null, store.AliPayAuthToke);

            return(response);
        }