/* * <xml><appid><![CDATA[wxb4f8f3d799d22f03]]></appid> * <attach><![CDATA[测试数据]]></attach> * <bank_type><![CDATA[CFT]]></bank_type> * <cash_fee><![CDATA[1]]></cash_fee> * <fee_type><![CDATA[CNY]]></fee_type> * <is_subscribe><![CDATA[Y]]></is_subscribe> * <mch_id><![CDATA[1264926201]]></mch_id> * <nonce_str><![CDATA[rdwbEb2FXXmV7LBF]]></nonce_str> * <openid><![CDATA[oY-Cqs7wZ6p_Cq_0AAP2QHLhANRc]]></openid> * <out_trade_no><![CDATA[126492620120160426005955291]]></out_trade_no> * <result_code><![CDATA[SUCCESS]]></result_code> * <return_code><![CDATA[SUCCESS]]></return_code> * <sign><![CDATA[C251718418AFA3FDEB764E258F220340]]></sign> * <time_end><![CDATA[20160426010056]]></time_end> * <total_fee>1</total_fee> * <trade_type><![CDATA[NATIVE]]></trade_type> * <transaction_id><![CDATA[4008492001201604265225452570]]></transaction_id> * </xml> */ #endregion public void ProcessRequest(HttpContext context) { WxPayData res = new WxPayData(); try { context.Response.ContentType = "text/plain"; System.IO.Stream s = context.Request.InputStream; int count = 0; byte[] buffer = new byte[1024]; StringBuilder builder = new StringBuilder(); while ((count = s.Read(buffer, 0, 1024)) > 0) { builder.Append(Encoding.UTF8.GetString(buffer, 0, count)); } s.Flush(); s.Close(); s.Dispose(); Loggers.Debug(new DebugLogInfo() { Message = string.Format("Receive data from WeChat : {0}", builder.ToString()) }); string rspStr = builder.ToString(). Replace("<![CDATA[", "").Replace("]]>", ""); XmlDocument doc = new XmlDocument(); doc.LoadXml(rspStr); string orderId = doc.GetElementsByTagName("out_trade_no")[0].InnerText; string resultcode = doc.GetElementsByTagName("result_code")[0].InnerText; string openId = doc.GetElementsByTagName("openid")[0].InnerText; AppOrderBLL bll = new AppOrderBLL(new Utility.BasicUserInfo()); AppOrderEntity appOrder = bll.QueryByEntity(new AppOrderEntity() { AppOrderID = orderId, }, null).FirstOrDefault(); if (appOrder != null && resultcode == "SUCCESS" && appOrder.Status != 2) { appOrder.Status = 2; new RechargeBLL().RechargeTonysCardAct2(appOrder); } if (appOrder != null && !(appOrder.IsNotified ?? false)) { try { string msg; if (NotifyHandler.Notify(appOrder, out msg, true)) { appOrder.IsNotified = true; } else { appOrder.NextNotifyTime = DateTime.Now.AddMinutes(1); } //通知完成,通知次数+1 appOrder.NotifyCount = (appOrder.NotifyCount ?? 0) + 1; bll.Update(appOrder); } catch (Exception ex) { Loggers.Exception(new ExceptionLogInfo(ex)); res.SetValue("return_code", "FAIL"); res.SetValue("return_msg", "FAIL"); } } NotifyHandler.NotifyTFSaveWxVipInfo(appOrder.AppOrderID, appOrder.AppClientID, openId); if ((appOrder.IsNotified ?? false) && appOrder.Status == 2) { res.SetValue("return_code", "SUCCESS"); res.SetValue("return_msg", "OK"); } } catch (Exception ex) { res.SetValue("return_code", "FAIL"); res.SetValue("return_msg", ex.Message); } context.Response.Write(res.ToXml()); context.Response.End(); }
/// <summary> /// 使用汇付储值卡支付订单 /// </summary> /// <param name="request"></param> /// <returns></returns> internal static PrePaidCardPayRD PrePaidCardPay(TradeRequest request) { PrePaidCardPayRD rd = new PrePaidCardPayRD(); var rp = request.GetParameter <PrePaidCardPayRP>(); var userInfo = request.GetUserInfo(); if (rp == null || string.IsNullOrEmpty(rp.OrderId) || string.IsNullOrEmpty(rp.CardNo) || string.IsNullOrEmpty(rp.Password)) { rd.errcode = 40000; rd.errmsg = "参数错误"; return(rd); } try { var appBll = new AppOrderBLL(userInfo); var appOrder = appBll.GetAppOrderByAppOrderId(rp.OrderId); if (appOrder == null) { rd.errcode = 40001; rd.errmsg = "未找到支付订单,请重试!"; return(rd); } if (CacheOrder.Contains(rp.OrderId)) { rd.errcode = 40003; rd.errmsg = "订单支付中,请稍后重试"; return(rd); } CacheOrder.Add(rp.OrderId); // 限制重复提交支付,只针对单服务器程序,多服务请走第三方缓存 if (appOrder.Status == 2) { rd.errcode = 0; rd.errmsg = "该订单已支付"; return(rd); } string msg = string.Empty; var result = Consumption(rp, appOrder, out msg); if (result.rspCd == "0000") { rd.errcode = 200; rd.errmsg = "success"; AppOrderBLL bll = new AppOrderBLL(new Utility.BasicUserInfo()); if (!(appOrder.IsNotified ?? false)) { Task.Factory.StartNew(() => {//起一个新线程通知业务系统处理订单 try { string errmsg; if (NotifyHandler.Notify(appOrder, out errmsg)) { appOrder.IsNotified = true; } else { appOrder.NextNotifyTime = DateTime.Now.AddMinutes(1); } //通知完成,通知次数+1 appOrder.NotifyCount = (appOrder.NotifyCount ?? 0) + 1; bll.Update(appOrder); } catch (Exception ex) { Loggers.Exception(new ExceptionLogInfo(ex)); } }); } } else { rd.errcode = 40002; rd.errmsg = result.rspDesc; } } catch (Exception ex) { Loggers.Debug(new DebugLogInfo() { Message = ex.Message }); } finally { CacheOrder.Remove(rp.OrderId); } return(rd); }
public void ProcessRequest(HttpContext context) { string res = "{\"CODE\": \"00\", \"MSG\": \"OK\"}";// Y/N 接收成功或失败 try { context.Response.ContentType = "application/json"; #region 获取流数据 System.IO.Stream s = context.Request.InputStream; int count = 0; byte[] buffer = new byte[1024]; StringBuilder builder = new StringBuilder(); while ((count = s.Read(buffer, 0, 1024)) > 0) { builder.Append(Encoding.UTF8.GetString(buffer, 0, count)); } s.Flush(); s.Close(); s.Dispose(); #endregion string rspStr = builder.ToString(); //Task.Factory.StartNew(() => //{ // HttpHelper.SendSoapRequest(DateTime.Now + " 收到旺财支付回调:" + rspStr, "http://182.254.242.12:56789/log/push/"); //}); Loggers.Debug(new DebugLogInfo() { Message = string.Format("Receive data from PALifePay : {0}", rspStr) }); LifePayRP req = rspStr.DeserializeJSONTo <LifePayRP>(); string orderId = req.merOrderNo; string resultcode = req.notifyType; string openId = req.openId; AppOrderBLL bll = new AppOrderBLL(new Utility.BasicUserInfo()); AppOrderEntity appOrder = bll.QueryByEntity(new AppOrderEntity() { AppOrderID = orderId, }, null).FirstOrDefault(); // 00 成功 01 失败 02 其他 if (appOrder != null && resultcode == "00" && appOrder.Status != 2) { appOrder.Status = 2; } if (appOrder != null && !(appOrder.IsNotified ?? false)) { try { string msg; Hashtable ht = new Hashtable(); ht.Add("serialNo", req.serialNo); // 异步通知cpos if (NotifyHandler.Notify(appOrder, out msg, ht)) { appOrder.IsNotified = true; } else { appOrder.NextNotifyTime = DateTime.Now.AddMinutes(1); } //通知完成,通知次数+1 appOrder.NotifyCount = (appOrder.NotifyCount ?? 0) + 1; bll.Update(appOrder); } catch (Exception ex) { Loggers.Exception(new ExceptionLogInfo(ex)); } } if ((appOrder.IsNotified ?? false) && appOrder.Status == 2) { res = "{\"CODE\": \"00\", \"MSG\": \"OK\"}";// } } catch (Exception ex) { res = "{\"CODE\": \"01\", \"MSG\": \"" + ex + "\"}";// } Loggers.Debug(new DebugLogInfo() { Message = string.Format("Response data from PALifePay : {0}", res) }); context.Response.Write(res); context.Response.End(); }