public void TestParseTransactionNotificationRequest() { string encrypedReq1 = "MjY3MDk5NjMzMjE4|Aa/qpl2e+s6+kfKQY0H9rYQTbA6n0o1k/JlBTQezC81hXdIXjZLohIF1lOGTtC6q1luGeXrSHHxusCZdg5gHCz79gEQkdq4eHWN6aZPryu/DbvNv7jXVxnors+ZqFqJE2zeWp0Lr5Fu9S3zXl0w7unAxfz766Kltruy+4MXYKr4=|oIUNRpv1nzvfQQunMn70rG260iepVSeX8UmvVFxewcSjdiFPEoqP1LcMevlQBj+6wk8yKWtH8V3A51/JVgA4mWQoqYtaSrsne5wUN0wvb8ejbjgSiyu00wg3EDHSW+enaHNg399iPu+DQ929XVGyHvDYrpXqv3eZwROP+LKZ/2QR5zGZGqPYxiZu6N1rAyK4ZqZvabWLC6rlDLnmA23lXXL4eGhRixbKSmXuTJ7AsIsQbVEi5mkIMM5LIncQDVUqmYzLPNQHESv07WoWjzAb01dox1//kxzVj1k90p7uPaczkhjort48xdoasbqeixSMVA49oa52qgFkDPUTbxioOVdox1//kxzV47Uzt3uucC0ocl1rZ3TPEV0L7rqTMTY2m+KOz89IscKqR7zrrDujO+qPccNnwwSG0Os8Aeb0DoeVhiyjpWW4lrErBXrLWx/HdbHN9FH31ayW2PFVxfFzysochNP2S/1ONE1bx6WsJ2VaUoGP4ptUTzRr7QOQKKfDBUQ/uOZk3QD5MYUy/JQsgDfv2YNd17NV1zESRTLwDE5sxg+BeGVAytstx6xPeBveg0PdvV1Rsh6p8/RQBVIuVxlC4kYCUfMHjiqueqWn4ovuFnT3e1qzZJ10PfG44mwdJrLSNhTPc+fc32ObyDWV4pcRqHqTOVHC8wI895/+IwpvSnVFU1KXnyay0jYUz3PndSO7nNl7cLrZMDmrTpmgJyhv/Pz3Jma7XZEYHjzXrVUUb3uOJmyEgtLSb86Nxext5aZLdb2GG9vgDCZaa9izZZkHmP5I9erDrlU+4B4wiH0="; var req1 = IVRGateway.ParseTransactionNotificationRequest("D:/cer/ivr.cer", encrypedReq1); Assert.IsTrue(req1 != null); }
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 void ProcessRequest(HttpContext context) { using (StreamReader sr = new StreamReader(context.Request.InputStream)) { try { //读取支付平台发送的交易通知密文 string strReq = sr.ReadToEnd(); Loggers.Debug(new DebugLogInfo() { Message = "[IVR]Encrypted Transaction Notification Request=" + strReq }); //解析交易通知密文,获得交易通知请求的内容 var req = IVRGateway.ParseTransactionNotificationRequest(ConfigurationManager.AppSettings["IVRDecryptCertificateFilePath"], strReq); Loggers.Debug(new DebugLogInfo() { Message = "[IVR]Decrypted Transaction Notification Request=" + req.GetContent() }); if (req.IsPayOK) {//用户支付成功 try { //TODO:业务系统自身的订单处理逻辑(通常为:更新订单状态为支付成功) //业务处理完成后,告诉支付平台处理成功 var rsp = TransactionNotificationResponse.OK.GetContent(); Loggers.Debug(new DebugLogInfo() { Message = string.Format("[IVR]Transaction Notification Response={0}", rsp) }); context.Response.Write(rsp); } 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); } } else {//用户支付失败 try { //TODO:业务系统自身的订单处理逻辑(通常为:更新订单状态为支付失败) //业务处理完成后,告诉支付平台处理成功 var rsp = TransactionNotificationResponse.OK.GetContent(); Loggers.Debug(new DebugLogInfo() { Message = string.Format("[IVR]Transaction Notification Response={0}", rsp) }); context.Response.Write(rsp); } 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); } } } catch (Exception ex) {//出错 Loggers.Exception(new ExceptionLogInfo(ex)); context.Response.Write(TransactionNotificationResponse.FAILED.GetContent()); } } }