/// <summary>
        /// 全局数据库数据初始化
        /// </summary>
        /// <param name="srv"></param>
        public static void InitDbData(EduDbContext db)
        {
            GlobalSrv srv = new GlobalSrv(db);

            _AliPayApplication = srv.GetAliPayApplication();
            _CourseDateRange   = srv.GetCourseDateRangeList();
        }
Beispiel #2
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);
        }
Beispiel #3
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);
        }
Beispiel #4
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);
        }
Beispiel #5
0
        /// <summary>
        /// O2O转账
        /// </summary>
        /// <param name="initedTrans">已初始化的Transfer对象</param>
        /// <returns></returns>
        public ETransferAmount O2OTransferHandler(ETransferAmount initedTransfer, EAliPayApplication app, EAliPayApplication subApp)
        {
            try
            {
                AlipayFundTransToaccountTransferResponse res = null;

                string TransferId = "";

                res = DoTransferAmount(initedTransfer.TransferTarget,
                                       subApp,
                                       initedTransfer.TargetAccount,
                                       initedTransfer.TransferAmount.ToString("0.00"),
                                       PayTargetMode.AliPayAccount, out TransferId);
                initedTransfer.TransferId = TransferId;
                if (res.Code == "10000")
                {
                    initedTransfer.TransferStatus = TransferStatus.Success;
                }
                else
                {
                    initedTransfer.TransferStatus = TransferStatus.Failure;
                    initedTransfer.Log           += string.Format("[Transfer to {2}] SubCode:{0};Submsg:{1}", res.SubCode, res.SubMsg, initedTransfer.TransferTarget.ToString());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(initedTransfer);
        }
Beispiel #6
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);
        }
Beispiel #7
0
        // public bool

        /// <summary>
        /// 通过转账验证账户
        /// </summary>
        /// <returns></returns>
        public OutAPIResult TestAccountByTransfer(string AliPayAccount, EAliPayApplication app)
        {
            OutAPIResult result = new OutAPIResult();
            string       tId;

            try
            {
                AlipayFundTransToaccountTransferResponse res = DoTransferAmount(TransferTarget.User,
                                                                                app, AliPayAccount, "0.1",
                                                                                PayTargetMode.AliPayAccount,
                                                                                out tId, null, "账户校验");
                if (res.Code != "10000")
                {
                    result.IsSuccess = false;
                    result.ErrorMsg  = res.Msg + "--" + res.SubMsg;
                }

                return(result);
            }
            catch (Exception ex)
            {
                result.IsSuccess = false;
                result.ErrorMsg  = ex.Message;
            }

            return(result);
        }
Beispiel #8
0
        public AlipayFundTransToaccountTransferResponse TransferAmount(string toUserAliPayAccount, string userOpenId, double amount)
        {
            EAliPayApplication app          = StaticDataSrv.GetAliPayApplication();
            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);

            AlipayFundTransToaccountTransferRequest request = new AlipayFundTransToaccountTransferRequest();

            var TransferId = EduCodeGenerator.TransferOrderNo();

            AlipayFundTransToaccountTransferModel model = new AlipayFundTransToaccountTransferModel();

            model.Amount        = amount.ToString("0.00");
            model.OutBizNo      = TransferId;
            model.PayeeType     = "ALIPAY_LOGONID";
            model.PayeeAccount  = toUserAliPayAccount;
            model.PayerShowName = "云艺书院奖励金";
            request.SetBizModel(model);
            AlipayFundTransToaccountTransferResponse response = aliyapClient.Execute(request);



            return(response);

            //if (PayTargetMode == PayTargetMode.AliPayAccount)
            //    model.PayeeType = "ALIPAY_LOGONID";
            //else
            //    model.PayeeType = "ALIPAY_USERID";

            //model.PayeeAccount = toAliPayAccount;
            //if (!string.IsNullOrEmpty(ShowName))
            //{
            //    model.PayerShowName = ShowName;
            //}
            //else
            //{
            //    string profix = "";
            //    if (target == TransferTarget.ParentAgent)
            //        profix = "(上级佣金)";
            //    else if (target == TransferTarget.Agent)
            //        profix = "(代理费)";
            //    else if (target == TransferTarget.User)
            //        profix = "(打款)";
            //    else if (target == TransferTarget.L3Agent)
            //        profix = "(三级)";
            //    else if (target == TransferTarget.MidStore)
            //        profix = "(码商)";
            //    model.PayerShowName = profix + "服务费";
            //}

            //if (order != null)
            //    model.Remark = string.Format("#{0}-订单金额:{1}-订单ID:{2}", order.AgentName, order.TotalAmount, order.OrderNo);

            //request.SetBizModel(model);

            //AlipayFundTransToaccountTransferResponse response = aliyapClient.Execute(request);

            //return response;
        }
