/// <summary> /// 订单查询 /// </summary> /// <returns></returns> public ActionResult OrderQuery() { #if false string nonceStr = TenPayV3Util.GetNoncestr(); RequestHandler packageReqHandler = new RequestHandler(null); //设置package订单参数 packageReqHandler.SetParameter("appid", TenPayV3Info.AppId); //公众账号ID packageReqHandler.SetParameter("mch_id", TenPayV3Info.MchId); //商户号 packageReqHandler.SetParameter("transaction_id", ""); //填入微信订单号 packageReqHandler.SetParameter("out_trade_no", ""); //填入商家订单号 packageReqHandler.SetParameter("nonce_str", nonceStr); //随机字符串 string sign = packageReqHandler.CreateMd5Sign("key", TenPayV3Info.Key); packageReqHandler.SetParameter("sign", sign); //签名 string data = packageReqHandler.ParseXML(); var result = TenPayV3.OrderQuery(data); var res = XDocument.Parse(result); string openid = res.Element("xml").Element("sign").Value; #else var result = TenPayV3.OrderQuery(new TenPayV3OrderQueryRequestData( TenPayV3Info.AppId, TenPayV3Info.MchId, "", TenPayV3Util.GetNoncestr(), "", TenPayV3Info.Key )); string openid = result.sign; #endif return(Content(openid)); }
/// <summary> /// 订单查询 /// </summary> /// <param name="orderId"></param> /// <returns></returns> public static string OrderQuery(string orderId) { try { string nonceStr = TenPayV3Util.GetNoncestr(); RequestHandler packageReqHandler = new RequestHandler(null); //设置package订单参数 packageReqHandler.SetParameter("appid", WxOpenId); //公众账号ID packageReqHandler.SetParameter("mch_id", MchId); //商户号 packageReqHandler.SetParameter("transaction_id", ""); //填入微信订单号 packageReqHandler.SetParameter("out_trade_no", orderId); //填入商家订单号 packageReqHandler.SetParameter("nonce_str", nonceStr); //随机字符串 string sign = packageReqHandler.CreateMd5Sign("key", MchIdkey); packageReqHandler.SetParameter("sign", sign); //签名 string data = packageReqHandler.ParseXML(); var result = TenPayV3.OrderQuery(data); return(result); } catch (Exception ex) { WxWriteLogError(ex); } return(null); }
public ActionResult OrderQuery(string transactionId, string orderNumber) { string nonceStr = TenPayV3Util.GetNoncestr(); ////设置订单参数 TenPayV3OrderQueryRequestData data = new TenPayV3OrderQueryRequestData(WxOpenAppId, TenPayV3_MchId, transactionId, nonceStr, orderNumber, TenPayV3_Key); OrderQueryResult result = TenPayV3.OrderQuery(data); return(new JsonResult(HttpResult.Success(result))); }
public ActionResult OrderQuery() { string nonceStr = TenPayV3Util.GetNoncestr(); TenPayV3OrderQueryRequestData data = new TenPayV3OrderQueryRequestData(TenPayV3Info.AppId, TenPayV3Info.MchId, "微信订单号", nonceStr, "商家订单号", TenPayV3Info.Key); var result = TenPayV3.OrderQuery(data); string openid = result.openid; return(Content(openid)); }
private void OrderQueryTest(string sandBoxKey, string nonceStr, string transactionId, string outTradeNo) { var dataInfo = new TenPayV3OrderQueryRequestData(base._appId, base._mchId, transactionId, nonceStr, outTradeNo, sandBoxKey); var result = TenPayV3.OrderQuery(dataInfo); Console.WriteLine(result.ResultXml); Assert.IsTrue(result.IsReturnCodeSuccess()); //下载对账单 DownloadBillTest(sandBoxKey, nonceStr); }
public string OrderQuery() { int orderId = MyCommFun.RequestInt("orderid"); int wid = MyCommFun.RequestInt("wid"); string code = MyCommFun.RequestParam("code"); string state = MyCommFun.RequestParam("state"); BLL.wx_payment_wxpay wxPayBll = new BLL.wx_payment_wxpay(); Model.wx_payment_wxpay paymentInfo = wxPayBll.GetModelByWid(wid); BLL.wx_userweixin wx = new BLL.wx_userweixin(); Model.wx_userweixin wxModel = wx.GetModel(wid); BLL.orders otBll = new BLL.orders(); Model.orders orderEntity = otBll.GetModel(orderId, wid); litout_trade_no = orderEntity.order_no; string nonceStr = TenPayV3Util.GetNoncestr(); RequestHandler packageReqHandler = new RequestHandler(null); //设置package订单参数 packageReqHandler.SetParameter("appid", paymentInfo.appId); //公众账号ID packageReqHandler.SetParameter("mch_id", paymentInfo.partnerId); //商户号 packageReqHandler.SetParameter("transaction_id", ""); //填入微信订单号 packageReqHandler.SetParameter("out_trade_no", litout_trade_no); //填入商家订单号 packageReqHandler.SetParameter("nonce_str", nonceStr); //随机字符串 string sign = packageReqHandler.CreateMd5Sign("key", paymentInfo.paySignKey); packageReqHandler.SetParameter("sign", sign); //签名 string data = packageReqHandler.ParseXML(); var result = TenPayV3.OrderQuery(data); var res = XDocument.Parse(result); openid = res.Element("xml").Element("sign").Value; string transaction_id = res.Element("xml").Element("sign").Value; openids = res.Element("xml").Element("openid").Value; bank_type = res.Element("xml").Element("bank_type").Value; if (bank_type == "CNY") { bank_type = "钱包零钱"; } if (bank_type == "CFT") { bank_type = "银行卡"; } total_fee = res.Element("xml").Element("total_fee").Value; time_end = res.Element("xml").Element("time_end").Value; out_trade_no = res.Element("xml").Element("out_trade_no").Value; transaction_id = res.Element("xml").Element("transaction_id").Value; result_code = res.Element("xml").Element("result_code").Value; return(openid); }
/// <summary> /// 订单查询 /// </summary> /// <param name="localTradeNo">系统交易单号(预付单返回的OutTradeNo)</param> /// <returns></returns> public bool TryOrderQuery(string appId, string mchId, string mchKey, string localTradeNo, out OrderQueryResult result) { string nonceStr = TenPayV3Util.GetNoncestr(); result = TenPayV3.OrderQuery(new TenPayV3OrderQueryRequestData( appId, mchId, null, nonceStr, localTradeNo, mchKey)); Logger.LogInformation($"微信支付订单查询,out_trade_no:{localTradeNo},result:{result.ResultXml}"); return(result.IsReturnCodeSuccess() && result.IsResultCodeSuccess()); }
public IActionResult Query([FromRoute] string orderid) { IActionResult actionResult = NoContent(); string nonceStr = TenPayV3Util.GetNoncestr(); RequestHandler packageReqHandler = new RequestHandler(null); try { var _order = _context.Order.FirstOrDefault(od => od.OrderID == orderid); if (_order != null) { //设置package订单参数 packageReqHandler.SetParameter("appid", TenPayV3Info.AppId); //公众账号ID packageReqHandler.SetParameter("mch_id", TenPayV3Info.MchId); //商户号 packageReqHandler.SetParameter("transaction_id", _order.TransactionId); //填入微信订单号 packageReqHandler.SetParameter("out_trade_no", orderid); //填入商家订单号 packageReqHandler.SetParameter("nonce_str", nonceStr); //随机字符串 string sign = packageReqHandler.CreateMd5Sign("key", TenPayV3Info.Key); packageReqHandler.SetParameter("sign", sign); //签名 string data = packageReqHandler.ParseXML(); var result = TenPayV3.OrderQuery(data); OrderQueryResult orderQueryResult = new OrderQueryResult(result); _order.TransactionId = orderQueryResult.transaction_id; _order.ActPay = decimal.Parse(orderQueryResult.total_fee); var trade_state = Enum.Parse <TradeState>(orderQueryResult.trade_state); _order.OrderStatus = trade_state; _order.PayType = orderQueryResult.fee_type; _order.OpenID = orderQueryResult.openid; _context.Order.Update(_order); _context.SaveChanges(); actionResult = CreatedAtRoute("api/Orders", orderid); } else { actionResult = Ok(new { code = 1014, msg = "订单不存在" }); _logger.LogInformation($"订单{orderid}不存在"); } } catch (Exception ex) { actionResult = Ok(new { code = 1005, msg = ex.Message }); _logger.LogError(ex, "查询订单时异常" + ex.Message); } return(actionResult); }
public string OrderQuery() { //int orderId = MyCommFun.RequestInt("orderid"); //int wid = MyCommFun.RequestInt("wid"); //string code = MyCommFun.RequestParam("code"); //string state = MyCommFun.RequestParam("state"); //BLL.wx_payment_wxpay wxPayBll = new BLL.wx_payment_wxpay(); //Model.wx_payment_wxpay paymentInfo = wxPayBll.GetModelByWid(wid); //BLL.wx_userweixin wx = new BLL.wx_userweixin(); //Model.wx_userweixin wxModel = wx.GetModel(wid); //BLL.orders otBll = new BLL.orders(); //Model.orders orderEntity = otBll.GetModel(orderId, wid); //litout_trade_no = orderEntity.order_no; string nonceStr = TenPayV3Util.GetNoncestr(); RequestHandler packageReqHandler = new RequestHandler(null); //设置package订单参数 packageReqHandler.SetParameter("appid", "wx57d365e74490cf2f"); //公众账号ID packageReqHandler.SetParameter("mch_id", "1261485801"); //商户号 packageReqHandler.SetParameter("transaction_id", ""); //填入微信订单号 packageReqHandler.SetParameter("out_trade_no", "0908322087037927"); //填入商家订单号 packageReqHandler.SetParameter("nonce_str", nonceStr); //随机字符串 string sign = packageReqHandler.CreateMd5Sign("key", "Hk80BEC2ChK727L4W6845133519F3lD6"); packageReqHandler.SetParameter("sign", sign); //签名 string data = packageReqHandler.ParseXML(); var result = TenPayV3.OrderQuery(data); var res = XDocument.Parse(result); openid = res.Element("xml").Element("sign").Value; string transaction_id = res.Element("xml").Element("sign").Value; openids = res.Element("xml").Element("openid").Value; return(openid); }
/// <summary> /// 查询订单 /// </summary> /// <param name="orderno">订单号</param> /// <param name="transaction_id">微信统一下单单号</param> /// <returns></returns> public bool OrderQuery(string orderno, ref string transaction_id) { string nonceStr = TenPayV3Util.GetNoncestr(); RequestHandler packageReqHandler = new RequestHandler(null); //设置package订单参数 packageReqHandler.SetParameter("appid", TenPayV3Info.AppId); //公众账号ID packageReqHandler.SetParameter("mch_id", TenPayV3Info.MchId); //商户号 packageReqHandler.SetParameter("transaction_id", ""); //填入微信订单号 二选一 packageReqHandler.SetParameter("out_trade_no", orderno); //填入商家订单号 二选一 packageReqHandler.SetParameter("nonce_str", nonceStr); //随机字符串 string sign = packageReqHandler.CreateMd5Sign("key", TenPayV3Info.Key); packageReqHandler.SetParameter("sign", sign); //签名 string data = packageReqHandler.ParseXML(); var result = TenPayV3.OrderQuery(data); var res = XDocument.Parse(result); string return_code = res.Element("xml").Element("return_code").Value; if (return_code.ToUpper() == "SUCCESS") { string result_code = res.Element("xml").Element("result_code").Value; if (result_code.ToUpper() == "SUCCESS") { string trade_state = res.Element("xml").Element("trade_state").Value;//交易状态 https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_2 if (trade_state.ToUpper() == "SUCCESS") { transaction_id = res.Element("xml").Element("transaction_id").Value; return(true); } } } return(false); }
public HttpResponseMessage Notify() { var respData = new Dictionary <string, string>(); try { // 读取微信支付返回结果 var resp = ReadFromInputStream(); var dict = ReadXml(resp); LogHelper.Info("\n\nnotify 接收内容:\n" + JsonHelper.Serialize(dict)); // 微信订单号 string transactionId, tradeNo; dict.TryGetValue("transaction_id", out transactionId); dict.TryGetValue("out_trade_no", out tradeNo); #region 1. 检查支付结果中transaction_id是否存在 if (string.IsNullOrEmpty(transactionId)) { //若transaction_id不存在,则立即返回结果给微信支付后台 respData.Add("return_code", "FAIL"); respData.Add("return_msg", "支付结果中微信订单号不存在"); var xml = DictToXml(respData); LogHelper.Info("\n\nnotify 响应内容:\n" + xml); return(RetMessage(xml)); } #endregion #region 2. 同步查询订单,判断订单真实性 var appId = ConfigurationManager.AppSettings["appId"]; var mchId = ConfigurationManager.AppSettings["mchId"]; var key = ConfigurationManager.AppSettings["appKey"]; var reqData = new TenPayV3OrderQueryRequestData(appId, mchId, transactionId, TenPayV3Util.GetNoncestr(), "", key); var queryData = TenPayV3.OrderQuery(reqData); if (queryData.result_code == "SUCCESS" && queryData.result_code == "SUCCESS") {//查询订单成功 // 业务逻辑:更新订单状态 if (_orderService.UpdateOrderStatus(tradeNo, (int)Enums.OrderStatus.未发货)) { respData.Add("return_code", "SUCCESS"); respData.Add("return_msg", "OK"); var xml = DictToXml(respData); LogHelper.Info("\n\nnotify 响应内容:\n" + xml); return(RetMessage(xml)); } else { respData.Add("return_code", "FAIL"); respData.Add("return_msg", "订单状态修改失败"); var xml = DictToXml(respData); LogHelper.Info("\n\nnotify 响应内容:\n" + xml); return(RetMessage(xml)); } } else {//若订单查询失败,则立即返回结果给微信支付后台 respData.Add("return_code", "FAIL"); respData.Add("return_msg", "订单查询失败"); var xml = DictToXml(respData); LogHelper.Info("\n\nnotify 响应内容:\n" + xml); return(RetMessage(xml)); } #endregion } catch (Exception ex) { LogHelper.Info("\n\nnotify 异常:\n", ex); respData.Add("return_code", "FAIL"); respData.Add("return_msg", "系统异常:" + ex.Message); var xml = DictToXml(respData); return(RetMessage(xml)); } }
/// <summary> /// 订单查询 /// </summary> /// <param name="requestDto"></param> /// <returns></returns> public async Task <OrderQueryResult> OrderQuery(GetWeiXinPaymentBeforeRequestDto requestDto) { TenPayV3OrderQueryRequestData data = new TenPayV3OrderQueryRequestData(AppID, MerchantNumber, "wx0818171559664608e39c01920461325676", GetRandomString(16, false, true, true, false, string.Empty), "GDSPDD_IKJRMNLCCJ20190408181709", MerchantSecret); return(TenPayV3.OrderQuery(data)); }
/// <summary> /// 微信支付的结果校验 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void timerDo2_Tick(object sender, ElapsedEventArgs e) { t2.Enabled = false; Console.WriteLine("开始支付查询"); LogHelper.WriteLog(typeof(string), "开始支付查询"); try { var time = DateTime.Now; if (time.Second % 3 == 0) { context_m2.Dispose(); context_m2 = new MSZ(); //t.Enabled = false; var list = context_m2.BillState.Where(x => x.State == 0).ToList(); if (list.Count == 0) { LogHelper.WriteLog(typeof(string), "无数据跳出支付查询"); t2.Enabled = true; return; } else { LogHelper.WriteLog(typeof(FrmMain), "进行支付遍历"); for (int i = 0; i < list.Count; i++) { var entity = list[i]; string nonceStr = TenPayV3Util.GetNoncestr(); TenPayV3OrderQueryRequestData order = new TenPayV3OrderQueryRequestData(entity.Appid, entity.Mch_id, null, nonceStr, entity.BillNum, entity.Key, "MD5"); var result = TenPayV3.OrderQuery(order); LogHelper.WriteLog(typeof(FrmMain), "返回结果:" + JsonConvert.SerializeObject(result)); var bill = context_m2.BillState.FirstOrDefault(x => x.BillNum == entity.BillNum); if (result.return_code == "SUCCESS" && result.result_code == "SUCCESS" && result.trade_state == "SUCCESS") { LogHelper.WriteLog(typeof(FrmMain), "金额:" + result.cash_fee); if (result.trade_state == "SUCCESS") { Console.WriteLine("SUCCESS"); bill.State = 1; Console.WriteLine("保存:" + context_m2.SaveChanges()); var sbill = context_m2.StudentBill.FirstOrDefault(x => x.StudentBillUUID == bill.SBillUUID.Value); LogHelper.WriteLog(typeof(FrmMain), "钱:" + sbill.OrderMoney); LogHelper.WriteLog(typeof(FrmMain), "钱2:" + (decimal.Parse(result.cash_fee))); LogHelper.WriteLog(typeof(FrmMain), "愿订单时间:" + DateTime.Parse(sbill.OederTime)); if ((string.IsNullOrEmpty(sbill.OrderNum)) || ((!string.IsNullOrEmpty(sbill.OrderNum)) && sbill.OrderNum != result.out_trade_no && DateTime.Parse(sbill.OederTime) < DateTime.ParseExact(result.time_end, "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture))) { LogHelper.WriteLog(typeof(string), "进入条件,修改数据"); sbill.OrderMoney = sbill.OrderMoney + (decimal.Parse(result.cash_fee) / 100); sbill.OrderNum = result.out_trade_no; sbill.OederTime = DateTime.ParseExact(result.time_end, "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture).ToString("yyyy-MM-dd HH:mm:ss"); sbill.SystemUserUUID = context_m2.SystemUser.FirstOrDefault(x => x.Wechat == result.openid).SystemUserUUID; } } else if (result.trade_state == "REFUND") { Console.WriteLine("REFUND"); bill.State = 2; } else if (result.trade_state == "NOTPAY") { Console.WriteLine("NOTPAY"); bill.State = 3; } else if (result.trade_state == "CLOSED") { Console.WriteLine("CLOSED"); bill.State = 4; } else if (result.trade_state == "REVOKED") { Console.WriteLine("REVOKED"); bill.State = 5; } else if (result.trade_state == "USERPAYING") { Console.WriteLine("USERPAYING"); bill.State = 0; } else if (result.trade_state == "PAYERROR") { Console.WriteLine("PAYERROR"); bill.State = 6; } var num = context_m2.SaveChanges(); Console.WriteLine("保存" + num); } //else //{ // bill.State = -1; // context_m.SaveChanges(); //} } } } else { LogHelper.WriteLog(typeof(string), "非时段跳出"); t2.Enabled = true; return; } } catch (Exception ex) { Console.WriteLine(ex.Message); LogHelper.WriteLog(typeof(string), "支付查询错误:" + ex.Message); } finally { t2.Enabled = true; } }