コード例 #1
0
#pragma warning disable CS1591 // 缺少对公共可见类型或成员的 XML 注释
        public RefundQueryResult RefundQuery(WeChatRefundQueryParamter paramter)
#pragma warning restore CS1591 // 缺少对公共可见类型或成员的 XML 注释
        {
            string nonceStr = TenPayV3Util.GetNoncestr();
            TenPayV3RefundQueryRequestData tenPayV3RefundRequestData = new TenPayV3RefundQueryRequestData(Options.WeChatBaseOptions.AppId,
                                                                                                          Options.WeChatBaseOptions.MchId, Options.WeChatBaseOptions.Key, nonceStr, paramter.DeviceInfo, paramter.TransactionId,
                                                                                                          paramter.OutTradeNo, paramter.OutRefundNo, paramter.RefundId, null, null, paramter.Offset);

            RefundQueryResult refundQueryResult = TenPayV3.RefundQuery(tenPayV3RefundRequestData);

            return(refundQueryResult);
        }
コード例 #2
0
        /// <summary>
        /// 退款查询
        /// </summary>
        /// <param name="appId"></param>
        /// <param name="mchId"></param>
        /// <param name="mchKey"></param>
        /// <param name="localTranNo"></param>
        /// <param name="offset"></param>
        /// <returns></returns>
        public bool TryRefundQuery(string appId, string mchId, string mchKey, string localTranNo,
                                   out WxRefundData wxRefundData, int offset = 0)
        {
            wxRefundData = null;

            string nonceStr = TenPayV3Util.GetNoncestr();
            var    result   = TenPayV3.RefundQuery(new TenPayV3RefundQueryRequestData(
                                                       appId, mchId, mchKey, nonceStr, null, null, localTranNo, null, null, offset: offset));

            Logger.LogInformation($"微信支付退款查询,localRefundNo:{localTranNo},result:{result.ResultXml}");
            if (!result.IsReturnCodeSuccess())
            {
                Logger.LogWarning($"微信退款查询异常,localRefundNo:{localTranNo},result:{result.ResultXml}");
                return(false);
            }

            if (!result.IsResultCodeSuccess())
            {
                Logger.LogWarning($"微信退款查询结果错误,localRefundNo:{localTranNo},result:{result.ResultXml}");
                return(false);
            }

            try
            {
                var resInner = new RefundQueryResultInner(result.ResultXml);
                wxRefundData = new WxRefundData
                {
                    TotalAmount      = resInner.total_fee.ParseTo <long>(),
                    TotalRefundCount = resInner.refund_count.ParseTo <int>(),
                    List             = resInner.List
                };

                return(true);
            }
            catch (Exception ex)
            {
                throw new Exception($"微信退款查询结果处理异常,localRefundNo:{localTranNo},result:{result.ResultXml}", ex);
            }
        }
コード例 #3
0
        /// <summary>
        /// 查询订单退款
        /// </summary>
        /// <param name="orderNumber">订单号</param>
        /// <returns></returns>
        public string RefundQuery(string orderNumber)
        {
            //读取配置文件
            var merchantId = string.Empty;
            var appId      = string.Empty;
            var key        = string.Empty;
            //接收微信支付异步通知回调地址

            var xd = new XmlDocument();

            xd.Load(HttpContext.Current.Server.MapPath("/app_data/xml/payment.xml"));
            var selectSingleNode = xd.SelectSingleNode("paymentMethod");

            if (selectSingleNode != null)
            {
                var xnl = selectSingleNode.ChildNodes;
                foreach (XmlNode xn in xnl)
                {
                    var xe = (XmlElement)xn;
                    if (xe.GetAttribute("id") != "wechat")
                    {
                        continue;
                    }
                    merchantId = xe.GetAttribute("merchant_id");
                    appId      = xe.GetAttribute("app_id");
                    key        = xe.GetAttribute("key");
                    break;
                }
            }
            var nonceStr          = TenPayV3Util.GetNoncestr();
            var packageReqHandler = new RequestHandler(null);

            packageReqHandler.SetKey(key);
            packageReqHandler.SetParameter("appid", appId);
            packageReqHandler.SetParameter("mch_id", merchantId);
            packageReqHandler.SetParameter("nonce_str", nonceStr);
            packageReqHandler.SetParameter("out_trade_no", orderNumber);//商户系统内部的订单号

            var querysign = packageReqHandler.CreateMd5Sign("key", key);

            packageReqHandler.SetParameter("sign", querysign);                        //签名

            var data = packageReqHandler.ParseXML();

            var result = TenPayV3.RefundQuery(data);
            var res    = System.Xml.Linq.XDocument.Parse(result);

            var xElement = res.Element("xml");

            if (xElement == null)
            {
                return("");
            }
            var element = xElement.Element("return_code");

            if (element == null)
            {
                return("");
            }
            var returnCode = element.Value;

            return(returnCode);
        }