Example #1
0
        public JsonResult Notify(int resultSysNo)
        {
            try
            {
                var resultInfo = PayResultDAL.GetPayResult(resultSysNo);
                if (resultInfo == null || resultInfo.SysNo <= 0)
                {
                    return(Json(new { status = 0, msg = "支付结果记录不存在" }));
                }

                if (resultInfo.ExecuteResult != (int)ResultStatus.Success)
                {
                    return(Json(new { status = 0, msg = "支付结果记录不是成功且有效的支付" }));
                }

                if (resultInfo.RequestSysNo <= 0)
                {
                    return(Json(new { status = 0, msg = "支付结果记录无对应的请求记录" }));
                }

                var requestInfo = PayRequestDAL.GetPayRequest(resultInfo.RequestSysNo);
                if (requestInfo == null || requestInfo.SysNo <= 0)
                {
                    return(Json(new { status = 0, msg = "支付结果记录对应的请求记录不存在" }));
                }

                if (!requestInfo.NotifyUrl.IsUrl())
                {
                    return(Json(new { status = 0, msg = "支付请求记录的通知地址无效" }));
                }

                var resultInterface = Builder.BuildAlipayResult();
                var notifyResult    = resultInterface.NotifyBack(resultInfo, requestInfo);
                if (notifyResult.Status == ResultStatus.Success)
                {
                    return(Json(new { status = 1, msg = "通知成功" }));
                }

                //如果已经通知多次,则将通知状态改成已作废
                int notifyCount = PayResultDAL.GetNotifyBackCount(resultInfo.SysNo);
                if (notifyCount >= 5 && resultInfo.NotifyStatus != (int)AppEnum.NotifyStatus.Canceled)
                {
                    resultInfo.NotifyStatus = (int)AppEnum.NotifyStatus.Canceled;
                    PayResultDAL.Update(resultInfo);
                }
                return(Json(new { status = 0, msg = "通知失败,原因:" + notifyResult.Message }));
            }
            catch (Exception ex)
            {
                LogWriter.WriteLog(ex.Message + "\r\n" + ex.StackTrace, _logDirName, ExceptionHelper.ExceptionLevel.Exception);
                return(Json(new { status = -1, msg = ex.Message, error = ex.StackTrace }));
            }
        }
Example #2
0
        public JsonResult GetReturnUrl(int resultSysNo)
        {
            try
            {
                var resultInfo = PayResultDAL.GetPayResult(resultSysNo);
                if (resultInfo == null || resultInfo.SysNo <= 0)
                {
                    return(Json(new { status = 0, msg = "支付结果记录不存在" }));
                }

                if (resultInfo.RequestSysNo <= 0)
                {
                    return(Json(new { status = 0, msg = "支付结果记录无对应的请求记录" }));
                }

                var requestInfo = PayRequestDAL.GetPayRequest(resultInfo.RequestSysNo);
                if (requestInfo == null || requestInfo.SysNo <= 0)
                {
                    return(Json(new { status = 0, msg = "支付结果记录对应的请求记录不存在" }));
                }

                if (!requestInfo.ReturnUrl.IsUrl())
                {
                    return(Json(new { status = 0, msg = "支付请求记录的返回地址不是有效URL" }));
                }

                var notifyInfo = new PayNotifyInfo()
                {
                    OrderId    = resultInfo.OrderId,
                    PaymentAmt = resultInfo.PaymentAmt.ToString(),
                    TradeNo    = resultInfo.TradeNo,
                    ExtTradeNo = resultInfo.ExtTradeNo,
                    Result     = resultInfo.ExecuteResult.ToString(),
                };

                var    resultInterface = Builder.BuildAlipayResult();
                string returnUrl       = resultInterface.GetReturnUrl(requestInfo, notifyInfo);
                return(Json(new { status = 1, href = returnUrl }));
            }
            catch (Exception ex)
            {
                LogWriter.WriteLog(ex.Message + "\r\n" + ex.StackTrace, _logDirName, ExceptionHelper.ExceptionLevel.Exception);
                return(Json(new { status = -1, msg = ex.Message, error = ex.StackTrace }));
            }
        }