public override bool Process(PayChannelEntity pChannel, HttpContext context, out Entity.AppOrderEntity entity) { using (StreamReader sr = new StreamReader(context.Request.InputStream)) { try { #region Channel var UnionIVRChannel = pChannel.ChannelParameters.DeserializeJSONTo <UnionPayChannel>(); #endregion //读取支付平台发送的交易通知密文 string strReq = sr.ReadToEnd(); Loggers.Debug(new DebugLogInfo() { Message = "[IVR]Encrypted Transaction Notification Request=" + strReq }); //解析交易通知密文,获得交易通知请求的内容 var req = IVRGateway.ParseTransactionNotificationRequest(UnionIVRChannel.DecryptCertificateFilePath, strReq); Loggers.Debug(new DebugLogInfo() { Message = "[IVR]Decrypted Transaction Notification Request=" + req.GetContent() }); AppOrderBLL bll = new AppOrderBLL(new Utility.BasicUserInfo()); entity = bll.GetByID(req.MerchantOrderID); if (req.IsPayOK) {//用户支付成功 try { //TODO:业务系统自身的订单处理逻辑(通常为:更新订单状态为支付成功) #region 更新订单状态 entity.Status = 2; entity.ErrorMessage = ""; bll.Update(entity); #endregion //业务处理完成后,告诉支付平台处理成功 var rsp = TransactionNotificationResponse.OK.GetContent(); Loggers.Debug(new DebugLogInfo() { Message = string.Format("[IVR]Transaction Notification Response={0}", rsp) }); context.Response.Write(rsp); return(true); } catch (Exception ex) {//业务处理时如果出现异常 //记录日志 Loggers.Exception(new ExceptionLogInfo(ex)); //告诉支付前置,业务处理失败,支付平台会在一定的时间范围内重发交易通知 var rsp = TransactionNotificationResponse.FAILED.GetContent(); Loggers.Debug(new DebugLogInfo() { Message = string.Format("[IVR]Transaction Notification Response={0}", rsp) }); context.Response.Write(rsp); return(false); } } else {//用户支付失败 try { //TODO:业务系统自身的订单处理逻辑(通常为:更新订单状态为支付失败) entity.ErrorMessage = req.PayFailedReason; bll.Update(entity); //业务处理完成后,告诉支付平台处理成功 var rsp = TransactionNotificationResponse.OK.GetContent(); Loggers.Debug(new DebugLogInfo() { Message = string.Format("[IVR]Transaction Notification Response={0}", rsp) }); context.Response.Write(rsp); return(false); } catch (Exception ex) {//业务处理时如果出现异常 //记录日志 Loggers.Exception(new ExceptionLogInfo(ex)); //告诉支付前置,业务处理失败,支付平台会在一定的时间范围内重发交易通知 var rsp = TransactionNotificationResponse.FAILED.GetContent(); Loggers.Debug(new DebugLogInfo() { Message = string.Format("[IVR]Transaction Notification Response={0}", rsp) }); context.Response.Write(rsp); return(false); } } } catch (Exception ex) {//出错 entity = null; Loggers.Exception(new ExceptionLogInfo(ex)); context.Response.Write(TransactionNotificationResponse.FAILED.GetContent()); return(false); } } }
public override bool Process(PayChannelEntity pChannel, HttpContext pContext, out Entity.AppOrderEntity pEntity) { pContext.Response.ContentType = "text/plain"; try { var orderId = pContext.Request["outTradeNo"]; var outTradeNo = pContext.Request.QueryString["outTradeNo"]; Loggers.Debug(new DebugLogInfo() { Message = "outTradeNo:" + outTradeNo }); Loggers.Debug(new DebugLogInfo() { Message = "ChannelID:104&OrderId:" + orderId }); AppOrderBLL bll = new AppOrderBLL(new Utility.BasicUserInfo()); //根据订单号从数据库中找到记录 pEntity = bll.GetByID(orderId); #region 更新订单状态 pEntity.Status = 2; pEntity.ErrorMessage = ""; bll.Update(pEntity); #endregion return(true); } catch (Exception ex) { pEntity = null; Loggers.Exception(new ExceptionLogInfo(ex)); return(false); } }
public override bool Process(PayChannelEntity pChannel, HttpContext pContext, out Entity.AppOrderEntity pEntity) { pContext.Response.ContentType = "text/plain"; try { //组织支付平台回调时回传的参数集 Dictionary <string, string> sPara = new Dictionary <string, string>(); foreach (var item in pContext.Request.Form.AllKeys) { sPara[item] = pContext.Request.Form[item]; } //构建通知对象 OfflineNotify notify = new OfflineNotify(); notify.Load(sPara); Loggers.Debug(new DebugLogInfo() { Message = "交易状态:" + notify.TradeStatus + Environment.NewLine + notify.ToJSON() }); //根据通知结果更新订单 AppOrderBLL bll = new AppOrderBLL(new Utility.BasicUserInfo()); //根据订单号从数据库中找到记录 pEntity = bll.GetByID(notify.OutTradeNo); Loggers.Debug(new DebugLogInfo() { Message = "OutTradeNo:" + notify.OutTradeNo + ", TradeStatus:" + notify.TradeStatus + ", pEntity:" + pEntity.ToJSON() }); if (notify.TradeStatus == TradeStatus.TRADE_FINISHED.ToString() || notify.TradeStatus == TradeStatus.TRADE_SUCCESS.ToString()) { #region 更新订单状态 pEntity.Status = 2; pEntity.ErrorMessage = ""; bll.Update(pEntity); #endregion pContext.Response.Write("success"); Loggers.Debug(new DebugLogInfo() { Message = "更新订单状态成功!" }); return(true); } else { pEntity.ErrorMessage = notify.TradeStatus; bll.Update(pEntity); pContext.Response.Write("fail"); Loggers.Debug(new DebugLogInfo() { Message = "更新订单状态失败:" + notify.TradeStatus }); return(false); } } catch (Exception ex) { pContext.Response.Write("fail"); pEntity = null; Loggers.Exception(new ExceptionLogInfo() { ErrorMessage = ex.Message }); return(false); } }
public override bool Process(PayChannelEntity pChannel, HttpContext context, out Entity.AppOrderEntity entity) { context.Response.ContentType = "text/plain"; try { var channel = pChannel.ChannelParameters.DeserializeJSONTo <AliPayChannel>(); Dictionary <string, string> sPara = new Dictionary <string, string>(); foreach (var item in context.Request.Form.AllKeys) { sPara[item] = context.Request.Form[item]; } WapNotify notify = new WapNotify(); notify.Load(sPara); var data = notify.GetNotifyData(channel); Loggers.Debug(new DebugLogInfo() { Message = "交易状态:" + data.TradeStatus }); AppOrderBLL bll = new AppOrderBLL(new Utility.BasicUserInfo()); entity = bll.GetByID(data.OutTradeNo); Loggers.Debug(new DebugLogInfo() { Message = "AppOrder:" + entity.ToJSON() }); if (data.TradeStatus == TradeStatus.TRADE_FINISHED.ToString() || data.TradeStatus == TradeStatus.TRADE_SUCCESS.ToString()) { #region 分润 //PayChannelBLL pbll = new PayChannelBLL(new Utility.BasicUserInfo()); //var channel = pbll.GetByID(entity.PayChannelID).ChannelParameters.DeserializeJSONTo<AliPayWapChannel>(); //RoyaltyRequest royaltyrequest = new RoyaltyRequest() //{ // TradeNo = data.TradeNo, // OutTradeNo = data.OutTradeNo, // OutBillNo = Helper.GetDataRandom(), // Partner = AliPayConfig.Partner, // RoyaltyType = "10", // RoyaltyParameters = "[email protected]^0.01^Test", //}; //if (!string.IsNullOrEmpty(channel.GetRoyaltyStr())) //{ // royaltyrequest.RoyaltyParameters = channel.GetRoyaltyStr(); //} //try //{ // var royalReaponse = AliPayWapGeteway.GetRoyaltyResponse(royaltyrequest); // Loggers.Debug(new DebugLogInfo() { Message = royalReaponse.ToJSON() }); // if (royalReaponse.IsSuccess == "T") // { // Loggers.Debug(new DebugLogInfo() { Message = "分润成功" }); // } // else // { // Loggers.Debug(new DebugLogInfo() { Message = "分润失败" }); // } // context.Response.Write("successss"); // Loggers.Debug(new DebugLogInfo() { Message = "交易成功" }); //} //catch (Exception ex) //{ // context.Response.Write("fail"); // Loggers.Exception(new ExceptionLogInfo(ex)); //} #endregion #region 更新订单状态 entity.Status = 2; entity.ErrorMessage = ""; bll.Update(entity); Loggers.Debug(new DebugLogInfo() { Message = "更新订单状态成功!" }); #endregion context.Response.Write("success"); return(true); } else { entity.ErrorMessage = data.TradeStatus; bll.Update(entity); context.Response.Write("fail"); return(false); } } catch (Exception ex) { Loggers.Exception(new ExceptionLogInfo(ex)); entity = null; context.Response.Write("fail"); return(false); } }
public override bool Process(PayChannelEntity pChannel, HttpContext pContext, out Entity.AppOrderEntity pEntity) { pContext.Response.ContentType = "text/plain"; try { //var WXChannel = pChannel.ChannelParameters.DeserializeJSONTo<WeiXinPayChannel>(); byte[] buffer = new byte[pContext.Request.InputStream.Length]; pContext.Request.InputStream.Read(buffer, 0, (int)pContext.Request.InputStream.Length); string str = Encoding.UTF8.GetString(buffer); Loggers.Debug(new DebugLogInfo() { Message = "WeiXinNotify:" + str }); //微信回调返回的信息*****可用于本地测试 //构建通知对象(反序列化) WeiXinPayHelper.NotifyResult result = new XmlSerializer(typeof(WeiXinPayHelper.NotifyResult)).Deserialize(new MemoryStream(Encoding.UTF8.GetBytes(str.Replace("xml>", "NotifyResult>")))) as WeiXinPayHelper.NotifyResult; Loggers.Debug(new DebugLogInfo() { Message = "交易状态:" + result.result_code + Environment.NewLine + result.ToJSON() }); //把反序列化的数据转换成json数据 //根据通知结果更新订单 AppOrderBLL bll = new AppOrderBLL(new Utility.BasicUserInfo()); Loggers.Debug(new DebugLogInfo() { Message = "WeiXinNotify_result.out_trade_no:" + result.out_trade_no }); //根据订单号从数据库中找到记录 pEntity = bll.GetByID(result.out_trade_no); if (result.result_code == "SUCCESS") { #region 更新订单状态 pEntity.Status = 2; pEntity.ErrorMessage = ""; bll.Update(pEntity); #endregion pContext.Response.Write("<xml><return_code><![CDATA[SUCCESS]]></return_code></xml>"); return(true); } else { pEntity.ErrorMessage = result.err_code_des; bll.Update(pEntity); pContext.Response.Write("<xml><return_code><![CDATA[FAIL]]></return_code></xml>"); return(false); } } catch (Exception ex) { pEntity = null; Loggers.Exception(new ExceptionLogInfo(ex)); pContext.Response.Write("<xml><return_code><![CDATA[FAIL]]></return_code></xml>"); return(false); } }