public async Task <object> PayAsync(OrderPayRequestDto input)
        {
            var productOrder = await Repository.Include(x => x.OrderItems).FirstOrDefaultAsync(x => x.Id == input.OrderId);

            if (productOrder == null)
            {
                throw new UserFriendlyException("NotFind");
            }

            var appName = _httpContextAccessor?.GetAppName();
            var app     = await _appProvider.GetOrNullAsync(appName);

            var appid = app["appid"] ?? throw new AbpException($"App:{appName} appid未设置");

            var mchId = await _setting.GetOrNullAsync(MallManagementSetting.PayMchId);

            var mchKey = await _setting.GetOrNullAsync(MallManagementSetting.PayKey);

            var notifyUrl = await _setting.GetOrNullAsync(MallManagementSetting.PayNotify);


            var payorder = new PayOrder();

            payorder.CreatWxPayFromProductOrder(id: GuidGenerator.Create(),
                                                productOrder: productOrder,
                                                mchId: mchId,
                                                openid: input.openid,
                                                appName: appName,
                                                shareFromUserId: null,
                                                partnerId: null
                                                );

            var insertPayOrder = await _payOrderRepository.InsertAsync(payorder, autoSave : true);

            productOrder.SetBillNo(insertPayOrder.Id, insertPayOrder.BillNo);

            var unifiedResult = await _payApi.UnifiedOrderAsync(
                appid,
                mchId,
                mchKey,
                body : productOrder.OrderItems.First().SpuName,
                outTradeNo : insertPayOrder.BillNo,
                totalFee : Convert.ToInt32(productOrder.PriceOriginal * 100),
                notifyUrl : notifyUrl.EnsureEndsWith('/') + appName,
                tradeType : Consts.TradeType.JsApi,
                openId : input.openid,
                billCreateIp : _httpContext.HttpContext.Connection.RemoteIpAddress.ToString()
                );

            _rabbit.PushDelyMessage(new PayOrderLisenerData {
                Type = "PayOrder", Data = insertPayOrder
            }, MallConsts.PayAutoCancelTime, "SoMall_DelayQueue");                                                                                          // 半小时内未支付删除

            return(unifiedResult);
        }
예제 #2
0
        public async Task <object> PayAsync(OrderPayRequestDto input)
        {
            var productOrder = await Repository.Include(x => x.OrderItems).FirstOrDefaultAsync(x => x.Id == input.OrderId);

            var appName = _httpContextAccessor?.HttpContext.Request.Headers["AppName"].FirstOrDefault();
            var app     = await _appProvider.GetOrNullAsync(appName);

            var appid = app["appid"] ?? throw new AbpException($"App:{appName} appid未设置");

            var mchId = await _setting.GetOrNullAsync(MallManagementSetting.PayMchId);

            var mchKey = await _setting.GetOrNullAsync(MallManagementSetting.PayKey);

            var notifyUrl = await _setting.GetOrNullAsync(MallManagementSetting.PayNotify);


            var payorder = new PayOrder();

            payorder.CreatWxPayFromProductOrder(id: GuidGenerator.Create(),
                                                productOrder: productOrder,
                                                mchId: mchId,
                                                openid: input.openid,
                                                appName: appName,
                                                shareFromUserId: null,
                                                partnerId: null
                                                );

            var insertAsync = await _payOrderRepository.InsertAsync(payorder, autoSave : true);

            productOrder.SetBillNo(insertAsync.Id, insertAsync.BillNo);

            var result = await _payApi.UnifiedOrderAsync(
                appid,
                mchId,
                mchKey,
                body : productOrder.OrderItems.First().SpuName,
                outTradeNo : insertAsync.BillNo,
                totalFee : Convert.ToInt32(productOrder.PriceOriginal * 100),
                notifyUrl : notifyUrl,
                tradeType : Consts.TradeType.JsApi,
                openId : input.openid,
                billCreateIp : _httpContext.HttpContext.Connection.RemoteIpAddress.ToString()
                );


            return(result);
        }