public bool ClientCompleteServiceOrder(CompleteServiceOrder order, out string msg) { LogHelper.Logger.Debug("订单信息:" + order.ToJson()); var orderId = order.OrderID; var orderInfo = _userPayOrdeRepository.FirstOrDefault(p => p.Id == orderId); if (orderInfo == null) { msg = "没有查询到相关的订单"; return(false); } LogHelper.Logger.Debug("查询到的订单信息为:" + orderInfo.ToJson()); if (orderInfo.State == 2) { msg = "充值成功,您可以登陆代理系统查看您的充值金额"; return(true); } var query = _orderPolicy.Orderquery(string.Format("{0}{1}", WxPayConfig.MCHID, order.OrderID), OrderType.OutTradeNo); if (query == null) { LogHelper.Logger.Error("没有查询到相关的订单信息"); orderInfo.State = 3; orderInfo.PayState = "FAIL"; orderInfo.UpdateTime = DateTime.Now; _userPayOrdeRepository.Update(orderInfo); msg = "没有查询到相关的订单信息"; return(false); } else { LogHelper.Logger.Debug(query.ToJson()); if (query.IsSet("trade_state") && query.GetValue("trade_state").ToString() == "SUCCESS") { // var orderState = _purchaseServiceRepository.CompleteServiceOrder(new CompleteServiceOrder() // { // OrderID = orderId, // Cost = (double)Convert.ToInt32(query.GetValue("total_fee")) / 100, // NewID = OrderHelper.GenerateNewId(), // PayState = query.GetValue("trade_state").ToString(), // PayExtendInfo = query.ToXml(), // PayOrderID = query.GetValue("transaction_id").ToString(), // Remarks = "微信公众号支付" // }); var orderState = CompleteRechargeOrder(query, out msg); return(orderState); } else { msg = "支付失败"; return(false); } } }
public int ClientCompleteServiceOrder(CompleteServiceOrder order) { LogHelper.Logger.Debug("订单信息:" + order.ToJson()); var orderId = order.OrderID; var orderInfo = _userPayOrdeRepository.FirstOrDefault(p => p.Id == orderId); if (orderInfo == null) { return(-2); } LogHelper.Logger.Debug("查询到的订单信息为:" + orderInfo.ToJson()); if (orderInfo.State == 2) { return(0); } var query = _orderPolicy.Orderquery(string.Format("{0}{1}", WxPayConfig.MCHID, order.OrderID), OrderType.OutTradeNo); if (query == null) { LogHelper.Logger.Error("没有查询到相关的订单信息"); _purchaseServiceRepository.UpdateServiceOrder(new UpdateServiceOrder() { ID = orderId, State = 3, PayState = "FAIL", }); return(-1); } else { LogHelper.Logger.Debug(query.ToJson()); if (query.IsSet("trade_state") && query.GetValue("trade_state").ToString() == "SUCCESS") { var orderState = _purchaseServiceRepository.CompleteServiceOrder(new CompleteServiceOrder() { OrderID = orderId, Cost = (double)Convert.ToInt32(query.GetValue("total_fee")) / 100, NewID = OrderHelper.GenerateNewId(), PayState = query.GetValue("trade_state").ToString(), PayExtendInfo = query.ToXml(), PayOrderID = query.GetValue("transaction_id").ToString(), Remarks = "微信公众号支付" }); return(orderState); } else { return(-1); } } }
private void WechatPayOrderService(ref int count1, ref int count2, UserPayOrderInfo order) { var orderId = WxPayConfig.MCHID + order.Id.Trim(); var payData = _orderPolicy.Orderquery(orderId, OrderType.OutTradeNo); if (payData.GetValue("return_code").ToString() != "SUCCESS" || payData.GetValue("result_code").ToString() != "SUCCESS") { //订单查询失败, order.UpdateTime = DateTime.Now; order.PayExtendInfo = "未查询到订单的支付信息,直接关闭该订单"; order.State = 3; order.PayState = "NOPAY"; //_purchaseService.FailServiceOrder(new UpdateServiceOrder() //{ // ID = order.Id, // PayState = payData.GetValue("return_code").ToString(), // PayExtendInfo = "未查询到订单,直接关闭该订单", // State = 3, //}); _userpayOrderRepository.Update(order); count1++; } else { if (order.GoodsType == 0) { string msg = string.Empty; _rechargeService.CompleteRechargeOrder(payData, out msg); LogHelper.Logger.Info(msg); } else { _purchaseService.CompleteServiceOrder(payData); } count2++; } }
public HttpResponseMessage PurchaseService() { LogHelper.Logger.Debug("开始回调支付接口"); Senparc.Weixin.MP.TenPayLibV3.ResponseHandler payNotifyRepHandler = new Senparc.Weixin.MP.TenPayLibV3.ResponseHandler(HttpContext.Current); payNotifyRepHandler.SetKey(WxPayConfig.KEY); string return_code = payNotifyRepHandler.GetParameter("return_code"); //返回状态码 string return_msg = payNotifyRepHandler.GetParameter("return_msg"); //返回信息 string xml = string.Format(@"", return_code, return_msg); var res = Request.CreateResponse(HttpStatusCode.OK); // 通信失败 if (return_code.ToUpper() != "SUCCESS") { //支付失败调用 if (string.IsNullOrEmpty(payNotifyRepHandler.GetParameter("out_trade_no"))) { _purchaseAppService.FailServiceOrder(new UpdateServiceOrder() { ID = payNotifyRepHandler.GetParameter("out_trade_no").Substring(10), PayState = payNotifyRepHandler.GetParameter("return_code"), PayExtendInfo = payNotifyRepHandler.ParseXML(), State = 3, }); } xml = "<xml>" + "<return_code><![CDATA[FAIL]]></return_code>" + "<return_msg><![CDATA[Fail]]></return_msg>" + "</xml>"; Logger.Error("交易失败"); res.Content = new StringContent(xml, Encoding.UTF8, "text/xml"); return(res); } if (!payNotifyRepHandler.IsTenpaySign()) { xml = "<xml>" + "<return_code><![CDATA[FAIL]]></return_code>" + "<return_msg><![CDATA[sign is error]]></return_msg>" + "</xml>"; LogHelper.Logger.Debug("签名验证未通过"); res.Content = new StringContent(xml, Encoding.UTF8, "text/xml"); return(res); } LogHelper.Logger.Debug(payNotifyRepHandler.GetParameter("out_trade_no").Substring(10) + "支付并且验证成功!"); var transactionId = payNotifyRepHandler.GetParameter("transaction_id"); if (string.IsNullOrEmpty(transactionId)) { xml = "<xml>" + "<return_code><![CDATA[FAIL]]></return_code>" + "<return_msg><![CDATA[微信支付单不存在]]></return_msg>" + "</xml>"; LogHelper.Logger.Error("微信支付单不存在"); res.Content = new StringContent(xml, Encoding.UTF8, "text/xml"); return(res); } var payData = _orderPolicy.Orderquery(transactionId, OrderType.TransactionId); Logger.Debug(payData.ToJson()); if (payData.GetValue("return_code").ToString() != "SUCCESS" || payData.GetValue("result_code").ToString() != "SUCCESS") { //订单查询失败,则立即返回结果给微信支付后台 xml = "<xml>" + "<return_code><![CDATA[FAIL]]></return_code>" + "<return_msg><![CDATA[订单查询失败]]></return_msg>" + "</xml>"; LogHelper.Logger.Error("订单查询失败"); res.Content = new StringContent(xml, Encoding.UTF8, "text/xml"); return(res); } var result = _purchaseAppService.CompleteServiceOrder(payData); if (result.Code == ResultCode.Success) { xml = "<xml>" + "<return_code><![CDATA[SUCCESS]]></return_code>" + "<return_msg><![CDATA[OK]]></return_msg>" + "</xml>"; LogHelper.Logger.Debug("交易成功!"); } else { xml = "<xml>" + "<return_code><![CDATA[FAIL]]></return_code>" + "<return_msg><![CDATA[" + result.Msg + "]]></return_msg>" + "</xml>"; LogHelper.Logger.Debug(string.Format("{0}!订单号为{1},交易单号为:{2}", result.Msg, payNotifyRepHandler.GetParameter("out_trade_no").Substring(10), payNotifyRepHandler.GetParameter("transaction_id"))); } res.Content = new StringContent(xml, Encoding.UTF8, "text/xml"); LogHelper.Logger.Debug(return_code + return_msg); return(res); }