public async Task <bool> SendToWechat(IList <string> openids)
        {
            try
            {
                StallApplication.SysInfoFormat($"[MSG]start sending order {Id} to wechat");

                //send message
                var msg    = OwnerAlertMessage;
                var result = await WeChatHelper.SendMessageAsync(openids, msg);

                if (result)
                {
                    StallApplication.SysInfoFormat($"[MSG]succeed sending order {Id} to wechat");
                }
                else
                {
                    StallApplication.SysInfoFormat($"[MSG]failed sending order {Id} to wechat");
                }
                return(result);
            }
            catch (Exception ex)
            {
                StallApplication.SysError("[MSG]failed to send message", ex);
                return(false);
            }
        }
Exemple #2
0
        public async Task <ActionResult> WeChatMpLoginCallback(string returnUrl)
        {
            var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();

            if (loginInfo == null)
            {
                StallApplication.BizErrorFormat("[MSG]failed to get login info");
                return(View("Error"));
            }

            // Sign in the user with this external login provider if the user already has a login
            var result = await SignInManager.ExternalSignInAsync(loginInfo, isPersistent : false);

            switch (result)
            {
            case SignInStatus.Success:
                StallApplication.SysInfoFormat(string.Format("[MSG]signIn succeed, redirec to {0}", returnUrl));
                return(Redirect(returnUrl));

            case SignInStatus.LockedOut:
                return(View("Lockout"));

            case SignInStatus.RequiresVerification:
                return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = false }));

            case SignInStatus.Failure:
            default:
                // If the user does not have an account, then prompt the user to create an account
                ViewBag.ReturnUrl     = returnUrl;
                ViewBag.LoginProvider = loginInfo.Login.LoginProvider;

                GreenspotUser user = new GreenspotUser()
                {
                    UserName = ""
                };
                var rslt = await UserManager.CreateAsync(loginInfo, user);

                if (rslt.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    return(Redirect(returnUrl));
                }
                return(Redirect(returnUrl));
            }
        }
Exemple #3
0
        public ActionResult PxPay(int id)
        {
            string paidFlag = Request["paid"];

            if (paidFlag == null)
            {
                StallApplication.SysError("[MSG]pxpay callback without paid parameter");
                return(View("Error"));
            }

            StallApplication.SysInfoFormat("[MSG]PxPay call back [{0}]:{1}", paidFlag, Request.Url.ToString());
            bool isSuccess = "SUCCESS".Equals(paidFlag.ToUpper());

            string payResultId = Request["result"];

            if (string.IsNullOrEmpty(payResultId))
            {
                StallApplication.SysError("[MSG]pxpay callback without result id");
                return(View("Error"));
            }

            int paymentId = 0;

            if (!Accountant.VerifyPxPayPayment(payResultId, isSuccess, out paymentId))
            {
                StallApplication.BizErrorFormat("[MSG]PxPay not verified, result id={0}", payResultId);
                return(View("Error"));
            }

            if (paymentId != id)
            {
                StallApplication.BizErrorFormat("[MSG]transaction not matched, px {0} <> url {1}", paymentId, id);
                return(View("Error"));
            }

            if (isSuccess)
            {
                if (StallApplication.IsPaymentOperating(paymentId))
                {
                    StallApplication.BizErrorFormat("[MSG]payment {0} is operating", paymentId);
                    return(Redirect("/customer/orders"));
                }

                //set order as paid
                var orders = Models.Order.FindByPaymentId(paymentId, _db);
                foreach (var order in orders)
                {
                    if (!order.HasPaid)
                    {
                        try
                        {
                            order.HasPaid = true;
                            _db.SaveChanges();

                            //notify
                            var openIds = new List <string>();
                            //owner
                            var owner   = UserManager.FindById(order.Stall.UserId);
                            var ownerId = owner?.SnsInfos[WeChatClaimTypes.OpenId].InfoValue;
                            openIds.Add(ownerId);

                            //delivery man
                            var deliveryMen = Models.User.GetByRole(_db, "DeliveryMan");
                            foreach (var d in deliveryMen)
                            {
                                var dId = d.SnsInfos.FirstOrDefault(x => WeChatClaimTypes.OpenId.Equals(x.InfoKey))?.InfoValue;
                                if (!string.IsNullOrEmpty(dId))
                                {
                                    openIds.Add(dId);
                                }
                            }

                            //await order.Notify(_db, openId);
                            HostingEnvironment.QueueBackgroundWorkItem(x => order.Notify(_db, openIds));
                        }
                        catch (Exception ex)
                        {
                            StallApplication.SysError($"[MSG]failed to save order {order.Id}", ex);
                        }
                    }
                }

                StallApplication.RemoveOperatingPayment(paymentId);
                return(Redirect("/customer/orders?act=paid"));
            }
            else
            {
                return(Redirect("/errorpage/payfailed"));
            }
        }