Beispiel #1
0
        /// <summary>
        /// 获取扫码支付的二维码图片链接(将链接用二维码工具生成二维码打印出来,顾客可以用支付宝钱包扫码支付)
        /// </summary>
        public string GetQrCodePayLink(decimal amount, string orderNo, string subject, string body, string storeId, string operatorId)
        {
            string link = string.Empty;

            //组装业务参数
            var model = new AlipayTradePrecreateModel()
            {
                Body        = body,
                Subject     = subject,
                TotalAmount = amount.ToString(),
                OutTradeNo  = orderNo,
                StoreId     = storeId, //商户门店编号
                OperatorId  = operatorId
            };

            var request = new AlipayTradePrecreateRequest();

            request.SetBizModel(model);

            //不推荐使用异步通知,避免单边账问题发生。推荐使用轮询撤销机制
            //对所有唤起收银台的交易(支付宝返回状态10003(等待用户支付))发起轮询,并且建议轮询总时间设为30秒,轮询平均间隔设为3秒。在让用户再次支付前,必须通过查询确认当前订单的状态。
            //request.SetNotifyUrl(NotifyUrl);

            AlipayTradePrecreateResponse response = aopClient.Execute(request);

            if (response != null && response.Code == "10000")
            {
                link = response.QrCode;
            }

            //记日志response.ToJson();

            return(link);
        }
Beispiel #2
0
        public async Task <IActionResult> PreCreate(string out_trade_no, string subject, string total_amount, string body, string notify_url = "")
        {
            var model = new AlipayTradePrecreateModel
            {
                OutTradeNo  = out_trade_no,
                Subject     = subject,
                TotalAmount = total_amount,
                Body        = body
            };
            var req = new AlipayTradePrecreateRequest();

            req.SetBizModel(model);
            req.SetNotifyUrl(notify_url);

            var response = await _client.ExecuteAsync(req);

            ResponseModel responseModel = new ResponseModel()
            {
                code = HTTPResponseCode.PartialContent,
                data = response.Body
            };

            if (response.IsError)
            {
                responseModel.code    = HTTPResponseCode.BadRequest;
                responseModel.message = response.Msg;
            }
            else
            {
                responseModel.code = HTTPResponseCode.Successful;
            }
            return(Json(responseModel));
        }
Beispiel #3
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 #4
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);
        }
        public async Task <IActionResult> Alipay()
        {
            var config = new AlipayConfig
            {
                NotifyUrl    = "http://mobiletest.emoney.cn/mdata/payment/api/alipay/alipaynotity",
                AppId        = "2015072000178264",
                PrivateKey   = "MIIEowIBAAKCAQEA92h++oFzk59dB+Xjcn+QsXMcMFREsMq1CqBXd1G8l+5wjDKetmoCbXNU3beZtWL+6XuetfPa2tmOR42v1zJeKODid5+tvgBe0ecJvgmxmSQ3al7gAu2mMnwzY6jkhl8kMG9CCUUs5PTQXAeDc5oSoXzfX06xgbCf4D4NRlRwPU5Ff3QVqlZ1desEczubyuhE7dl0pf+/Y6FB1NMTvB1MEX6PQ0ygVqe2i32ugCT/Fq2yf1UNwU6VXqOmX14mF/ZKxhWLn5bW3PVtvQkZQqR1Wtr5pNYDJ91XoKLraeSzH8fbLuxMGfwgflskMGwhMrmt69wRa5+Gc/5TdtgdLH648QIDAQABAoIBADWi8eRdLDFU21ZbAHRSM4xE6FeR7VJmn9kt6ch0b+6AQuYiE0Z4tQ4FcuCebTRlwd3cbwwDUe8gOzhH/1coFEHIf1BvzbrjWasn63THpTkOIPVunCIGY4GOa5Wvh9uZxL67YBWiaZk5efJ5roXhYSihacu/w7vaDs8OpNIafDrN0CE7KKxwo21sxR6++CikPV3ecs1lepKuiGmxSfUlZQ0LIK2kf0nt5JxAkcCmofW5wfTEQ3jD1ogdPtnqenGHqLONPU9vJ/onGLle8zu4K6m1FsIDFmpY/G9CAUDFE/Mkue6jmTFnMzSdEfQyA4mLqiSryerppzkF1eLsShUpAAECgYEA/2JrP8OzE0O3N0sMT0/KwMPrMKlz94GnLAd+YPs3Rf6c5UUEJCBgOo7wSrssvbeTg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qtZ0XDu5/+LiLm/Wvd2lBp1z3QsqTHLumR+w/4CeTH1R/YZXd3fUULqg/2lVEk9O8rIcYVtnMJ/oR/BRhQsCU5y3nvC3fPMOwVqlM8AUzrZvN7tjhxxdFPpyj/d0yTS9B8pwQIDAQAB"
            };

            var data = new AlipayTradePrecreateModel
            {
                Body           = "产品",
                Subject        = "产品",
                OutTradeNo     = $"em_{DateTime.Now.ToString("yyyyMMddHHmmss")}",
                TimeoutExpress = "15m",
                TotalAmount    = $"{10:0.##}"
            };

            var response = await AlipayClient.CreateOrderAsync(data, config);

            var ms = Convert.FromBase64String((await GetImage(response.QrCode)).Replace("data:image/jpeg;base64,", ""));

            return(File(ms, "image/png"));
        }
        public async Task <IActionResult> PreCreate(AlipayTradePreCreateViewModel viewModel)
        {
            if (_Interceptor != null)
            {
                return(Ok("this is _Interceptor"));
            }
            var model = new AlipayTradePrecreateModel
            {
                OutTradeNo  = viewModel.OutTradeNo,
                Subject     = viewModel.Subject,
                TotalAmount = viewModel.TotalAmount,
                Body        = viewModel.Body
            };
            var req = new AlipayTradePrecreateRequest();

            req.SetBizModel(model);
            req.SetNotifyUrl(viewModel.NotifyUrl);

            //var response = await _client.CertificateExecuteAsync(req, _optionsAccessor.Value);
            var response = await _client.ExecuteAsync(req, _optionsAccessor.Value);

            ViewData["qrcode"]   = response.QrCode;
            ViewData["response"] = response.Body;
            return(View());
        }
