Example #1
0
        //接受处理方法
        public void Receive(HttpContext context)
        {
            SortedDictionary<string, string> sPara = GetRequestGet();

            if (sPara.Count > 0)//判断是否有带返回参数
            {
                Notify aliNotify = new Notify();
                bool verifyResult = aliNotify.Verify(sPara, Request.QueryString["notify_id"], Request.QueryString["sign"]);

                if (verifyResult)//验证成功
                {
                    string trade_no = Request.QueryString["trade_no"];              //支付宝交易号
                    string order_no = Request.QueryString["out_trade_no"];	        //获取订单号
                    string total_fee = Request.QueryString["total_fee"];            //获取总金额
                    string subject = Request.QueryString["subject"];                //商品名称、订单名称
                    string body = Request.QueryString["body"];                      //商品描述、订单备注、描述
                    string buyer_email = Request.QueryString["buyer_email"];        //买家支付宝账号
                    string trade_status = Request.QueryString["trade_status"];      //交易状态

                    PayOrder model = PayOrderBLL.GetPayOrder(order_no);
                    if (model == null) Response.Redirect(string.Format("PayResult.aspx?errorInfo={0}", HttpUtility.UrlEncode("未找到对应的订单编号")), true);
                    if (model.State == "success") Response.Redirect("PayResult.aspx?info=true", true);
                    if (model.State == "fail") Response.Redirect("PayResult.aspx?info=false", true);

                    bool result = true;// PayOrderBLL.PayOrder(model.UserId, IsSuccess(trade_status) ? "success" : "fail", order_no, trade_no);
                    if (!result) Response.Redirect(string.Format("PayResult.aspx?errorInfo={0}", HttpUtility.UrlEncode("订单处理失败!")), true);
                    else Response.Redirect(string.Format("PayResult.aspx?info={0}", IsSuccess(trade_status).ToString()), true);
                }
            }
        }
Example #2
0
        //接受处理方法
        public void Receive(HttpContext context)
        {
            SortedDictionary<string, string> sPara = GetRequestPost();

            if (sPara.Count > 0)//判断是否有带返回参数
            {
                Notify aliNotify = new Notify();
                bool verifyResult = aliNotify.Verify(sPara, Request.Form["notify_id"], Request.Form["sign"]);

                if (verifyResult)//验证成功
                {
                    string trade_no = Request.Form["trade_no"];         //支付宝交易号
                    string order_no = Request.Form["out_trade_no"];     //获取订单号
                    string total_fee = Request.Form["total_fee"];       //获取总金额
                    string subject = Request.Form["subject"];           //商品名称、订单名称
                    string body = Request.Form["body"];                 //商品描述、订单备注、描述
                    string buyer_email = Request.Form["buyer_email"];   //买家支付宝账号
                    string trade_status = Request.Form["trade_status"]; //交易状态
                    try
                    {
                        PayOrder model = PayOrderBLL.GetPayOrder(order_no);
                        if (model == null || model.State != "nopay") Response.Write("success");
                        else
                        {
                            XLog.XTrace.WriteLine(string.Format("内部订单:【{2}】,支付宝订单:【{0}】,返回结果:【{1}】,充值金额:【{3}】", trade_no, trade_status, order_no, total_fee));
                            if (trade_status == "TRADE_FINISHED" || trade_status == "TRADE_SUCCESS")
                            {
                                int fee = Convert.ToInt32(Convert.ToDecimal(total_fee));
                                bool result = PayOrderBLL.PayOrder(model.UserId, "success", order_no, trade_no, fee);
                                string mobile = UserBLL.GetUserByUserID(model.UserId).Mobile;
                                if (result) SmsBLL.SendSms(mobile, string.Format("尊敬的魔云用户,您好!您已成功充值{0}魔豆!", fee));
                                else SmsBLL.SendSms(mobile, string.Format("订单{0}:充值失败", model.TradeNo));
                            }
                            else
                            {
                                PayOrderBLL.PayOrder(model.UserId, "fail", order_no, trade_no, 0);
                            }
                        }
                        Response.Write("success");
                    }
                    catch (Exception ex)
                    {
                        XLog.XTrace.WriteLine(ex.Message);
                    }
                }
                else
                {
                    Response.Write("fail");
                }
            }
            Response.Write("fail");
        }