/* * <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> /// 创建交易中心支付订单AppOrder /// </summary> /// <param name="pRequest"></param> /// <returns></returns> public static CreateOrderResponse CreateOrder(TradeRequest pRequest) { var userInfo = pRequest.GetUserInfo(); CreateOrderResponse response = new CreateOrderResponse(); response.ResultCode = 0; CreateOrderParameters para = pRequest.GetParameter <CreateOrderParameters>(); Loggers.Debug(new DebugLogInfo() { Message = "业务参数:" + para.ToJSON() }); if (para == null) { throw new Exception("Parameters参数不正确"); } AppOrderBLL bll = new AppOrderBLL(userInfo); AppOrderEntity entity; #region 支付等待5秒后可再次支付 var appOrderEntity = bll.QueryByEntity(new AppOrderEntity() { ClientIP = pRequest.ClientID, AppOrderID = para.AppOrderID }, null).FirstOrDefault(); if (appOrderEntity != null) { DateTime dtNow = DateTime.Now; TimeSpan ts = dtNow - appOrderEntity.CreateTime.Value; if (ts.TotalSeconds < 5) { throw new Exception("支付已启动,请稍后再试"); } } #endregion #region 在支付中心创建订单 var tran = bll.CreateTran(); using (tran.Connection) { try { #region 除已存在的订单 bll.DeleteByAppInfo(pRequest.ClientID, para.AppOrderID, pRequest.AppID.Value, tran); #endregion #region 创建订单 entity = new AppOrderEntity() { Status = 0, MobileNO = para.MobileNO, AppClientID = pRequest.ClientID, AppUserID = pRequest.UserID, AppID = pRequest.AppID, AppOrderAmount = Convert.ToInt32(para.AppOrderAmount), AppOrderDesc = para.AppOrderDesc, AppOrderID = para.AppOrderID, AppOrderTime = para.GetDateTime(), Currency = 1, CreateBy = pRequest.UserID, PayChannelID = para.PayChannelID, LastUpdateBy = pRequest.UserID, OpenId = para.OpenId, ClientIP = para.ClientIP }; bll.Create(entity, tran);//并且生成了一个自动增长的订单标识orderid Loggers.Debug(new DebugLogInfo() { Message = "创建支付中心订单并保存数据库:" + entity.ToJSON() }); #endregion tran.Commit(); } catch { tran.Rollback(); throw; } } #endregion #region 获取Channel PayChannelBLL channelBll = new PayChannelBLL(userInfo); var channel = channelBll.GetByID(para.PayChannelID);//PayChannelID是不同商户的支付方式的标识 if (channel == null) { throw new Exception("无此ChannelID的Channel信息"); } #endregion #region 测试Channel订单价格设置为1分钱*** entity.AppOrderAmount = channel.IsTest.Value ? 1 : entity.AppOrderAmount; #endregion string url = string.Empty; if (para.AppOrderDesc != "ScanWxPayOrder") { if (para.PaymentMode == 0) { channel.PayType = 9; //新版支付宝扫码支付 } url = CreatePayRecord(response, para, bll, entity, channel); } response.PayUrl = url; response.OrderID = entity.OrderID; return(response); }
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(); }