示例#1
0
        public override Task <string> GetRefundResultResponse(bool success, RefundData notify)
        {
            return(Task.FromResult(string.Format(@"<xml>
<return_code><![CDATA[{0}]]></return_code>
<return_msg><![CDATA[{1}]]></return_msg>
</xml>", success ? "SUCCESS" : "FAIL", success ? "OK" : "FAIL")));
        }
示例#2
0
 public abstract Task <string> GetRefundResultResponse(bool success, RefundData notify);
示例#3
0
        public override async Task <(bool success, RefundData refundDetail)> RefundResultNotify(
            IEnumerable <KeyValuePair <string, string> > query,
            IDictionary <string, string> header,
            IDictionary <string, string> form,
            Stream body)
        {
            await Task.CompletedTask;
            var xml = body.ReadToString();

            if (xml.IsNullOrWhiteSpace())
            {
                Logger.LogWarning("微信退款回调,xml数据为空");
                return(false, null);
            }

            ResponseHandler resHandler;

            try
            {
                // 获取微信回调数据
                resHandler = new ResponseHandler(HttpContextAccessor.HttpContext);

                string return_code = resHandler.GetParameter("return_code");
                string return_msg  = resHandler.GetParameter("return_msg");
                if (return_code != "SUCCESS")
                {
                    return(false, null);
                }

                string appId     = resHandler.GetParameter("appid");
                string mch_id    = resHandler.GetParameter("mch_id");
                string nonce_str = resHandler.GetParameter("nonce_str");
                string req_info  = resHandler.GetParameter("req_info");

                var secret = MchOptions.Value.Get(mch_id)?.MchKey;
                if (secret.IsNullOrWhiteSpace())
                {
                    Logger.LogError($"微信支付回调,未找到商户密钥,mchId:{mch_id},result:{xml}");
                    return(false, null);
                }

                var decodeReqInfo = TenPayV3Util.DecodeRefundReqInfo(req_info, secret);
                var decodeDoc     = XDocument.Parse(decodeReqInfo);

                //获取接口中需要用到的信息
                string transaction_id       = decodeDoc.Root.Element("transaction_id").Value;
                string out_trade_no         = decodeDoc.Root.Element("out_trade_no").Value;
                string refund_id            = decodeDoc.Root.Element("refund_id").Value;
                string out_refund_no        = decodeDoc.Root.Element("out_refund_no").Value;
                int    total_fee            = int.Parse(decodeDoc.Root.Element("total_fee").Value);
                int?   settlement_total_fee = decodeDoc.Root.Element("settlement_total_fee") != null
                    ? int.Parse(decodeDoc.Root.Element("settlement_total_fee").Value)
                    : null as int?;

                int    refund_fee = int.Parse(decodeDoc.Root.Element("refund_fee").Value);
                int    tosettlement_refund_feetal_fee = int.Parse(decodeDoc.Root.Element("settlement_refund_fee").Value);
                string refund_status         = decodeDoc.Root.Element("refund_status").Value;
                string success_time          = decodeDoc.Root.Element("success_time").Value;
                string refund_recv_accout    = decodeDoc.Root.Element("refund_recv_accout").Value;
                string refund_account        = decodeDoc.Root.Element("refund_account").Value;
                string refund_request_source = decodeDoc.Root.Element("refund_request_source").Value;

                var refundDetail = new RefundData
                {
                    FailReason       = "",
                    LocalRefundNo    = out_refund_no,
                    RefundNo         = refund_id,
                    RealRefundAmount = tosettlement_refund_feetal_fee,
                    Status           = ToStatus(refund_status),
                    SuccessTime      = success_time.IsNullOrWhiteSpace()
                        ? null
                        : (long?)success_time.ConvertTo <DateTime>().GetLongDate(),
                    OriginData = decodeReqInfo
                };
                return(true, refundDetail);
            }
            catch (XmlException)
            {
                Logger.LogWarning("微信退款回调,xml数据解析错误");
                return(false, null);
            }
            catch (Exception ex)
            {
                Logger.LogWarning(ex, "微信退款回调数据处理异常");
                return(false, null);
            }
        }
 public RefundResultInnerNotifyEvent(RefundData notify)
 {
     Notify = notify;
 }