/// <summary> /// 通知业务系统支付结果 /// </summary> /// <param name="resultInfo">支付结果记录</param> /// <param name="requestInfo">支付请求记录</param> /// <returns></returns> public virtual ExecuteResult NotifyBack(PayResultInfo resultInfo, PayRequestInfo requestInfo) { var result = new ExecuteResult() { Status = ResultStatus.Failure }; //支付结果记录对象无效,则不执行 if (resultInfo == null || resultInfo.SysNo <= 0) { result.Message = "支付结果记录对象无效"; return(result); } //支付请求记录对象无效,则不执行 if (requestInfo == null || requestInfo.SysNo <= 0) { result.Message = "支付请求记录对象无效"; return(result); } //支付结果记录与支付请求记录不对应,则不执行 if (requestInfo.SysNo != resultInfo.RequestSysNo) { result.Message = "支付结果记录与支付请求记录不对应"; return(result); } //支付结果记录未成功执行,或者已通知,则不执行 if (resultInfo.ExecuteResult != (int)ResultStatus.Success || resultInfo.NotifyStatus == (int)AppEnum.NotifyStatus.Finished) { result.Message = "支付结果记录未成功执行或已通知成功"; return(result); } //支付请求记录中不存在有效的通知地址,则不执行 if (!requestInfo.NotifyUrl.IsUrl()) { result.Message = "支付请求记录中不存在有效的通知地址"; return(result); } var notifyInfo = this.GetPayNotifyInfo(resultInfo); var setting = JsonHelper.GetDefaultSettings(); setting.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore; string data = JsonHelper.Serialize(notifyInfo, setting); string sign = SignManager.CreateSign(requestInfo.AppId, data).Data; string param = string.Format("appId={0}&sign={1}&data={2}", requestInfo.AppId, sign, data); var response = HttpHelper.HttpRequest("POST", requestInfo.NotifyUrl, param, 10000); string status = JsonHelper.GetJsonNode(response, "status"); string msg = JsonHelper.GetJsonNode(response, "msg"); result.Message = msg; var backInfo = new NotifyBackInfo() { ResultSysNo = resultInfo.SysNo, Status = (int)AppEnum.GlobalStatus.Invalid, Msg = msg, CreateTime = DateTime.Now, ResponseData = response, }; if (status == "1") { backInfo.Status = (int)AppEnum.GlobalStatus.Valid; resultInfo.NotifyStatus = (int)AppEnum.NotifyStatus.Finished; PayResultDAL.Update(resultInfo); result.Status = ResultStatus.Success; } PayResultDAL.InsertNotifyBack(backInfo); return(result); }
/// <summary> /// 通知业务系统支付成功 /// </summary> /// <param name="payResult"></param> /// <param name="payRequest"></param> /// <returns></returns> public static bool NotifyBack(PayResultInfo payResult, PayRequestInfo payRequest) { //支付结果记录对象无效,则不执行 if (payResult == null || payResult.SysNo <= 0) { return(false); } //支付请求记录对象无效,则不执行 if (payRequest == null || payRequest.SysNo <= 0) { return(false); } //支付结果记录与支付请求记录不对应,则不执行 if (payRequest.SysNo != payResult.RequestSysNo) { return(false); } //支付结果记录未成功执行,或者已通知,则不执行 if (payResult.ExecuteResult != (int)ResultStatus.Success || payResult.NotifyStatus != (int)AppEnum.GlobalStatus.Invalid) { return(false); } //支付请求记录中不存在有效的通知地址,则不执行 if (!payRequest.NotifyUrl.IsUrl()) { return(false); } var payNotify = new PayNotifyInfo() { OrderId = payResult.OrderId, TradeNo = payResult.TradeNo, PaymentAmt = payResult.PaymentAmt.ToString(), Result = ((int)ResultStatus.Success).ToString(), }; string data = JsonHelper.Serialize(payNotify); string sign = SignManager.CreateSign(data).Data; string param = "sign=" + sign; param += "&data=" + data; var response = HttpHelper.HttpRequest("POST", payRequest.NotifyUrl, param, 10000); string status = JsonHelper.GetJsonNode(response, "status"); string msg = JsonHelper.GetJsonNode(response, "msg"); var notifyBack = new NotifyBackInfo() { ResultSysNo = payResult.SysNo, Status = (int)AppEnum.GlobalStatus.Valid, CreateTime = DateTime.Now, ResponseData = response, }; if (status != "1") { notifyBack.Status = (int)AppEnum.GlobalStatus.Invalid; notifyBack.Msg = msg; } else { payResult.NotifyStatus = (int)AppEnum.GlobalStatus.Valid; PayResultDAL.Update(payResult); } PayResultDAL.InsertNotifyBack(notifyBack); bool result = notifyBack.Status == (int)AppEnum.GlobalStatus.Valid; return(result); }