Ejemplo n.º 1
0
        public ContentResult NotifyVirtualOrder(string id)
        {
            id = DecodePaymentId(id);
            string errorMsg = string.Empty;
            string response = string.Empty;

            try
            {
                var payment = Core.PluginsManagement.GetPlugin <IPaymentPlugin>(id);
                //获取传统context
                var payInfo = payment.Biz.ProcessNotify(this.HttpContext.Request);
                if (payInfo != null)
                {
                    var orderid = payInfo.OrderIds.FirstOrDefault();
                    IVirtualOrderService virtualOrderService = ServiceHelper.Create <IVirtualOrderService>();
                    //更新付款状态
                    virtualOrderService.UpdateMoneyFlagByPayNum(orderid.ToString());
                    //更新诊所账户的待结算金额和余额
                    virtualOrderService.UpdateShopAccountByPayNum(orderid.ToString());
                    //更新平台账户的待结算金额和余额
                    virtualOrderService.UpdatePlatAccountByPayNum(orderid.ToString());
                    //更新平台待结算金额
                    response = payment.Biz.ConfirmPayResult();
                }
            }
            catch (Exception ex)
            {
                errorMsg = ex.Message;
                Core.Log.Error("移动端支付异步通知返回出错,支持方式:" + id, ex);
            }
            return(Content(response));
        }
Ejemplo n.º 2
0
        public object GetPrepaidParameter(string openId, decimal payAmount, long shopId)
        {
            CheckUserLogin();
            var    mobilePayments = Core.PluginsManagement.GetPlugins <IPaymentPlugin>(true).Where(item => item.Biz.SupportPlatforms.Contains(Core.PlatformType.WeiXinSmallProg));
            string webRoot        = HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Host + (HttpContext.Current.Request.Url.Port == 80 ? "" : (":" + HttpContext.Current.Request.Url.Port.ToString()));
            string notifyUrl      = webRoot + "/m-" + Core.PlatformType.Android + "/Payment/NotifyVirtualOrder/";
            string orderId        = GenerateOrderNumber().ToString();
            var    models         = mobilePayments.ToArray().Select(item =>
            {
                string url = string.Empty;
                try
                {
                    url = item.Biz.GetRequestUrl("", notifyUrl + item.PluginInfo.PluginId.Replace(".", "-"), orderId, payAmount, "商家:" + shopId + "快捷收款", CurrentUserOpenId);
                }
                catch (Exception ex)
                {
                    Core.Log.Error("获取支付方式错误:", ex);
                }
                //适配小程序接口,从支付插件里解析出相应参数
                //字符串格式:prepayId:234320480,partnerid:32423489,nonceStr=dslkfjsld
                #region 适配小程序接口,从支付插件里解析出相应参数
                var prepayId  = string.Empty;
                var nonceStr  = string.Empty;
                var timeStamp = string.Empty;
                var sign      = string.Empty;
                if (!string.IsNullOrWhiteSpace(url))
                {
                    var paras = url.Split(',');
                    foreach (var str in paras)
                    {
                        var keyValuePair = str.Split(':');
                        if (keyValuePair.Length == 2)
                        {
                            switch (keyValuePair[0])
                            {
                            case "prepayId":
                                prepayId = keyValuePair[1];
                                break;

                            case "nonceStr":
                                nonceStr = keyValuePair[1];
                                break;

                            case "timeStamp":
                                timeStamp = keyValuePair[1];
                                break;

                            case "sign":
                                sign = keyValuePair[1];
                                break;
                            }
                        }
                    }
                }
                #endregion
                return(new
                {
                    prepayId = prepayId,
                    nonceStr = nonceStr,
                    timeStamp = timeStamp,
                    sign = sign
                });
            });
            var model = models.FirstOrDefault();

            if (!string.IsNullOrEmpty(model.prepayId))
            {
                IVirtualOrderService virtualOrderService = ServiceHelper.Create <IVirtualOrderService>();
                VirtualOrderInfo     entity = new VirtualOrderInfo
                {
                    MoneyFlag = 1,
                    PayAmount = payAmount,
                    PayTime   = DateTime.Now,
                    UserId    = CurrentUserId,
                    UserName  = CurrentUser.Nick,
                    PayNum    = orderId,
                    ShopId    = shopId
                };
                virtualOrderService.CreateVirtualOrder(entity);
            }
            return(Json(new { Status = "OK", Data = model }));
        }