Beispiel #1
0
        /// <summary>
        /// 支付宝Notify & Return回写操作
        /// Notify使用Post方式,Return使用Get方法并完成URL的重定向
        /// </summary>
        /// <param name="httpMethod">Http请求方式,0为Get,1为Post</param>
        public override void Notify_Return(HttpMethod httpMethod)
        {
            var    Request  = HttpContext.Current.Request;
            var    Response = HttpContext.Current.Response;
            var    get_post = httpMethod == HttpMethod.Get ? Request.QueryString : Request.Form;
            string body     = Utility.DecryptString(Request.Params["body"].ToString());
            int    userID   = Convert.ToInt32(body.Split('|')[0]);
            string orderID  = "0";
            string orderIDs = string.Empty;

            orderID = body.Split('|')[1].Split(',')[0];
            if (body.Split('|')[1].Split(',').Length > 1)
            {
                orderIDs = Utility.DecryptString(body.Split('|')[1]);
            }
            int     types      = Convert.ToInt32(body.Split('|')[2]);
            decimal totalFee   = Convert.ToDecimal(body.Split('|')[3]);
            int     sourceType = Convert.ToInt32(body.Split('|')[4]);
            string  exchangeID = Request.Params["trade_no"].ToString();//支付宝的交易号
            string  exception  = null;
            bool    ret        = false;

            try
            {
                StringBuilder result = new StringBuilder();
                foreach (var item in get_post.AllKeys)
                {
                    result.Append(item + get_post[item].ToString() + ",");
                }
                LoggerFactory.Instance.Logger_Info("支付宝回调参数集合:" + result.ToString());
                ret = AlipayReturnParam(userID,
                                        orderID,
                                        exchangeID,
                                        get_post["notify_id"],
                                        get_post["sign"],
                                        get_post,
                                        System.Web.HttpContext.Current);
            }
            catch (Exception ex)
            {
                exception = "sign信息验证状态:" + ret + ",异常信息:" + ex.Message;
                LoggerFactory.Instance.Logger_Info(exception);
            }

            var model = new OrderEventArgs
            {
                OrderID          = orderID,//商家订单号
                UserID           = userID,
                UseType          = (UseType)types,
                TotalFee         = totalFee,
                SourceType       = sourceType,
                ExceptionMessage = exception,
                ExchangeCode     = exchangeID//支付宝交易号
            };

            try
            {
                LoggerFactory.Instance.Logger_Info(model.ToString());
            }
            catch (Exception ex)
            {
                LoggerFactory.Instance.Logger_Info(ex.Message);
            }

            if (ret)
            {
                try
                {
                    //成功
                    OnSuccess(model);
                    if (httpMethod == HttpMethod.Post)
                    {
                        Response.Write("success");
                    }
                }
                catch (Exception)//业务层出现问题,向支付宝也输出fail
                {
                    Response.Write("fail");
                }
            }
            else
            {
                try
                {
                    OnFail(model);
                    if (httpMethod == HttpMethod.Post)
                    {
                        Response.Write("fail");
                    }
                }
                catch (Exception)
                {
                    Response.Write("fail");
                }
            }
        }
Beispiel #2
0
        public override void Notify_Return(HttpMethod httpMethod)
        {
            #region 赋值
            var Response = HttpContext.Current.Response;

            string body     = Utility.DecryptString(Get_Post_Return("Priv1"), Utility.EncryptorType.DES);
            int    userID   = Convert.ToInt32(body.Split('|')[0]);
            string orderID  = "0";
            string orderIDs = string.Empty;
            orderID = body.Split('|')[1].Split(',')[0];
            if (body.Split('|')[1].Split(',').Length > 1)
            {
                orderIDs = Utility.DecryptString(body.Split('|')[1]);
            }
            int     types      = Convert.ToInt32(body.Split('|')[2]);
            decimal totalFee   = Convert.ToDecimal(body.Split('|')[3]);
            int     sourceType = Convert.ToInt32(body.Split('|')[4]);
            string  exchangeID = Get_Post_Return("OrdId");
            bool    ret        = false;
            #endregion

            try
            {
                ret = ChinaPayRetUrlParam(
                    Get_Post_Return("MerId"),
                    Get_Post_Return("BusiId"),
                    Get_Post_Return("OrdId"),
                    Get_Post_Return("OrdAmt"),
                    Get_Post_Return("CuryId"),
                    Get_Post_Return("Version"),
                    Get_Post_Return("GateId"),
                    Get_Post_Return("OrdDesc"),
                    Get_Post_Return("ShareType"),
                    Get_Post_Return("ShareData"),
                    Get_Post_Return("Priv1"),
                    Get_Post_Return("CustomIp"),
                    Get_Post_Return("PayStat"),
                    Get_Post_Return("PayTime"),
                    Get_Post_Return("ChkValue"));
            }
            catch (Exception ex)
            {
                LoggerFactory.Instance.Logger_Info("sign信息验证状态:" + ret + ",异常信息:" + ex.Message);
            }
            LoggerFactory.Instance.Logger_Info(body);
            LoggerFactory.Instance.Logger_Info(Get_Post_Return("ChkValue"));

            var model = new OrderEventArgs
            {
                OrderID      = orderID,
                UserID       = userID,
                UseType      = (UseType)types,
                TotalFee     = totalFee / 100,//将分转换为元
                SourceType   = sourceType,
                ExchangeCode = "银联交易状态:" + Get_Post_Return("PayStat") + ",交易时间:" + Get_Post_Return("PayTime"),
            };
            if (ret)
            {
                //成功
                OnSuccess(model);
                Response.Write("success");
            }
            else
            {
                //成功
                OnFail(model);
                Response.Write("success");
            }
        }