Ejemplo n.º 1
0
 public async Task <bool> NotifyAsync(string requestUri, QueryOrderResult result)
 {
     return(await target.SendAsync(new QueueEntry()
     {
         requestUri = requestUri, result = result
     }));
 }
Ejemplo n.º 2
0
        public async Task <IActionResult> OrderStatus(QueryOrderRequest model)
        {
            var order = await context.Orders.AsNoTracking()
                        .SingleOrDefaultAsync(o => o.OrderId == model.OrderId && o.AppId == model.AppId);

            if (order != null)
            {
                var result = new QueryOrderResult()
                {
                    Result      = "SUCCESS",
                    Message     = "OK",
                    AppId       = order.AppId,
                    OrderId     = order.OrderId,
                    NonceStr    = this.signatureService.GenerateNonceStr(),
                    Status      = Enum.GetName(typeof(OrderStatus), order.Status),
                    LastUpdated = order.LastUpdated.ToUniversalTime().ToString("yyyyMMddHHmmss")
                };
                result.Signature = this.signatureService.CalculateSignature(result.AsEnumerable(), order.AppId);

                return(Json(result));
            }
            else
            {
                var result = new QueryOrderResult()
                {
                    Result   = "FAIL",
                    Message  = "OrderNotFound",
                    NonceStr = Guid.NewGuid().ToString().Replace("-", ""),
                    AppId    = model.AppId
                };

                result.Signature = this.signatureService.CalculateSignature(result.AsEnumerable(), model.AppId);
                return(Json(result));
            }
        }
Ejemplo n.º 3
0
        public async Task <bool> NotifyAsync(string requestUri, QueryOrderResult result)
        {
            var content  = new FormUrlEncodedContent(result.AsEnumerable().Select(x => new KeyValuePair <string, string>(x.Key, x.Value)));
            var response = await client.PostAsync(requestUri, content);

            if (response.IsSuccessStatusCode)
            {
                var resContent = await response.Content.ReadAsStringAsync();

                var res = JsonConvert.DeserializeObject <NotifyResult>(resContent);
                if (res.Result == "SUCCESS")
                {
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> WxPayCallback()
        {
            string responseBody;

            System.IO.StreamReader sr = new System.IO.StreamReader(HttpContext.Request.Body);
            var status = paymentService.ProcessCallback(await sr.ReadToEndAsync(), out responseBody);

            logger.LogDebug($"Callback from server: {status.ToJson()}");

            var order = await context.Orders.SingleOrDefaultAsync(x => x.OrderId == status.OrderID);

            if (order != null)
            {
                UpdateOrderStatus(status, ref order);
                await context.SaveChangesAsync();

                if (!String.IsNullOrEmpty(order.NotifyUrl))
                {
                    QueryOrderResult result = new QueryOrderResult()
                    {
                        Result      = "SUCCESS",
                        Message     = "OK",
                        AppId       = order.AppId,
                        OrderId     = order.OrderId,
                        Status      = Enum.GetName(typeof(OrderStatus), order.Status),
                        NonceStr    = signatureService.GenerateNonceStr(),
                        LastUpdated = status.TransactionTime.HasValue ? status.TransactionTime.Value.ToString("yyyyMMddHHmmss") : DateTime.Now.ToUniversalTime().AddHours(8).ToString("yyyyMMddHHmmss")
                    };
                    result.Signature = this.signatureService.CalculateSignature(result.AsEnumerable(), order.AppId);
                    // ******* this should enqueue, instead of sending immediately
                    await this.notifyService.NotifyAsync(order.NotifyUrl, result);

                    // ***************
                }
            }
            else
            {
                logger.LogDebug($"Order not found.");
            }
            return(Content(responseBody));
        }
Ejemplo n.º 5
0
        public QueryOrderResult QueryOrderAsync(QueryOrderParameter queryOrderParameter)
        {
            string str;

            if (!this.ValidateParameter <QueryOrderParameter>(queryOrderParameter, out str))
            {
                QueryOrderResult result1 = new QueryOrderResult();
                result1.ErrorMessage = str;
                return(result1);
            }
            OrderQueryRequest request = new OrderQueryRequest
            {
                AppId       = this.m_AppId,
                MerchantId  = queryOrderParameter.MerchantId,
                NonceString = WeChatSignHelper.CreateRandomString(),
                OutTradeNo  = queryOrderParameter.OutTradeNo
            };
            OrderQueryResponse response = this.InvokeApiAsync <OrderQueryRequest, OrderQueryResponse>(_OrderQueryUrl, request);

            if (!response.IsSuccess)
            {
                QueryOrderResult result3 = new QueryOrderResult();
                result3.ErrorCode    = response.ErrCode;
                result3.ErrorMessage = response.ReturnMsg;
                return(result3);
            }
            QueryOrderResult result2 = new QueryOrderResult();

            result2.IsSuccess             = true;
            result2.EndTime               = response.TimeEnd;
            result2.OutTradeNo            = response.OutTradeNo;
            result2.TotalFee              = ((double)response.TotalFee.GetValueOrDefault()) / 100.0;
            result2.TradeState            = (TradeState)Enum.Parse(typeof(TradeState), response.TradeState, true);
            result2.TradeStateDescription = response.TradeStateDesc;
            result2.TransactionId         = response.TransactionId;
            result2.Bank = WeChatBankTypes.GetBank(response.BankType);
            return(result2);
        }
Ejemplo n.º 6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            ParamQueryOrderResult param = new ParamQueryOrderResult();

            param.m_gmAccount = Request.QueryString["gmAcc"];
            param.m_gmPwd     = Request.QueryString["gmPwd"];
            //param.m_playerAcc = Request.QueryString["playerAcc"];
            param.m_sign    = Request.QueryString["sign"];
            param.m_orderId = Request.QueryString["orderId"];

            if (!param.isParamValid())
            {
                Dictionary <string, object> data = new Dictionary <string, object>();
                data.Add("result", RetCode.RET_PARAM_NOT_VALID);
                Response.Write(Helper.genJsonStr(data));
                return;
            }

            QueryOrderResult query  = new QueryOrderResult();
            string           retStr = query.doQuery(param);

            Response.Write(retStr);
        }