Beispiel #1
0
        /// <summary>
        /// 请求结果
        /// </summary>
        /// <param name="config">支付宝配置</param>
        /// <param name="builder">支付宝参数生成器</param>
        /// <returns></returns>
        protected virtual async Task <PayResult> RequestResult(AlipayConfig config, AlipayParameterBuilder builder)
        {
            var result = new AlipayResult(await Request(config, builder));

            WriteLog(config, builder, result);
            return(CreateResult(builder, result));
        }
Beispiel #2
0
        /// <summary>
        /// 写日志
        /// </summary>
        /// <param name="config">支付宝配置</param>
        /// <param name="builder">支付宝参数生成器</param>
        /// <param name="result">支付宝结果</param>
        protected void WriteLog(AlipayConfig config, AlipayParameterBuilder builder, AlipayResult result)
        {
            var log = GetLog();

            if (log.IsTraceEnabled == false)
            {
                return;
            }

            log.Class(GetType().FullName)
            .Caption("支付宝支付")
            .Content($"支付宝方式 : {GetPayWay().Description()}")
            .Content($"支付网关 : {config.GetGatewayUrl()}")
            .Content("请求参数:")
            .Content(builder.GetDictionary())
            .Content()
            .Content("返回结果:")
            .Content(result.GetDictionary())
            .Content()
            .Content("原始请求:")
            .Content(builder.ToString())
            .Content()
            .Content("原始响应:")
            .Content(result.Raw)
            .Trace();
        }
Beispiel #3
0
        /// <summary>
        /// 写日志
        /// </summary>
        private void WriteLog(AlipayResult result)
        {
            var log = GetLog();

            if (log.IsTraceEnabled == false)
            {
                return;
            }
            log.Class(GetType().FullName)
            .Caption("请求支付宝支付")
            .Content("支付方式 : {0}", GetPayWay().Description())
            .Content("支付网关 : {0}", GetGatewayUrl())
            .Content()
            .Content("请求参数:")
            .Content(_builder.GetDictionary())
            .Content()
            .Content("返回结果:")
            .Content(result.GetDictionary())
            .Content()
            .Content("原始请求:")
            .Content(_builder.ToString())
            .Content()
            .Content("原始响应: ")
            .Content(result.Raw)
            .Trace();
        }
Beispiel #4
0
 /// <summary>
 /// 创建结果
 /// </summary>
 protected virtual PayResult CreateResult(AlipayResult result)
 {
     return(new PayResult(result.Success, result.GetTradeNo(), result.Raw)
     {
         Message = result.GetMessage()
     });
 }
Beispiel #5
0
 /// <summary>
 /// 创建结果
 /// </summary>
 /// <param name="builder">支付宝参数生成器</param>
 /// <param name="result">支付宝结果</param>
 /// <returns></returns>
 protected virtual PayResult CreateResult(AlipayParameterBuilder builder, AlipayResult result)
 {
     return(new PayResult(result.Success, result.GetTradeNo(), result.Raw)
     {
         Parameter = builder.ToString(),
         Message = result.GetMessage()
     });
 }
Beispiel #6
0
        public void TestJson()
        {
            const string json   = "{\"alipay_trade_pay_response\":{\"code\":\"10000\",\"msg\":\"Success\",\"buyer_logon_id\":\"jeu*** @sandbox.com\",\"buyer_pay_amount\":\"10.00\",\"buyer_user_id\":\"2088102174804335\",\"fund_bill_list\":[{\"amount\":\"10.00\",\"fund_channel\":\"ALIPAYACCOUNT\"}],\"gmt_payment\":\"2017-10-31 13:23:12\",\"invoice_amount\":\"10.00\",\"open_id\":\"20881058260191225496241750118233\",\"out_trade_no\":\"06bfa9807832438dac6a2b785ad7addc\",\"point_amount\":\"0.00\",\"receipt_amount\":\"10.00\",\"total_amount\":\"10.00\",\"trade_no\":\"2017103121001004330200344580\"},\"sign\":\"CkMKbLdFmlhIz0Ymob7IjnGdjBDfAt5/aAZ7l0jMvwFJyBRf0TaRJiHfXTCI7srL68RQ5DnR6N89XSr1+MiclVbpbNa3joi4XDd1sdEkTKMcEmp28tvL9q3UAbMtwKgiS93CWjmj/D5xK7K+ZxwVPwF3JlkeCd2Qg5GAtHmNjAAt3tlEKVn+SmRQ0yKyk2PpvVSSBBYbFo+VircmOxHo/m/ji3sK68y0ikhQYhHRuNQXXTp3KellpIESaIUGHi8KdQa7lV2acnDnSDChWy/4PxIrEmm8Ki8PMKsqS8WiIwKiUTldeWGZ0D749oP4iq6n18iDtjmSDeEgOTkhErVKLg==\"}";
            var          result = new AlipayResult(json);

            Assert.Equal("10000", result.GetCode());
            Assert.Equal("2017103121001004330200344580", result.GetTradeNo());
            Assert.True(result.HasKey("sign"));
        }
