Esempio n. 1
0
        public ActionResult AppPay(string out_trade_no, int total_amount, string body)
        {
            var request = new AppPayRequest();

            request.AddGatewayData(new AppPayModel()
            {
                Body        = body,
                TotalAmount = total_amount,
                OutTradeNo  = out_trade_no
            });

            var response = _gateway.Execute(request);

            return(Json(response));
        }
Esempio n. 2
0
        public IActionResult AppPay(string order_id, int total_amount, string body)
        {
            var request = new AppPayRequest();

            request.AddGatewayData(new AppPayModel()
            {
                Body        = body,
                TotalAmount = total_amount,
                OrderId     = order_id
            });

            var response = _gateway.Execute(request);

            return(Json(response));
        }
Esempio n. 3
0
        public void TestAppPay()
        {
            var request = new AppPayRequest();

            request.AddGatewayData(new AppPayModel()
            {
                TotalAmount = 1,
                Subject     = "支付宝手机APP支付测试",
                OutTradeNo  = _outTradeNo
            });

            var response = _alipayGateway.Execute(request);

            _output.WriteLine(response.OrderInfo);
            Assert.NotNull(response.OrderInfo);
        }
Esempio n. 4
0
        public async Task <JsonResult> Create([FromForm] string token, [FromForm] int courseId)
        {
            DataResult dr = new DataResult();

            try
            {
                if (courseId < 10000)
                {
                    dr.code = "201";
                    dr.msg  = "参数错误";
                    return(Json(dr));
                }

                UserEntity userEntity = this.GetUserByToken(token);

                CourseEntity courseEntity = courseOrderBLL.ActionDal.ActionDBAccess.Queryable <CourseEntity>().InSingle(courseId);

                if (courseEntity == null)
                {
                    dr.code = "201";
                    dr.msg  = "不存在该课程";
                    return(Json(dr));
                }

                CourseOrderEntity courseOrderEntity = new CourseOrderEntity()
                {
                    courseId   = courseEntity.courseId,
                    createDate = DateTime.Now,
                    modifyDate = DateTime.Now,
                    orderNo    = "WX" + userEntity.userId.ToString() + DateTime.Now.ToString("yyyyMMddHHmmss"),
                    orderTotal = courseEntity.price,
                    payChannel = "",
                    payDate    = Helper.ConvertHelper.DEFAULT_DATE,
                    payNo      = "",
                    realTotal  = 0,
                    state      = 1,
                    userId     = userEntity.userId
                };

                CourseOrderEntity courseOrder = await courseOrderBLL.ActionDal.ActionDBAccess.Insertable(courseOrderEntity).ExecuteReturnEntityAsync();

                if (courseOrder == null)
                {
                    dr.code = "201";
                    dr.msg  = "创建订单失败";
                    return(Json(dr));
                }

                CoursePayResult coursePayResult = new CoursePayResult();
                coursePayResult.courseOrderEntity = courseOrder;

                var request = new AppPayRequest();
                request.AddGatewayData(new AppPayModel()
                {
                    Body        = "购买课程" + courseEntity.name,
                    TotalAmount = Convert.ToInt32(courseOrder.orderTotal * 100),
                    OutTradeNo  = courseOrder.orderNo
                });

                var response = _gateway.Execute(request);
                coursePayResult.payResult = response.OrderInfo;

                dr.code = "200";
                dr.msg  = "成功";
                dr.data = coursePayResult;
            }
            catch (Exception ex)
            {
                dr.code = "999";
                dr.msg  = ex.Message;
            }
            return(Json(dr));
        }
Esempio n. 5
0
        async Task <RequestPaymentResponseDTO> AppPay(RequestPaymentRequestDTO model)
        {
            var orderDTO = await _orderServiceProxy.GetById(model.OrderId);

            if (orderDTO == null)
            {
                return(null);
            }

            var request = new AppPayRequest();

            var body   = "";
            var orgStr = (orderDTO.OrderItems.FirstOrDefault()?.Title ?? "-");

            if (orgStr.Length > 20)
            {
                body = orgStr.Substring(0, 20);
            }
            else
            {
                body = orgStr;
            }

            request.AddGatewayData(new AppPayModel()
            {
                Body        = body,
                OutTradeNo  = orderDTO.OrderNo,
                TotalAmount = (int)(orderDTO.PayAmount * 100)
            });

            IGateway gateway = null;

            var organizationId = "";

            organizationId = orderDTO.OrganizationId ?? "";
            WeChatAppConfiguration appConfig = null;

            if (!string.IsNullOrEmpty(organizationId))
            {
                appConfig = _wechatAppConfigurationRepository.GetFiltered(o => o.OrganizationId == organizationId).FirstOrDefault();
            }

            if (appConfig != null)
            {
                var wechatpayMerchant = new PaySharp.Wechatpay.Merchant
                {
                    AppId           = appConfig.AppId,
                    MchId           = appConfig.MchId,
                    Key             = appConfig.Key,
                    AppSecret       = appConfig.AppSecret,
                    SslCertPath     = appConfig.SslCertPath,
                    SslCertPassword = appConfig.SslCertPassword,
                    NotifyUrl       = appConfig.NotifyUrl
                };

                gateway = new WechatpayGateway(wechatpayMerchant);
            }
            else
            {
                gateway = _gateways.Get <WechatpayGateway>();
            }

            var response = gateway.Execute(request);

            var ns   = Guid.NewGuid().ToString().Replace("-", "").Substring(0, 20);
            var ts   = GetTimeStamp();
            var pkg  = $"prepay_id={response?.PrepayId}";
            var sign = GetSign(((WechatpayGateway)gateway).Merchant.AppId, ns, response?.PrepayId, ts.ToString(), ((WechatpayGateway)gateway).Merchant.Key);

            var result = new RequestPaymentResponseDTO
            {
                NonceStr  = ns,
                Package   = "Sign=WXPay",//pkg,
                PaySign   = sign,
                TimeStamp = ts.ToString(),
                AppId     = response?.AppId,
                PartnerId = response?.MchId,
                PrepayId  = response?.PrepayId
            };

            return(result);
        }