/// <summary> /// 即刻回调函数 /// </summary> /// <returns></returns> public ActionResult Alipay_Return() { bool isSuccess = false; string AcitonCate = string.Empty; try { SortedDictionary <string, string> sArrary = GetRequestGet(); ///////////////////////以下参数是需要设置的相关配置参数,设置后不会更改的////////////////////// AlipayConfig con = new AlipayConfig(); string partner = con.Partner; string key = con.Key; string input_charset = con.Input_charset; string sign_type = con.Sign_type; string transport = con.Transport; ////////////////////////////////////////////////////////////////////////////////////////////// if (sArrary.Count > 0)//判断是否有带返回参数 { AlipayNotify aliNotify = new AlipayNotify(sArrary, Request.QueryString["notify_id"], partner, key, input_charset, sign_type, transport); string responseTxt = aliNotify.ResponseTxt; //获取远程服务器ATN结果,验证是否是支付宝服务器发来的请求 string sign = Request.QueryString["sign"]; //获取支付宝反馈回来的sign结果 string mysign = aliNotify.Mysign; //获取通知返回后计算后(验证)的签名结果 //写日志记录(若要调试,请取消下面两行注释) //string sWord = "responseTxt=" + responseTxt + "\n return_url_log:sign=" + Request.QueryString["sign"] + "&mysign=" + mysign + "\n return回来的参数:" + aliNotify.PreSignStr; //AlipayFunction.log_result(Server.MapPath("log/" + DateTime.Now.ToString().Replace(":", "")) + ".txt",sWord); //判断responsetTxt是否为ture,生成的签名结果mysign与获得的签名结果sign是否一致 //responsetTxt的结果不是true,与服务器设置问题、合作身份者ID、notify_id一分钟失效有关 //mysign与sign不等,与安全校验码、请求时的参数格式(如:带自定义参数等)、编码格式有关 if (responseTxt == "true" && sign == mysign)//验证成功 { ///////////////////////////////////////////////////////////////////////////////////////////////////////////// //——请根据您的业务逻辑来编写程序(以下代码仅作参考)—— //获取支付宝的通知返回参数,可参考技术文档中页面跳转同步通知参数列表 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"]; //交易状态 string extra_common_param = Request.QueryString["trade_status"]; //会员唯一编号 ////打印页面 if (Request.QueryString["trade_status"] == "TRADE_FINISHED" || Request.QueryString["trade_status"] == "TRADE_SUCCESS") { //################################################# try { SqlTranEx.SqlTranExtensions _STE = new SqlTranEx.SqlTranExtensions(); #region 付款成功之后的操作 switch (body) { } #endregion isSuccess = _STE.ExecuteSqlTran(); //return Content("失败:该流水号不存在"); } catch { return(Content("Error")); } //################################################# } else { Response.Write("trade_status=" + Request.QueryString["trade_status"]); } ////——请根据您的业务逻辑来编写程序(以上代码仅作参考)—— } else { //验证失败 } } else { return(Content("无返回参数")); } } catch (Exception ex) { } if (isSuccess) { if (AcitonCate == "充值") { return(RedirectToAction("MemberAccountInfo", "MSComm")); } else if (AcitonCate == "活动付款") { return(RedirectToAction("SignUpSuccess", "Home")); } else if (AcitonCate == "会员卡") { return(RedirectToAction("MemberCardLog", "MSComm")); } return(RedirectToAction("MemberAccountInfo", "MSComm")); } else { if (AcitonCate == "充值") { return(RedirectToAction("MemberAccountInfo", "MSComm")); } else if (AcitonCate == "活动付款") { return(RedirectToAction("SignUpFailed", "Home", new { msg = "支付失败,请重新核对支付信息后重新支付" })); } else if (AcitonCate == "会员卡") { return(RedirectToAction("MemberCardLog", "MSComm")); } return(RedirectToAction("SignUpFailed", "Home", new { msg = "支付失败,请重新核对支付信息后重新支付" })); } }