/// <summary> /// 处理支付异步返回的信息(主要是使用该函数进行日志记录logResult) /// 创建人:孙佳杰 时间:2015.1.16 /// </summary> /// <param name="method">订单处理逻辑</param> /// <param name="Request">当前请求对象</param> /// <returns>获得处理情况</returns> public static string NotifyAction(Func <AliPayReturnModel, string> method, System.Web.HttpRequest Request) { string msg = ""; SortedDictionary <string, string> sPara = GetRequestPost(Request); if (sPara.Count > 0)//判断是否有带返回参数 { Notify aliNotify = new Notify(); bool verifyResult = aliNotify.Verify(sPara, Request.Form["notify_id"], Request.Form["sign"]); if (verifyResult)//验证成功 { AliPayReturnModel aliPayReturn = new AliPayReturnModel(Request); if (aliPayReturn.Trade_status == "TRADE_FINISHED" || aliPayReturn.Trade_status == "TRADE_SUCCESS") { //对返回的结果进行处理 msg = method(aliPayReturn); } else { //Tools.Tool.Log.WritePurWeb("无效支付宝状态"); msg = "fail"; } } else//验证失败 { msg = "trade_status=" + Request.Form["trade_status"]; } } else { // Tools.Tool.Log.WritePurWeb("无通知参数"); msg = "无通知参数"; } return(msg); }
/// <summary> /// 处理支付同步返回的信息(主要是支付成功后返回页面) /// 创建人:孙佳杰 时间:2015.1.16 /// </summary> /// <param name="method">订单处理逻辑</param> /// <param name="Request">当前请求对象</param> /// <returns></returns> public static string ReturnAction(Func <AliPayReturnModel, AliPayAfterResultStatus> method, System.Web.HttpRequest Request) { SortedDictionary <string, string> sPara = GetRequestGet(Request); string returnResult = string.Empty; //返回结果 if (sPara.Count > 0) //判断是否有带返回参数 { Notify aliNotify = new Notify(); bool verifyResult = aliNotify.Verify(sPara, Request.QueryString["notify_id"], Request.QueryString["sign"]); if (verifyResult)//验证成功 { AliPayReturnModel aliPayReturn = new AliPayReturnModel(Request); if (aliPayReturn.Trade_status == "TRADE_FINISHED" || aliPayReturn.Trade_status == "TRADE_SUCCESS") { //对返回的结果进行处理 returnResult = method(aliPayReturn).ToString(); } else { return(AliPayAfterResultStatus.支付宝返回数据错误.ToString()); } } else//验证失败 { returnResult = AliPayAfterResultStatus.验证失败.ToString(); } } else { returnResult = AliPayAfterResultStatus.无返回参数.ToString(); } return(returnResult); }
public void AlipayNotify() { AliPayReturnModel payResult = new AliPayReturnModel(); HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"]; //获取传统context HttpRequestBase request = context.Request; //定义传统request对象 var result = this._aliPay.VerfyNotify(request, out payResult); }
private bool Verify(HttpRequestBase request, NameValueCollection requestVal, out AliPayReturnModel model) { bool result = false; SortedDictionary <string, string> sortedDic = new SortedDictionary <string, string>(); foreach (var item in requestVal.AllKeys) { if (item.ToLower() != "sign" && item.ToLower() != "sign_type" && !string.IsNullOrEmpty(item)) { sortedDic.Add(item, requestVal[item]); } } string requestSign = requestVal["sign"]; string requestSigntype = requestVal["sign_type"]; string param = CreateURLParamString(sortedDic); EnumSignType signType = requestSigntype == "MD5" ? EnumSignType.MD5 : requestSigntype == "RSA" ? EnumSignType.RSA : EnumSignType.MD5; if (signType == EnumSignType.MD5) { string sign = BuildRequestsign(param, signType); if (requestSign.Equals(sign)) { result = true; } } else { result = RSAFromPkcs8.verify(param, requestSign, AlipayConfig.ALIPay_RSA_ALI_PUBLICKEY, "utf-8"); } string responseText = GetResponseTxt(requestVal["notify_id"]); bool resultVal = result && responseText == "true"; if (resultVal) { model = new AliPayReturnModel() { OutTradeNo = request.Form["out_trade_no"], TradeNo = request.Form["trade_no"], TradeStatus = request.Form["trade_status"] }; decimal total_fee; decimal.TryParse(request.Form["total_fee"], out total_fee); model.TotalFee = total_fee; } else { model = null; } return(resultVal); }
public bool VerfyNotify(HttpRequestBase request, out AliPayReturnModel model) { var requestVal = request.Form; return(Verify(request, requestVal, out model)); }
public bool VerifyReturnURL(HttpRequestBase request, out AliPayReturnModel model) { var requestVal = request.QueryString; return(Verify(request, requestVal, out model)); }