示例#1
0
        public static IApplicationBuilder UseWxPayProccessor(this IApplicationBuilder app)
        {
            app.Map("/WxNotifyUrl", appBuilder =>
            {
                appBuilder.Run(async ctx =>
                {
                    //var wxService = appBuilder.ApplicationServices.GetService<WxService>();
                    var logger           = ctx.RequestServices.GetService <ILogger <WxService> >();
                    var coursePayService = ctx.RequestServices.GetService <CouseOrderService>();
                    try
                    {
                        WxPayData notifyData;
                        //var reqData = await new StreamReader(ctx.Request.Body).ReadToEndAsync();
                        //logger.LogInformation(reqData);
                        //ctx.Request.Body.Position = 0;
                        var responseStr = WeAppPayApi.ProcessNotify(ctx.Request.Body, out notifyData);

                        if (notifyData != null)
                        {
                            logger.LogInformation("notify data ");
                            logger.LogInformation(notifyData.ToJson());

                            var out_trade_no = notifyData.GetValue("out_trade_no").ToString();
                            if (!string.IsNullOrEmpty(out_trade_no))
                            {
                                await coursePayService.NotifyOrder(out_trade_no);
                            }
                            else
                            {
                                logger.LogError("微信服务器数据处理失败。");
                                await ctx.Response.WriteAsync("Faulth");
                            }
                        }

                        await ctx.Response.WriteAsync(responseStr);
                    }
                    catch (Exception exc)
                    {
                        logger.LogError(exc, exc.Message);
                    }
                });
            });

            app.Map("/CheckOrderStatus", appBuilder =>
            {
                appBuilder.Run(async ctx =>
                {
                    var orderId            = ctx.Request.Query["orderId"];
                    var courseOrderService = ctx.RequestServices.GetService <CouseOrderService>();
                    var order = await courseOrderService.GetOrder(Guid.Parse(orderId));
                    if (order.Status == DataCore.Orders.OrderStatus.Payed)
                    {
                        ctx.Response.ContentType = "application/json";
                        await ctx.Response.WriteAsync("{\"success\":true}", Encoding.UTF8);
                    }
                });
            });

            return(app);
        }
示例#2
0
        public async Task <IActionResult> NotifyUrl()
        {
            try
            {
                WxPayData notifyData;
                var       responseStr = WeAppPayApi.ProcessNotify(HttpContext.Request.Body, out notifyData);

                if (notifyData != null)
                {
                    var out_trade_no = notifyData.GetValue("out_trade_no").ToString();
                    var ordyerEntity = await OrderBs.GetDetailData(x => x.OutTradeNo == out_trade_no);

                    if (ordyerEntity != null)
                    {
                        ordyerEntity.Status = Model.Shop.Orders.OrderStatus.Successful;
                        await OrderBs.Update(ordyerEntity);

                        await OrderBs.WriteLog(ordyerEntity);
                    }
                    else
                    {
                        logger.LogError("微信服务器数据处理失败。");
                        return(Content("Faulth"));
                    }
                }

                return(Content(responseStr));
            }
            catch (Exception exc)
            {
                logger.LogError(exc.Message);
                return(Content(exc.Message));
            }
        }
示例#3
0
        public async Task <IActionResult> GetImg()
        {
            var pay    = new NativePay();
            var str    = pay.GetPrePayUrl(Guid.NewGuid().ToString());
            var stream = (MemoryStream)await Task.Run(() => { return(WeAppPayApi.MakeQRCode(str)); });

            //var bytes = new byte[stream.Length];
            //await stream.WriteAsync(bytes, 0, bytes.Length);
            //System.IO.File.WriteAllBytes(AppDomain.CurrentDomain.BaseDirectory + "testqrcode2.jpg", bytes);
            var resStream = new MemoryStream(stream.GetBuffer());

            return(new FileStreamResult(resStream, "image/jpeg"));

            //return File(stream, "image/jpeg");
        }
示例#4
0
        public async Task <IActionResult> UiniferOrder(Guid orderId)
        {
            try
            {
                var orderEntity = await OrderBs.GetDetailData(orderId);

                var totalFee = orderEntity.OrderGoods.Select(x => new
                {
                    Fee = x.Good.Price * x.Number
                }).Sum(x => x.Fee);

                var outtradeno = WeAppPayApi.GenOutTradeNo();

                var vm = new UnifierOrderViewModel()
                {
                    OpenId     = orderEntity.UserAccountEntry.WeChat.OpenIdMapping.FirstOrDefault(x => x.Source == "丸子家族")?.OpenId,
                    Body       = "ceshi ",
                    Attach     = "丸子家族",
                    OutTradeNo = outtradeno,
                    Tag        = "",
                    TotalFee   = (int)(totalFee * 100)
                };
                orderEntity.OutTradeNo = outtradeno;
                await OrderBs.Update(orderEntity);

                var packageStr = WeAppPayApi.UnifiedOrder(vm);

                //return Json(packageStr);
                return(Content(packageStr, "application/json"));
            }
            catch (Exception exc)
            {
                logger.LogError(exc.Message);
                return(Content(exc.Message));
            }
        }