Beispiel #7
0
        //扫码支付
        public override async Task <AlipayReponse> ExecuteAsync(TradeModel request, ServerCallContext context)
        {
            var model = new AlipayTradePrecreateModel
            {
                OutTradeNo  = request.OutTradeNo,
                Subject     = request.Subject,
                TotalAmount = request.TotalAmount,
                Body        = request.Body
            };



            var req = new AlipayTradePrecreateRequest();

            req.SetBizModel(model);
            req.SetNotifyUrl("http://domain.com/alipay/notify/precreate");

            var response = await _client.ExecuteAsync(req, _optionsAccessor.Value);

            return(new AlipayReponse
            {
                Message = response.Body,
                Qrcode = response.QrCode
            });

            //return base.ExecuteAsync(request, context);
        }
Beispiel #8
0
        /// <summary>
        /// 获取扫码支付的二维码图片链接
        /// </summary>
        /// <param name="orderNo">商户订单号,64个字符以内、只能包含字母、数字、下划线;需保证在商户端不重复</param>
        /// <param name="amount">订单总金额,单位为元,精确到小数点后两位,取值范围[0.01,100000000] 如果同时传入了【打折金额】,【不可打折金额】,【订单总金额】三者,则必须满足如下条件:【订单总金额】=【打折金额】+【不可打折金额】</param>
        /// <param name="subject">订单标题</param>
        /// <param name="body">商品描述信息</param>
        /// <param name="storeId">商户门店编号</param>
        /// <returns></returns>
        public string GetQrCodeUrl(string orderNo, decimal amount, string subject, string body, string storeId)
        {
            string link = string.Empty;

            //组装业务参数
            var model = new AlipayTradePrecreateModel()
            {
                Body        = body,
                Subject     = subject,
                TotalAmount = amount.ToString(),
                OutTradeNo  = orderNo,
                StoreId     = storeId //商户门店编号
            };

            var request = new AlipayTradePrecreateRequest();

            request.SetBizModel(model);
            request.SetNotifyUrl(NotifyUrl);

            AlipayTradePrecreateResponse response = aopClient.Execute(request);

            if (response != null && response.Code == "10000")
            {
                link = response.QrCode;
            }
            return(link);
        }
Beispiel #9
0
        /// <summary>
        /// 预付统一下单
        /// </summary>
        /// <param name="request">提交给统一下单API的参数</param>
        /// <param name="config"></param>
        /// <param name="accessToken">用户授权码</param>
        /// <param name="timeOut">超时时间</param>
        /// <returns>成功时返回,其他抛异常</returns>
        public static async Task <AlipayTradePrecreateResponse> CreateOrderAsync(AlipayTradePrecreateModel request, AlipayConfig config, string accessToken = null, int timeOut = 6)
        {
            IAopClient client      = new AopClient(AlipayConstants.GATEWAYURL, config.AppId, config.PrivateKey, config.Format, config.Version, config.SignType, config.AliPublicKey, config.Charset, config.KeyFromFile);
            var        requestData = new AlipayTradePrecreateRequest();

            requestData.SetNotifyUrl(config.NotifyUrl);
            requestData.SetBizModel(request);

            return(await client.ExecuteAsync(requestData, accessToken));
        }
        public async Task <IActionResult> PreCreate(string out_trade_no, string subject, string total_amount, string body, string notify_url)
        {
            var model = new AlipayTradePrecreateModel()
            {
                Body        = body,
                Subject     = subject,
                TotalAmount = total_amount,
                OutTradeNo  = out_trade_no,
            };
            var req = new AlipayTradePrecreateRequest();

            req.SetBizModel(model);
            req.SetNotifyUrl(notify_url);

            var response = await _client.ExecuteAsync(req);

            return(Ok(response.Body));
        }
Beispiel #11
0
        // 当面付/扫码支付
        public async Task <AlipayTradePrecreateResponse> PreCreate(PayRequest request)
        {
            var order = OrderService.Get(request.Id);
            var model = new AlipayTradePrecreateModel
            {
                OutTradeNo  = order.Order_SN,
                Subject     = order.Name,
                TotalAmount = order.Order_Money.ToString("n"),
                Body        = order.Remark
            };

            var req = new AlipayTradePrecreateRequest();

            req.SetBizModel(model);
            req.SetNotifyUrl(request.NotifyUrl);

            return(await client.ExecuteAsync(req, options.Value));
        }
Beispiel #12
0
        public async Task <IActionResult> PreCreate(AlipayTradePreCreateViewModel viewModel)
        {
            var model = new AlipayTradePrecreateModel()
            {
                OutTradeNo  = viewModel.OutTradeNo,
                Subject     = viewModel.Subject,
                TotalAmount = viewModel.TotalAmount,
                Body        = viewModel.Body,
            };
            var req = new AlipayTradePrecreateRequest();

            req.SetBizModel(model);
            req.SetNotifyUrl(viewModel.NotifyUrl);

            var response = await _client.ExecuteAsync(req);

            ViewData["qrcode"]   = response.QrCode;
            ViewData["response"] = response.Body;
            return(View());
        }