Beispiel #9
0
        public AlipayTradePrecreateContentBuilder BuildPrecreateContent(EAliPayApplication app, EUserInfo AgentUi, string sellerid, string TotalAmt)
        {
            //线上联调时,请输入真实的外部订单号。
            _OrderNo  = StringHelper.GenerateOrderNo();
            _SellerId = sellerid;

            AlipayTradePrecreateContentBuilder builder = new AlipayTradePrecreateContentBuilder();

            //收款账号
            builder.seller_id = _SellerId;

            //      builder.store_id = _SellerId;

            //订单编号
            builder.out_trade_no = OrderNo;
            //订单总金额
            builder.total_amount = TotalAmt;

            //参与优惠计算的金额
            //builder.discountable_amount = "";
            //不参与优惠计算的金额
            //builder.undiscountable_amount = "";
            //订单名称
            builder.subject = "#" + AgentUi.Name + "收银台";
            //自定义超时时间
            //  builder.timeout_express = "5m";
            //订单描述
            builder.body = "#" + app.AppName + "-商品";
            //门店编号,很重要的参数,可以用作之后的营销
            // builder.store_id = "test store id";
            //操作员编号,很重要的参数,可以用作之后的营销
            // builder.operator_id = "test";

            //传入商品信息详情
            //List<GoodsInfo> gList = new List<GoodsInfo>();
            //GoodsInfo goods = new GoodsInfo();
            //goods.goods_id = "爱钱吧商品";
            //goods.goods_name = "爱钱吧商品";
            //goods.price = TotalAmt;
            //goods.quantity = "1";
            //gList.Add(goods);
            //List<GoodsInfo> gList = AliPayManager.GetGoodsList(TotalAmt);
            //builder.goods_detail = gList;

            //系统商接入可以填此参数用作返佣
            //ExtendParams exParam = new ExtendParams();
            //exParam.sys_service_provider_id = app.AppId;

            //builder.extend_params = exParam;



            return(builder);
        }
Beispiel #10
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);
            }
        }
Beispiel #11
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);
        }
Beispiel #12
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);
        }
Beispiel #13
0
        public string PayF2F_ForR(EAliPayApplication app, string SellerId, string amount, ETool_QR qr, out ResultEnum status)
        {
            string result = "";

            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_ForR(app, "", amount);

            AlipayF2FPrecreateResult precreateResult = serviceClient.tradePrecreate(builder);

            status = precreateResult.Status;

            switch (precreateResult.Status)
            {
            case ResultEnum.SUCCESS:
                result = _handler.CreateQR_ForR(precreateResult, qr);

                break;

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

                break;

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

                break;
            }

            return(result);
        }
Beispiel #14
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);
        }