Beispiel #7
0
 /// <summary>
 /// 创建结果
 /// </summary>
 protected override PayResult CreateResult(AlipayResult result)
 {
     return(new PayResult(result.Success, result.GetTradeNo(), result.Raw)
     {
         Parameter = result.Builder.ToString(),
         Message = result.GetMessage(),
         Result = result.GetValue(AlipayConst.QrCode)
     });
 }
Beispiel #8
0
        /// <summary>
        /// 请求结果
        /// </summary>
        protected virtual async Task <AlipayResult> RequstResult(AlipayConfig config, AlipayParameterBuilder builder)
        {
            var response = await SendRequest(config, builder);

            var result = new AlipayResult(response, builder);

            WriteLog(config, builder, result);
            return(result);
        }
Beispiel #9
0
        /// <summary>
        /// 支付
        /// </summary>
        /// <param name="param">支付参数</param>
        public async Task <PayResult> PayAsync(PayParam param)
        {
            Validate(param);
            _payParam = param;
            Config();
            var result = new AlipayResult(await RequestAsync());

            WriteLog(result);
            return(CreateResult(result));
        }
Beispiel #10
0
 /// <summary>
 /// 写日志
 /// </summary>
 protected void WriteLog(AlipayConfig config, AlipayParameterBuilder builder, AlipayResult result)
 {
     Logger.Error(GetType().FullName + " 支付宝支付:"
                  + $"支付方式 : {EnumUtil.GetEnumDescription(GetPayWay())}"
                  + $"支付网关 : {config.GetGatewayUrl()}"
                  + "请求参数:" + builder.GetDictionary()
                  + "返回结果:" + result.GetDictionary()
                  + "原始请求:" + builder.ToString()
                  + "原始响应: " + result.Raw
                  );
 }
        /// <summary>
        /// 写日志
        /// </summary>
        protected void WriteLog(AliPayConfig config, AlipayParameterBuilder builder, AlipayResult result)
        {
            var logContent = LogContentBuilder.CreateLogContentBuilder()
                             .SetEventId(Guid.NewGuid()).SetMoudle(GetType().FullName).SetTitle("支付宝支付")
                             .AddContent($"支付宝支付 : {GetType()}")
                             .AddContent($"支付网关 : {config?.GetGatewayUrl()}")
                             .AddContent($"请求参数:{builder?.GetDictionary()?.ToXml()}")
                             .AddContent($"返回结果:{result?.GetDictionary()}")
                             .AddContent($"原始响应:{result?.Raw}")
                             .Build();

            Logger.LogInfo(logContent);
        }
Beispiel #12
0
        public static AlipayResult ParseAlipayResult(string content)
        {
            if (string.IsNullOrEmpty(content))
            {
                return(null);
            }

            var list = content.Split(PrimaryDiv, StringSplitOptions.None);

            if (list.Length <= 0)
            {
                return(null);
            }

            var res = new AlipayResult();

            for (int i = 0; i < list.Length; i++)
            {
                var pair = list[i].Split(EqualDiv, StringSplitOptions.None);
                if (pair.Length >= 2)
                {
                    if (StringUtil.AreEqual(AlipayResult.KeyStatus, pair[0]))
                    {
                        res.status = pair[1];
                    }
                    else if (StringUtil.AreEqual(AlipayResult.KeyMemo, pair[0]))
                    {
                        res.memo = pair[1];
                    }
                    else if (StringUtil.AreEqual(AlipayResult.KeyResult, pair[0]))
                    {
                        res.result = pair[1];
                    }
                }
            }

            return(res);
        }
Beispiel #13
0
 /// <summary>
 /// 创建结果
 /// </summary>
 protected override PayResult CreateResult(AlipayResult result)
 {
     return(new PayResult {
         Result = result.Result
     });
 }
Beispiel #14
0
 /// <summary>
 /// 创建结果
 /// </summary>
 protected virtual AlipayCancelResult CreateResult(AlipayResult result)
 {
     return(new AlipayCancelResult(result));
 }
Beispiel #15
0
 /// <summary>
 /// 创建结果
 /// </summary>
 protected virtual AlipayDownloadBillResult CreateResult(AlipayResult result, string url, List <AlipayBillInfo> bills)
 {
     return(new AlipayDownloadBillResult(result, url, bills));
 }
 protected void WriteLog(AlipayConfig config, AlipayParameterBuilder builder, AlipayResult result)
 {
 }