Exemple #1
0
        //
        // GET: /Home/

        /// <summary>
        /// 支付宝异步通知接口
        /// </summary>
        /// <returns></returns>
        public ActionResult AlipayCallBack()
        {
            SortedDictionary<string, string> sPara = GetRequestPost();

            if (sPara.Count > 0)//判断是否有带返回参数
            {
                AlipayNotify aliNotify = new AlipayNotify();
                bool verifyResult = aliNotify.Verify(sPara, Request.Form["notify_id"], Request.Form["sign"]);
                if (verifyResult)//验证成功
                {
                    //商户订单号
                    string tradeNo = sPara["out_trade_no"];
                    //支付宝交易号
                    string taobaoPaymentNo = sPara["trade_no"];
                    //交易状态
                    string tradeStatus = sPara["trade_status"];
                    return Content(ModelFacade.Trade.PaymentModel.AlipayCallBack(tradeNo, taobaoPaymentNo, tradeStatus));
                }
                else//验证失败
                {
                    return Content("fail");
                }
            }
            else
            {
                return Content("无通知参数");
            }
        }
 /// <summary>
 /// 支付宝同步通知页面
 /// </summary>
 /// <returns></returns>
 public ActionResult AlipayReturn()
 {
    
     EPayment payment = null;
     string message = "支付成功";
     try
     {
         SortedDictionary<string, string> sPara = GetRequestGet();
         if (sPara.Count > 0)//判断是否有带返回参数
         {
             AlipayNotify aliNotify = new AlipayNotify();
             bool verifyResult = aliNotify.Verify(sPara, Request.QueryString["notify_id"], Request.QueryString["sign"]);
             if (verifyResult)//验证成功
             {
                 //商户订单号
                 string tradeNo = Request.QueryString["out_trade_no"];
                 //支付宝交易号
                 string taobaoPaymentNo = Request.QueryString["trade_no"];
                 //交易状态
                 string tradeStatus = Request.QueryString["trade_status"];
                 payment = ModelFacade.Trade.PaymentModel.AlipayReturn(tradeNo, taobaoPaymentNo, tradeStatus, out message);
             }
             else//验证失败
             {
                 message = "验证失败";
             }
         }
         else
         {
             message = "无返回参数";
         }
     }
     catch (Exception ex)
     {
         message = ex.Message;
     }
     ViewData["Message"] = message;
     return View(payment);
 }