Beispiel #15
0
        /// <summary>
        /// 转账
        /// </summary>
        /// <param name="target">转帐方向</param>
        /// <param name="app">支付宝App</param>
        /// <param name="ui">转账对象</param>
        /// <param name="order">根据订单获取转账金额</param>
        /// <param name="accessToken"></param>
        /// <param name="GlobalConfig">获取是否微信转账配置</param>
        /// <returns></returns>
        public ETransferAmount TransferHandler(TransferTarget target, EAliPayApplication app, EAliPayApplication subApp, EUserInfo ui, ref EOrderInfo order, float AmountNotInOrder = 0, string accessToken = null, EGlobalConfig GlobalConfig = null)
        {
            string          TransferId = "";
            ETransferAmount transfer   = null;
            AlipayFundTransToaccountTransferResponse res = null;
            string        AliPayAccount  = null;
            float         TransferAmount = 0;
            PayTargetMode PayTargetMode  = PayTargetMode.AliPayAccount;

            switch (target)
            {
            case TransferTarget.Agent:
                AliPayAccount  = ui.AliPayAccount;
                TransferAmount = order.RateAmount;
                break;

            case TransferTarget.L3Agent:
                AliPayAccount  = ui.AliPayAccount;
                TransferAmount = order.L3CommissionAmount;
                break;

            case TransferTarget.ParentAgent:
                AliPayAccount  = ui.AliPayAccount;
                TransferAmount = order.ParentCommissionAmount;
                break;

            case TransferTarget.User:
                if (string.IsNullOrEmpty(order.BuyerAliPayAccount))
                {
                    AliPayAccount = order.BuyerAliPayId;
                    PayTargetMode = PayTargetMode.AliPayId;
                }
                else
                {
                    AliPayAccount = order.BuyerAliPayAccount;
                }

                TransferAmount = order.BuyerTransferAmount;
                break;

            case TransferTarget.MidStore:
                AliPayAccount  = ui.AliPayAccount;
                TransferAmount = AmountNotInOrder;
                break;
            }
            if (target == TransferTarget.User)
            {
                res = DoTransferAmount(target, subApp, AliPayAccount, TransferAmount.ToString("0.00"), PayTargetMode, out TransferId, order);
                //if (res.Code == "40004" && res.SubCode == "PAYER_BALANCE_NOT_ENOUGH")
                //{
                //    string tid;
                //    Random r = new Random();
                //    int num = r.Next(11890, 15588);
                //    AlipayFundTransToaccountTransferResponse response = DoTransferAmount(TransferTarget.Internal,app, "*****@*****.**", num.ToString("0.00"), PayTargetMode.AliPayAccount, out tid);
                //    if(response.Code == "10000")
                //    {
                //        res = DoTransferAmount(target, subApp, AliPayAccount, TransferAmount.ToString("0.00"), PayTargetMode, out TransferId, order);
                //    }
                //}
            }
            else
            {
                res = DoTransferAmount(target, app, AliPayAccount, TransferAmount.ToString("0.00"), PayTargetMode, out TransferId, order);
            }

            transfer = ETransferAmount.Init(target, TransferId, TransferAmount, AliPayAccount, order, ui);
            transfer.AliPayOrderId = res.OrderId;

            if (res.Code == "10000")
            {
                //转账记录开始
                transfer.TransferStatus = TransferStatus.Success;
            }
            else
            {
                transfer.TransferStatus = TransferStatus.Failure;
                transfer.Log           += string.Format("[Transfer to {2}] SubCode:{0};Submsg:{1}", res.SubCode, res.SubMsg, target.ToString());

                order.LogRemark  += "【转账错误】" + string.Format("[Transfer to {2}] SubCode:{0};Submsg:{1}", res.SubCode, res.SubMsg, target.ToString());
                order.OrderStatus = IQBCore.IQBPay.BaseEnum.OrderStatus.Exception;
            }
            return(transfer);
        }
Beispiel #16
0
        public AlipayFundTransToaccountTransferResponse DoTransferAmount(TransferTarget target,
                                                                         EAliPayApplication app,
                                                                         string toAliPayAccount,
                                                                         string Amount,
                                                                         PayTargetMode PayTargetMode,
                                                                         out string TransferId,
                                                                         EOrderInfo order = null,
                                                                         string ShowName  = 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);

            AlipayFundTransToaccountTransferRequest request = new AlipayFundTransToaccountTransferRequest();

            TransferId = StringHelper.GenerateTransferNo(target);
            AlipayFundTransToaccountTransferModel model = new AlipayFundTransToaccountTransferModel();

            model.Amount   = Amount;
            model.OutBizNo = TransferId;
            if (PayTargetMode == PayTargetMode.AliPayAccount)
            {
                model.PayeeType = "ALIPAY_LOGONID";
            }
            else
            {
                model.PayeeType = "ALIPAY_USERID";
            }

            model.PayeeAccount = toAliPayAccount;
            if (!string.IsNullOrEmpty(ShowName))
            {
                model.PayerShowName = ShowName;
            }
            else
            {
                string profix = "";
                if (target == TransferTarget.ParentAgent)
                {
                    profix = "(上级佣金)";
                }
                else if (target == TransferTarget.Agent)
                {
                    profix = "(代理费)";
                }
                else if (target == TransferTarget.User)
                {
                    profix = "(打款)";
                }
                else if (target == TransferTarget.L3Agent)
                {
                    profix = "(三级)";
                }
                else if (target == TransferTarget.MidStore)
                {
                    profix = "(码商)";
                }
                model.PayerShowName = profix + "服务费";
            }

            if (order != null)
            {
                model.Remark = string.Format("#{0}-订单金额:{1}-订单ID:{2}", order.AgentName, order.TotalAmount, order.OrderNo);
            }

            request.SetBizModel(model);

            AlipayFundTransToaccountTransferResponse response = aliyapClient.Execute(request);

            return(response);
        }