Esempio n. 1
0
        public override bool TradePrecreate(MyOrder order)
        {
            IAlipayTradeService serviceClient = F2FBiz.CreateClientInstance(AliPayConfig.serverUrl, AliPayConfig.appId, AliPayConfig.merchant_private_key, AliPayConfig.version,
                                                                            AliPayConfig.sign_type, AliPayConfig.alipay_public_key, AliPayConfig.charset);

            AlipayTradePrecreateContentBuilder builder = BuildPrecreateContent(order);
            string out_trade_no = builder.out_trade_no;
            AlipayF2FPrecreateResult precreateResult = serviceClient.tradePrecreate(builder, AliPayConfig.notifyUrl);

            switch (precreateResult.Status)
            {
            case ResultEnum.SUCCESS:
                DoWaitProcess(precreateResult);
                return(true);

            case ResultEnum.FAILED:
                precreateMessage = precreateResult.response.Body;
                return(false);

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

            default:
                precreateMessage = "未定义的结果";
                return(false);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 条码支付操作
        /// </summary>
        /// <param name="posOrder"></param>
        /// <returns></returns>
        public Result <AlipayF2FPayResult> AlipayDsPosOrder(DBDsPosOrder posOrder)
        {
            Result <AlipayF2FPayResult> resultMod     = new Result <AlipayF2FPayResult>();
            IAlipayTradeService         serviceClient = F2FBiz.CreateClientInstance(Config.serverUrl, Config.appId, Config.merchant_private_key, Config.version,
                                                                                    Config.sign_type, Config.alipay_public_key, Config.charset);

            AlipayF2FPayResult payResult = serviceClient.tradePay(BuildPayContent(posOrder));

            switch (payResult.Status)
            {
            case ResultEnum.SUCCESS:
                DoSuccessProcess(payResult, ref resultMod);
                break;

            case ResultEnum.FAILED:
                DoFailedProcess(payResult, ref resultMod);
                break;

            case ResultEnum.UNKNOWN:
                resultMod.Status  = false;
                resultMod.Message = "网络异常,请检查网络配置后,更换外部订单号重试";
                resultMod.Data    = payResult;
                break;
            }

            return(resultMod);
            //Response.Redirect("result.aspx?Text=" + result);
        }
Esempio n. 3
0
        public Result QueryByOrderNo(string account, string orderNo)
        {
            Result result = new Result();

            try
            {
                result.IsOK        = true;
                result.StateCodeID = 0;
                IAlipayTradeService  serviceClient = F2FBiz.CreateClientInstance(Config.serverUrl, Config.appId, Config.merchant_private_key, Config.version, Config.sign_type, Config.alipay_public_key, Config.charset);
                AlipayF2FQueryResult queryResult   = serviceClient.tradeQuery(orderNo);
                if (queryResult != null)
                {
                    LogHelper.WriteLog(GetType()).Info(queryResult.response.OutTradeNo);
                    switch (queryResult.Status)
                    {
                    case ResultEnum.SUCCESS:
                    {
                        result = Common.Common.UpdateOrderTB(account, orderNo);
                        if (!result.IsOK)
                        {
                            return(result);
                        }
                        result.StateCodeID = 1;
                        return(result);
                    }

                    case ResultEnum.FAILED:
                    {
                        result.IsOK        = true;
                        result.Description = "未付款";
                        return(result);
                    }

                    case ResultEnum.UNKNOWN:
                        if (queryResult.response == null)
                        {
                            //result = "网络异常,请检查网络配置";
                            result.IsOK        = false;
                            result.Description = "配置或网络异常,请检查";
                            return(result);
                        }
                        else
                        {
                            result.IsOK        = false;
                            result.Description = "系统异常,请重试";
                            return(result);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(GetType()).Info(ex.StackTrace);
                result.IsOK        = false;
                result.Description = ex.Message;
            }
            return(result);
        }
Esempio n. 4
0
        public static IAlipayTradeService CreateServiceClient()
        {
            var serverUrl            = MDMSubList.GetOneName("支付宝接口", "AplipayGetWay");
            var appId                = MDMSubList.GetOneName("支付宝接口", "AppID");
            var merchant_private_key = MDMSubList.GetOneName("支付宝接口", "MerchantPrivateKey");
            var sign_type            = MDMSubList.GetOneName("支付宝接口", "SignType");
            var alipay_public_key    = MDMSubList.GetOneName("支付宝接口", "AlipayPublicKey");

            return(F2FBiz.CreateClientInstance(serverUrl, appId, merchant_private_key, "1.0",
                                               sign_type, alipay_public_key, "utf-8"));
        }
Esempio n. 5
0
        /// <summary>
        /// 预下单
        /// </summary>
        /// <returns></returns>
        public Result PreCreate(string account, string fileCoverId)
        {
            Result result = new Result();

            try
            {
                IAlipayTradeService serviceClient          = F2FBiz.CreateClientInstance(Config.serverUrl, Config.appId, Config.merchant_private_key, Config.version, Config.sign_type, Config.alipay_public_key, Config.charset);
                AlipayTradePrecreateContentBuilder builder = Common.Common.BuildPrecreateContent(account, fileCoverId);
                string out_trade_no = builder.out_trade_no;
                AlipayF2FPrecreateResult precreateResult = serviceClient.tradePrecreate(builder);

                switch (precreateResult.Status)
                {
                case ResultEnum.SUCCESS:
                    result.IsOK = true;
                    result      = Common.Common.RecordPreRenewal(account, fileCoverId, out_trade_no);
                    break;

                case ResultEnum.FAILED:
                    result.Description = precreateResult.response.Body;
                    result.IsOK        = false;
                    break;

                case ResultEnum.UNKNOWN:

                    if (precreateResult.response == null)
                    {
                        result.Description = "配置或网络异常,请检查后重试";
                    }
                    else
                    {
                        result.Description = precreateResult.response.Body;    // "系统异常,请更新外部订单后重新发起请求";
                    }
                    result.IsOK = false;
                    break;
                }
                if (!result.IsOK)
                {
                    return(result);
                }
                result.ExtData     = precreateResult.response.QrCode;
                result.Description = "预下单成功";
                //  result.SucceedDescription = out_trade_no;
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(GetType()).Info(ex.StackTrace);
                result.IsOK        = false;
                result.Description = ex.Message;
            }
            return(result);
        }
Esempio n. 6
0
 /// <summary>
 /// 构造方法
 /// </summary>
 /// <param name="configM">支付宝配置对象</param>
 public F2FPayManager(AlipayConfigmModel configM)
 {
     _config        = configM;
     _serviceClient = F2FBiz.CreateClientInstance(
         _config.ServerURL,
         _config.AppId,
         _config.MerchantPrivateKey,
         _config.Version,
         _config.SignType,
         _config.PublicKey,
         _config.CharSet
         );
 }
Esempio n. 7
0
        /// <summary>
        /// 申请退款
        /// </summary>
        /// <param name="out_trade_no">订单编号</param>
        /// <param name="total_fee">订单总金额(单位:元)</param>
        /// <param name="refund_fee">退款金额(单位:元)</param>
        /// <returns></returns>
        public static bool Run(string out_trade_no, string total_fee)
        {
            IAlipayTradeService serviceClient = F2FBiz.CreateClientInstance(
                F2FPayConfig.serverUrl,
                F2FPayConfig.appId,
                F2FPayConfig.merchant_private_key,
                F2FPayConfig.version,
                F2FPayConfig.sign_type,
                F2FPayConfig.alipay_public_key,
                F2FPayConfig.charset);
            var out_request_no = System.DateTime.Now.ToString("yyyyMMddHHmmss") + "0000" + (new Random()).Next(1, 10000).ToString();
            AlipayTradeRefundContentBuilder builder = new AlipayTradeRefundContentBuilder();

            //支付宝交易号与商户网站订单号不能同时为空
            builder.out_trade_no = out_trade_no.Trim();
            //退款请求单号保持唯一性。
            builder.out_request_no = out_request_no;
            //退款金额
            builder.refund_amount = total_fee.Trim();
            builder.refund_reason = "refund reason";
            AlipayF2FRefundResult refundResult = serviceClient.tradeRefund(builder);
            bool   isRefund = false;
            string result   = "";

            //请在这里加上商户的业务逻辑程序代码
            //——请根据您的业务逻辑来编写程序(以下代码仅作参考)——
            switch (refundResult.Status)
            {
            case ResultEnum.SUCCESS:
                isRefund = true;
                result   = "退款成功";
                break;

            case ResultEnum.FAILED:
                result = "退款失败," + refundResult.response.SubMsg;
                break;

            case ResultEnum.UNKNOWN:
                if (refundResult.response == null)
                {
                    result = "退款失败,配置或网络异常,请检查";
                }
                else
                {
                    result = "退款失败,系统异常,请走人工退款流程";
                }
                break;
            }
            return(isRefund);
        }
Esempio n. 8
0
        public static IAlipayTradeService GetDefaultF2FClient(string companyId)
        {
            AliPayApiConfig config = AliPayApiConfigServices.QueryAliPayConfig(companyId);

            if (config == null)
            {
                throw new MyException("获取支付宝配置失败");
            }

            string signType = config.AliPaySignType == 0 ? "RSA" : "RSA2";

            return(F2FBiz.CreateClientInstance(AliPayParam.serverUrl, config.AppId, config.PrivateKey, AliPayParam.version,
                                               signType, config.PublicKey, "utf-8"));
        }
Esempio n. 9
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. 10
0
        public Result CancelPreOrder(string account, string orderNo)
        {
            Result result = new Result();

            try
            {
                result.IsOK = true;

                IAlipayTradeService  serviceClient = F2FBiz.CreateClientInstance(Config.serverUrl, Config.appId, Config.merchant_private_key, Config.version, Config.sign_type, Config.alipay_public_key, Config.charset);
                AlipayF2FQueryResult queryResult   = serviceClient.tradeQuery(orderNo);
                if (queryResult != null)
                {
                    if (queryResult.Status == ResultEnum.SUCCESS)
                    {
                        result = Common.Common.UpdateOrderTB(account, orderNo);
                        if (!result.IsOK)
                        {
                            return(result);
                        }
                        result.Description = "用户已付款";
                        result.StateCodeID = 0;
                    }
                    else
                    {
                        //防止扫码之后退出续期
                        AlipayTradeCancelResponse cancelResult = serviceClient.tradeCancelResponse(orderNo);
                        if (cancelResult.Action == "close")
                        {
                            result = Common.Common.DelectOrderTB(account, orderNo);
                            if (!result.IsOK)
                            {
                                return(result);
                            }
                            result.Description = "取消订单成功";
                            result.StateCodeID = 1;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(GetType()).Info(ex.StackTrace);
                result.IsOK        = false;
                result.Description = ex.Message;
            }
            return(result);
        }
Esempio n. 11
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);
        }
Esempio n. 12
0
        public Result <AlipayF2FRefundResult> AlipayRefundDsPosOrder(CBDsPosReturnOrder returnOrder)
        {
            Result <AlipayF2FRefundResult> result = new Result <AlipayF2FRefundResult>();

            IAlipayTradeService serviceClient = F2FBiz.CreateClientInstance(Config.serverUrl, Config.appId, Config.merchant_private_key, Config.version,
                                                                            Config.sign_type, Config.alipay_public_key, Config.charset);

            AlipayTradeRefundContentBuilder builder = BuildContent(returnOrder);


            AlipayF2FRefundResult refundResult = serviceClient.tradeRefund(builder);

            //请在这里加上商户的业务逻辑程序代码
            //——请根据您的业务逻辑来编写程序(以下代码仅作参考)——
            switch (refundResult.Status)
            {
            case ResultEnum.SUCCESS:
                DoSuccessProcess(refundResult, ref result);
                break;

            case ResultEnum.FAILED:
                DoFailedProcess(refundResult, ref result);
                break;

            case ResultEnum.UNKNOWN:
                if (refundResult.response == null)
                {
                    result.Message = "配置或网络异常,请检查";
                    //result = "配置或网络异常,请检查";
                }
                else
                {
                    result.Message = "系统异常,请走人工退款流程";
                    //result = "系统异常,请走人工退款流程";
                }
                result.Data   = refundResult;
                result.Status = false;
                break;
            }
            return(result);
        }
Esempio n. 13
0
        public Result <AlipayF2FQueryResult> GetAliDsPosOrderQuery(string out_trade_no)
        {
            Result <AlipayF2FQueryResult> result = new Result <AlipayF2FQueryResult>();

            IAlipayTradeService serviceClient = F2FBiz.CreateClientInstance(Config.serverUrl, Config.appId, Config.merchant_private_key, Config.version,
                                                                            Config.sign_type, Config.alipay_public_key, Config.charset);

            AlipayF2FQueryResult queryResult = serviceClient.tradeQuery(out_trade_no);

            //请在这里加上商户的业务逻辑程序代码
            //——请根据您的业务逻辑来编写程序(以下代码仅作参考)——
            switch (queryResult.Status)
            {
            case ResultEnum.SUCCESS:
                DoSuccessProcess(queryResult, ref result);
                break;

            case ResultEnum.FAILED:
                DoFailedProcess(queryResult, ref result);
                break;

            case ResultEnum.UNKNOWN:
                result.Status = false;
                if (queryResult.response == null)
                {
                    //result = "网络异常,请检查网络配置";
                    //result = "配置或网络异常,请检查";
                    result.Message = "配置或网络异常,请检查";
                }
                else
                {
                    //result = "系统异常,请重试";
                    result.Message = "系统异常,请重试";
                }
                result.Data = queryResult;
                break;
            }
            return(result);
        }
Esempio n. 14
0
        /// <summary>
        /// 刷卡支付完整业务流程逻辑(2018-04-19写)
        /// </summary>
        /// <param name="body">商品描述</param>
        /// <param name="total_fee">总金额(单位为元)</param>
        /// <param name="auth_code">支付授权码</param>
        /// <returns>刷卡支付结果</returns>
        public static AlipayPayResponse OrderPay(string body, string total_fee, string auth_code)
        {
            IAlipayTradeService serviceClient = F2FBiz.CreateClientInstance(
                F2FPayConfig.serverUrl,
                F2FPayConfig.appId,
                F2FPayConfig.merchant_private_key,
                F2FPayConfig.version,
                F2FPayConfig.sign_type,
                F2FPayConfig.alipay_public_key,
                F2FPayConfig.charset);

            var result = new AlipayPayResponse {
                Success = false, Message = "支付失败"
            };

            //线上联调时,请输入真实的外部订单号。
            result.OutTradeNo = DateTime.Now.ToString("yyyyMMddHHmmss") + "0000" + (new Random()).Next(1, 10000).ToString();

            //扫码枪扫描到的用户手机钱包中的付款条码
            AlipayTradePayContentBuilder builder = new AlipayTradePayContentBuilder();

            //收款账号
            builder.seller_id = F2FPayConfig.pid;
            //订单编号
            builder.out_trade_no = result.OutTradeNo;
            //支付场景,无需修改
            builder.scene = "bar_code";
            //支付授权码,付款码
            builder.auth_code = auth_code.Trim();
            //订单总金额
            builder.total_amount = total_fee.Trim();
            //参与优惠计算的金额
            //builder.discountable_amount = "";
            //不参与优惠计算的金额
            //builder.undiscountable_amount = "";
            //订单名称
            builder.subject = body.Trim();
            //自定义超时时间
            builder.timeout_express = "2m";
            //订单描述
            builder.body = body.Trim();
            //门店编号,很重要的参数,可以用作之后的营销
            builder.store_id = "";
            //操作员编号,很重要的参数,可以用作之后的营销
            builder.operator_id = "";


            //传入商品信息详情
            List <GoodsInfo> gList = new List <GoodsInfo>();

            GoodsInfo goods = new GoodsInfo();

            goods.goods_id   = "304";
            goods.goods_name = "goods#name";
            goods.price      = total_fee.Trim();
            goods.quantity   = "1";
            gList.Add(goods);
            builder.goods_detail = gList;

            //系统商接入可以填此参数用作返佣
            //ExtendParams exParam = new ExtendParams();
            //exParam.sysServiceProviderId = "20880000000000";
            //builder.extendParams = exParam;

            AlipayF2FPayResult payResult = serviceClient.tradePay(builder);

            switch (payResult.Status)
            {
            case ResultEnum.SUCCESS:
                result.Success = true;
                result.Message = "支付成功";
                break;

            case ResultEnum.FAILED:
                var subMsg = payResult.response.SubMsg;
                if (string.IsNullOrEmpty(subMsg))
                {
                    subMsg = "支付失败";
                }
                result.Message = subMsg;
                break;

            case ResultEnum.UNKNOWN:
                result.Message = "支付失败,网络异常,请检查网络配置后,更换外部订单号重试";
                break;
            }
            return(result);
        }
Esempio n. 15
0
        public object getPayQRcode(Dictionary <string, object> dicParas)
        {
            try
            {
                string errMsg        = string.Empty;
                string orderId       = dicParas.ContainsKey("orderId") ? dicParas["orderId"].ToString() : string.Empty;
                string strPayChannel = dicParas.ContainsKey("payChannel") ? dicParas["payChannel"].ToString() : string.Empty;
                string payType       = dicParas.ContainsKey("payType") ? dicParas["payType"].ToString() : string.Empty;
                string subject       = dicParas.ContainsKey("subject") ? dicParas["subject"].ToString() : string.Empty;

                if (string.IsNullOrWhiteSpace(orderId))
                {
                    return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "订单号无效"));
                }

                if (string.IsNullOrWhiteSpace(payType))
                {
                    return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "支付方式为空"));
                }
                //支付方式
                PaymentChannel PayChannel = (PaymentChannel)Convert.ToInt32(payType);

                Flw_Order order = Flw_OrderBusiness.GetOrderModel(orderId);
                if (order == null)
                {
                    return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "订单号无效"));
                }

                Base_StoreInfo store = XCCloudStoreBusiness.GetStoreModel(order.StoreID);
                if (store == null)
                {
                    return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "订单所属门店无效"));
                }

                //订单减免金额
                decimal freePay = order.FreePay == null ? 0 : order.FreePay.Value;
                //计算订单实付金额,单位:元
                decimal amount = (decimal)order.PayCount - freePay;

                PayQRcodeModel model = new PayQRcodeModel();
                model.OrderId = orderId;

                //SelttleType selttleType = (SelttleType)store.SelttleType.Value;
                SelttleType selttleType = (SelttleType)Convert.ToInt32(strPayChannel);
                switch (selttleType)
                {
                case SelttleType.NotThird:
                    break;

                case SelttleType.AliWxPay:     //微信支付宝官方通道
                {
                    #region 支付宝、微信
                    if (PayChannel == PaymentChannel.ALIPAY)        //支付宝
                    {
                        try
                        {
                            IAlipayTradeService serviceClient = F2FBiz.CreateClientInstance(AliPayConfig.serverUrl, AliPayConfig.appId, AliPayConfig.merchant_private_key, AliPayConfig.version,
                                                                                            AliPayConfig.sign_type, AliPayConfig.alipay_public_key, AliPayConfig.charset);

                            AliPayCommon alipay = new AliPayCommon();
                            AlipayTradePrecreateContentBuilder builder = alipay.BuildPrecreateContent(order, amount, subject);
                            //如果需要接收扫码支付异步通知,那么请把下面两行注释代替本行。
                            //推荐使用轮询撤销机制,不推荐使用异步通知,避免单边账问题发生。
                            //AlipayF2FPrecreateResult precreateResult = serviceClient.tradePrecreate(builder);
                            //AliPayConfig.notify_url  //商户接收异步通知的地址
                            AlipayF2FPrecreateResult precreateResult = serviceClient.tradePrecreate(builder, AliPayConfig.notify_url);

                            switch (precreateResult.Status)
                            {
                            case ResultEnum.SUCCESS:
                                model.QRcode = precreateResult.response.QrCode;
                                break;

                            case ResultEnum.FAILED:
                                LogHelper.SaveLog(TxtLogType.AliPay, precreateResult.response.Body);
                                return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, precreateResult.response.Body));

                            case ResultEnum.UNKNOWN:
                                if (precreateResult.response == null)
                                {
                                    LogHelper.SaveLog(TxtLogType.AliPay, "配置或网络异常,请检查后重试");
                                    return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "获取支付二维码失败"));
                                }
                                else
                                {
                                    LogHelper.SaveLog(TxtLogType.AliPay, "系统异常,请更新外部订单后重新发起请求");
                                    return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "获取支付二维码失败"));
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            LogHelper.SaveLog(TxtLogType.AliPay, e.Message);
                            return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "获取支付二维码失败"));
                        }
                    }
                    else if (PayChannel == PaymentChannel.WXPAY)        //微信
                    {
                        NativePay native = new NativePay();
                        try
                        {
                            WxPayData resultData = native.GetPayUrl(order, amount, subject);
                            if (resultData.GetValue("result_code") != null)
                            {
                                string resule = resultData.GetValue("result_code").ToString();
                                if (resule == "SUCCESS")
                                {
                                    model.QRcode = resultData.GetValue("code_url").ToString();        //获得统一下单接口返回的二维码链接
                                }
                                else
                                {
                                    LogHelper.SaveLog(TxtLogType.WeiXinPay, resultData.GetValue("err_code_des").ToString());
                                    return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "获取支付二维码失败," + resultData.GetValue("err_code_des").ToString()));
                                }
                            }
                            else
                            {
                                LogHelper.SaveLog(TxtLogType.WeiXinPay, resultData.GetValue("return_msg").ToString());
                                return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "获取支付二维码失败," + resultData.GetValue("return_msg").ToString()));
                            }
                        }
                        catch (WxPayException ex)
                        {
                            LogHelper.SaveLog(TxtLogType.WeiXinPay, ex.Message);
                            return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "获取支付二维码失败"));
                        }
                        catch (Exception e)
                        {
                            LogHelper.SaveLog(TxtLogType.WeiXinPay, e.Message);
                            return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "获取支付二维码失败"));
                        }
                    }
                    #endregion
                }
                break;

                case SelttleType.StarPos:     //新大陆
                    #region 新大陆
                {
                    string error = "";
                    PPosPayData.OrderPay pposOrder = new PPosPayData.OrderPay();
                    pposOrder.txnTime = System.DateTime.Now.ToString("yyyyMMddHHmmss");
                    pposOrder.tradeNo = order.OrderID;
                    //pposOrder.tradeNo = Guid.NewGuid().ToString().Replace("-", "");
                    pposOrder.amount       = Convert.ToInt32(amount * 100).ToString();  //实际付款
                    pposOrder.total_amount = Convert.ToInt32(amount * 100).ToString();  //订单总金额
                    pposOrder.subject      = subject;
                    pposOrder.payChannel   = PayChannel.ToString();

                    PPosPayApi ppos = new PPosPayApi();
                    PPosPayData.OrderPayACK result = ppos.OrderPay(pposOrder, out error);
                    if (result == null)
                    {
                        return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "获取支付二维码失败," + error));
                    }
                    model.QRcode = result.payCode;
                }
                break;

                    #endregion
                case SelttleType.LcswPay:     //扫呗
                    #region 扫呗
                {
                    string qrcode = "";
                    LcswPayDate.OrderPay payInfo = new LcswPayDate.OrderPay();
                    //payInfo.terminal_trace = Guid.NewGuid().ToString().Replace("-", "");
                    payInfo.terminal_trace = order.OrderID;
                    payInfo.pay_type       = PayChannel.ToDescription();
                    payInfo.order_body     = subject;
                    payInfo.total_fee      = Convert.ToInt32(amount * 100).ToString();
                    LcswPayAPI api = new LcswPayAPI();
                    if (api.OrderPay(payInfo, out qrcode))
                    {
                        model.QRcode = qrcode;
                    }
                    else
                    {
                        return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "获取支付二维码失败"));
                    }
                }
                break;

                    #endregion
                case SelttleType.DinPay:     //智付
                    #region 智付
                    string             errmsg  = "";
                    DinPayData.ScanPay scanPay = new DinPayData.ScanPay();
                    //scanPay.order_no = order.OrderID;
                    scanPay.order_no     = Guid.NewGuid().ToString().Replace("-", "");
                    scanPay.order_time   = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    scanPay.order_amount = amount.ToString("0.01");
                    scanPay.service_type = PayChannel == PaymentChannel.WXPAY ? "weixin_scan" : "alipay_scan";
                    scanPay.product_name = subject;
                    scanPay.product_desc = subject;

                    DinPayApi payApi  = new DinPayApi();
                    string    payCode = payApi.GetQRcode(scanPay, out errmsg);
                    if (payCode == "")
                    {
                        return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "获取支付二维码失败," + errmsg));
                    }
                    model.QRcode = payCode;
                    break;
                    #endregion
                }

                return(ResponseModelFactory <PayQRcodeModel> .CreateModel(isSignKeyReturn, model));
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Esempio n. 16
0
        public object BarcodePay(Dictionary <string, object> dicParas)
        {
            try
            {
                string errMsg        = string.Empty;
                string orderId       = dicParas.ContainsKey("orderId") ? dicParas["orderId"].ToString() : string.Empty;
                string strPayChannel = dicParas.ContainsKey("payChannel") ? dicParas["payChannel"].ToString() : string.Empty;
                string subject       = dicParas.ContainsKey("subject") ? dicParas["subject"].ToString() : string.Empty;
                string payType       = dicParas.ContainsKey("payType") ? dicParas["payType"].ToString() : string.Empty;
                string authCode      = dicParas.ContainsKey("authCode") ? dicParas["authCode"].ToString() : string.Empty;

                if (string.IsNullOrWhiteSpace(orderId))
                {
                    return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "订单号无效"));
                }

                if (string.IsNullOrWhiteSpace(payType))
                {
                    return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "支付方式为空"));
                }
                //支付方式
                PaymentChannel PayChannel = (PaymentChannel)Convert.ToInt32(payType);

                Flw_Order order = Flw_OrderBusiness.GetOrderModel(orderId);
                if (order == null)
                {
                    return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "订单号无效"));
                }
                Base_StoreInfo store = XCCloudStoreBusiness.GetStoreModel(order.StoreID);
                if (store == null)
                {
                    return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "订单所属门店无效"));
                }

                //订单减免金额
                decimal freePay = order.FreePay == null ? 0 : order.FreePay.Value;
                //计算订单实付金额,单位:元
                decimal amount = (decimal)order.PayCount - freePay;

                BarcodePayModel model = new BarcodePayModel();
                model.OrderId = orderId;

                //SelttleType selttleType = (SelttleType)store.SelttleType.Value;
                SelttleType selttleType = (SelttleType)Convert.ToInt32(strPayChannel);
                switch (selttleType)
                {
                case  SelttleType.NotThird:
                    break;

                case SelttleType.AliWxPay:     //微信支付宝官方通道
                {
                    #region 微信支付宝官方通道
                    if (PayChannel == PaymentChannel.ALIPAY)        //支付宝
                    {
                        try
                        {
                            IAlipayTradeService serviceClient = F2FBiz.CreateClientInstance(AliPayConfig.serverUrl, AliPayConfig.appId, AliPayConfig.merchant_private_key, AliPayConfig.version,
                                                                                            AliPayConfig.sign_type, AliPayConfig.alipay_public_key, AliPayConfig.charset);

                            AliPayCommon alipay = new AliPayCommon();
                            AlipayTradePayContentBuilder builder = alipay.BuildPayContent(order, amount, subject, authCode);
                            //string out_trade_no = builder.out_trade_no;

                            AlipayF2FPayResult payResult = serviceClient.tradePay(builder);

                            if (payResult.Status == ResultEnum.SUCCESS)
                            {
                                decimal payAmount = Convert.ToDecimal(payResult.response.TotalAmount);

                                //支付成功后的处理
                                BarcodePayModel callbackModel = Flw_OrderBusiness.OrderPay(payResult.response.OutTradeNo, payAmount, selttleType);

                                model.OrderStatus = callbackModel.OrderStatus;
                                model.PayAmount   = payAmount.ToString("0.00");
                            }
                            else
                            {
                                LogHelper.SaveLog(TxtLogType.AliPay, payResult.response.SubMsg);
                                return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "支付失败"));
                            }
                        }
                        catch (Exception e)
                        {
                            LogHelper.SaveLog(TxtLogType.AliPay, e.Message);
                            return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "支付失败"));
                        }
                    }
                    else if (PayChannel == PaymentChannel.WXPAY)
                    {
                        try
                        {
                            MicroPay  pay        = new MicroPay();
                            WxPayData resultData = pay.BarcodePay(orderId, subject, amount, authCode);
                            string    resule     = resultData.GetValue("result_code").ToString();
                            if (resule == "SUCCESS")
                            {
                                string  out_trade_no = resultData.GetValue("out_trade_no").ToString();
                                decimal total_fee    = Convert.ToDecimal(resultData.GetValue("total_fee"));
                                decimal payAmount    = total_fee / 100;

                                //支付成功后的处理
                                BarcodePayModel callbackModel = Flw_OrderBusiness.OrderPay(out_trade_no, payAmount, selttleType);

                                model.OrderStatus = callbackModel.OrderStatus;
                                model.PayAmount   = payAmount.ToString("0.00");
                            }
                            else
                            {
                                LogHelper.SaveLog(TxtLogType.WeiXinPay, resultData.GetValue("result_code").ToString());
                                return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "支付失败"));
                            }
                        }
                        catch (WxPayException ex)
                        {
                            LogHelper.SaveLog(TxtLogType.WeiXinPay, ex.Message);
                            return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "支付失败"));
                        }
                        catch (Exception e)
                        {
                            LogHelper.SaveLog(TxtLogType.WeiXinPay, e.Message);
                            return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "支付失败"));
                        }
                    }
                    #endregion
                }
                break;

                case SelttleType.StarPos:     //新大陆
                    #region 新大陆
                    PPosPayData.MicroPay pposOrder = new PPosPayData.MicroPay();
                    //string tradeNo = Guid.NewGuid().ToString().Replace("-", "");
                    string tradeNo = order.OrderID;

                    pposOrder.tradeNo      = tradeNo;
                    pposOrder.amount       = Convert.ToInt32(amount * 100).ToString();
                    pposOrder.total_amount = Convert.ToInt32(amount * 100).ToString();
                    pposOrder.authCode     = authCode;
                    pposOrder.payChannel   = PayChannel.ToString();
                    pposOrder.subject      = subject;
                    pposOrder.selOrderNo   = tradeNo;
                    pposOrder.txnTime      = System.DateTime.Now.ToString("yyyyMMddHHmmss");
                    pposOrder.signValue    = "";

                    string     error = "";
                    PPosPayApi ppos  = new PPosPayApi();
                    PPosPayData.MicroPayACK result = ppos.ScanPay(pposOrder, out error);
                    if (result != null)
                    {
                        //SUCCESS
                        string  out_trade_no = result.tradeNo;
                        decimal total_fee    = Convert.ToDecimal(result.total_amount);
                        decimal payAmount    = total_fee / 100;

                        //支付成功后的处理
                        BarcodePayModel callbackModel = Flw_OrderBusiness.OrderPay(out_trade_no, payAmount, selttleType);

                        model.OrderStatus = callbackModel.OrderStatus;
                        model.PayAmount   = payAmount.ToString("0.00");
                    }
                    else
                    {
                        LogHelper.SaveLog(TxtLogType.PPosPay, error);
                        return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "支付失败," + error));
                    }
                    break;

                    #endregion
                case SelttleType.LcswPay:     //扫呗
                    #region 扫呗
                    LcswPayDate.TradePay tradePay = new LcswPayDate.TradePay();
                    tradePay.terminal_trace = order.OrderID;
                    tradePay.pay_type       = PayChannel.ToDescription();
                    tradePay.order_body     = subject;
                    tradePay.total_fee      = Convert.ToInt32(amount * 100).ToString();
                    tradePay.auth_no        = authCode;
                    LcswPayAPI api = new LcswPayAPI();
                    LcswPayDate.OrderPayACK ack = api.BarcodePay(tradePay);
                    if (ack != null)
                    {
                        if (ack.return_code == "01" && ack.result_code == "01")
                        {
                            string  out_trade_no = ack.out_trade_no;
                            decimal total_fee    = Convert.ToDecimal(ack.total_fee);
                            decimal payAmount    = total_fee / 100;

                            //支付成功后的处理
                            BarcodePayModel callbackModel = Flw_OrderBusiness.OrderPay(out_trade_no, payAmount, SelttleType.LcswPay);

                            model.OrderStatus = callbackModel.OrderStatus;
                            model.PayAmount   = payAmount.ToString("0.00");
                        }
                    }
                    else
                    {
                        LogHelper.SaveLog(TxtLogType.LcswPay, "条码支付失败");
                        return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "支付失败"));
                    }
                    break;

                    #endregion
                case SelttleType.DinPay:     //智付
                    #region 智付
                    string errmsg = "";

                    DinPayData.MicroPay Pay = new DinPayData.MicroPay();
                    //scanPay.order_no = order.OrderID;
                    Pay.order_no     = Guid.NewGuid().ToString().Replace("-", "");
                    Pay.order_time   = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    Pay.order_amount = amount.ToString("0.01");
                    Pay.service_type = PayChannel == PaymentChannel.WXPAY ? "weixin_micropay" : "alipay_micropay";
                    Pay.product_name = subject;
                    Pay.auth_code    = authCode;
                    //Pay.return_url = "http://106.14.174.131/returnurl.aspx";

                    DinPayApi payApi    = new DinPayApi();
                    string    resultXml = payApi.MicroPay(Pay);

                    //将同步返回的xml中的参数提取出来
                    var el = XElement.Load(new StringReader(resultXml));
                    //处理码
                    string resp_code = el.XPathSelectElement("/response/resp_code").Value;
                    //业务结果
                    string result_code = el.XPathSelectElement("/response/result_code").Value;
                    if (resp_code == "SUCCESS" && result_code == "0")
                    {
                        //支付成功后的处理
                        string  out_trade_no = el.XPathSelectElement("/response/order_no").Value;
                        decimal total_fee    = Convert.ToDecimal(el.XPathSelectElement("/response/order_amount").Value);
                        decimal payAmount    = total_fee / 100;

                        BarcodePayModel callbackModel = Flw_OrderBusiness.OrderPay(out_trade_no, payAmount, SelttleType.DinPay);

                        model.OrderStatus = callbackModel.OrderStatus;
                        model.PayAmount   = payAmount.ToString("0.00");
                    }
                    else
                    {
                        errmsg = el.XPathSelectElement("/response/result_desc").Value;
                        LogHelper.SaveLog(TxtLogType.DinPay, errmsg);
                        return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "支付失败," + errmsg));
                    }
                    break;
                    #endregion
                }

                return(ResponseModelFactory <BarcodePayModel> .CreateModel(isSignKeyReturn, model));
            }
            catch (WxPayException ex)
            {
                LogHelper.SaveLog(TxtLogType.WeiXinPay, ex.Message);
                return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "支付失败"));
            }
            catch (Exception e)
            {
                LogHelper.SaveLog(TxtLogType.Api, e.Message);
                return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "支付失败"));
            }
        }
Esempio n. 17
0
 public AlipayF2FService(IOptions <AlipayOptions> alipayOptions)
 {
     Options       = alipayOptions.Value;
     _alipayClient = F2FBiz.CreateClientInstance(Options.Gatewayurl, Options.AppId, Options.PrivateKey, "1.0",
                                                 Options.SignType, Options.AlipayPublicKey, Options.CharSet);
 }