Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }