コード例 #1
0
        /// <summary>
        /// 获取表单
        /// </summary>
        private string GetForm(AlipayParameterBuilder builder)
        {
            FormBuilder formBuilder = new FormBuilder();

            formBuilder.AddParam(builder);
            return(formBuilder.ToString());
        }
コード例 #2
0
ファイル: AlipayResult.cs プロジェクト: zzti/Util
 /// <summary>
 /// 初始化支付宝结果
 /// </summary>
 /// <param name="response">json响应消息</param>
 /// <param name="builder">支付宝参数生成器</param>
 public AlipayResult(string response, AlipayParameterBuilder builder = null)
 {
     Raw     = response;
     Builder = builder;
     _result = new Dictionary <string, string>();
     LoadJson(response);
 }
コード例 #3
0
ファイル: AlipayServiceBase.cs プロジェクト: zzti/Util
 /// <summary>
 /// 配置参数生成器
 /// </summary>
 /// <param name="builder">支付宝参数生成器</param>
 /// <param name="param">请求参数</param>
 protected void ConfigBuilder(AlipayParameterBuilder builder, TRequest param)
 {
     builder.Init();
     builder.Method(GetMethod());
     InitBuilder(builder, param);
     InitContentBuilder(builder.Content, param);
 }
コード例 #4
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));
        }
コード例 #5
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();
        }
コード例 #6
0
 /// <summary>
 /// 配置
 /// </summary>
 /// <param name="builder">支付宝参数生成器</param>
 /// <param name="param">支付参数</param>
 protected void Config(AlipayParameterBuilder builder, PayParam param)
 {
     builder.Init(param);
     builder.Method(GetMethod());
     builder.Content.Scene(GetScene());
     InitContentBuilder(builder.Content, param);
 }
コード例 #7
0
 public void TestConfig()
 {
     _builder = new AlipayParameterBuilder(new AlipayConfig {
         AppId = "a"
     });
     _output.WriteLine(_builder.ToString());
     Assert.Equal("app_id=a&charset=utf-8&format=json&sign_type=RSA2&timestamp=2000-10-10 10:10:10&version=1.0", _builder.ToString());
 }
コード例 #8
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()
     });
 }
コード例 #9
0
        /// <summary>
        /// 发送请求
        /// </summary>
        protected virtual async Task <string> Request(AliPayConfig config, AlipayParameterBuilder builder)
        {
            var resonse = await Web.Client()
                          .Post(config.GetGatewayUrl())
                          .JsonData(builder.GetDictionary())
                          .ResultAsync();

            return(await resonse.Content.ReadAsStringAsync());
        }
コード例 #10
0
 /// <summary>
 /// 创建结果
 /// </summary>
 protected override PayResult CreateResult(AlipayParameterBuilder builder, AlipayResult result)
 {
     return(new PayResult(result.Success, result.GetTradeNo(), result.Raw)
     {
         Parameter = builder.ToString(),
         Message = result.GetMessage(),
         Result = result.GetValue(AlipayConst.QrCode)
     });
 }
コード例 #11
0
        /// <summary>
        /// 请求结果
        /// </summary>
        protected override Task <AlipayResult> RequstResult(AlipayConfig config, AlipayParameterBuilder builder)
        {
            var result = builder.Result(true);

            WriteLog(config, builder, result);
            return(Task.FromResult(new AlipayResult {
                Result = result
            }));
        }
コード例 #12
0
 /// <summary>
 /// 写日志
 /// </summary>
 protected void WriteLog(AlipayConfig config, AlipayParameterBuilder builder, string content)
 {
     Logger.Error(GetType().FullName + " 支付宝支付:"
                  + $"支付方式 : {EnumUtil.GetEnumDescription(GetPayWay())}"
                  + $"支付网关 : {config.GetGatewayUrl()}"
                  + "请求参数:" + builder.GetDictionary()
                  + "原始请求:" + builder.ToString()
                  + "内容: " + content
                  );
 }
コード例 #13
0
        /// <summary>
        /// 获取调试参数
        /// </summary>
        /// <param name="param">支付参数</param>
        public virtual async Task <string> Debug(PayParam param)
        {
            var config = await ConfigProvider.GetConfigAsync();

            Validate(config, param);
            var builder = new AlipayParameterBuilder(config, param);

            Config(builder, param);
            return(builder.ToString());
        }
コード例 #14
0
ファイル: AlipayServiceBase.cs プロジェクト: zzti/Util
        /// <summary>
        /// 请求
        /// </summary>
        /// <param name="param">请求参数</param>
        protected async Task <AlipayResult> Request(TRequest param)
        {
            var config = await ConfigProvider.GetConfigAsync(param);

            Validate(config, param);
            var builder = new AlipayParameterBuilder(config);

            ConfigBuilder(builder, param);
            return(await RequstResult(config, builder));
        }
コード例 #15
0
        /// <summary>
        /// 支付
        /// </summary>
        /// <param name="param">支付参数</param>
        /// <returns></returns>
        public virtual async Task <PayResult> PayAsync(PayParam param)
        {
            var config = await ConfigProvider.GetConfigAsync();

            Validate(config, param);
            var builder = new AlipayParameterBuilder(config);

            Config(builder, param);
            return(await RequestResult(config, builder));
        }
コード例 #16
0
 /// <summary>
 /// 发送请求
 /// </summary>
 protected virtual async Task <string> Request(AlipayConfig config, AlipayParameterBuilder builder)
 {
     if (IsSend == false)
     {
         return(string.Empty);
     }
     return(await Web.Client()
            .Post(config.GetGatewayUrl())
            .Data(builder.GetDictionary())
            .ResultAsync());
 }
コード例 #17
0
        /// <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);
        }
コード例 #18
0
        /// <summary>
        /// 支付
        /// </summary>
        /// <param name="param">支付参数</param>
        public override async Task <PayResult> PayAsync(PayParam param)
        {
            var config = await ConfigProvider.GetConfigAsync();

            Validate(config, param);
            var builder = new AlipayParameterBuilder(config);

            Config(builder, param);
            var form = GetForm(builder);

            WriteLog(config, builder, form);
            return(new PayResult {
                Result = form
            });
        }
コード例 #19
0
        /// <summary>
        /// 写日志
        /// </summary>
        protected void WriteLog(AlipayConfig config, AlipayParameterBuilder builder, string content)
        {
            var log = GetLog();

            if (log.IsTraceEnabled == false)
            {
                return;
            }
            log.Class(GetType().FullName)
            .Caption("支付宝支付")
            .Content($"支付方式 :  {GetType()}")
            .Content($"支付网关 : {config.GetGatewayUrl()}")
            .Content("请求参数:")
            .Content(builder.GetDictionary())
            .Content()
            .Content("原始请求:")
            .Content(builder.ToString())
            .Content()
            .Content("内容: ")
            .Content(content)
            .Trace();
        }
コード例 #20
0
 /// <summary>
 /// 测试初始化
 /// </summary>
 public AlipayParameterBuilderTest(ITestOutputHelper output)
 {
     _output = output;
     Time.SetTime(TestConst.Time);
     _builder = new AlipayParameterBuilder(new AlipayConfig());
 }
コード例 #21
0
 protected override void InitContentBuilder(AlipayParameterBuilder builder, AlipayBarcodePayRequest param)
 {
     builder.Remove(AlipayConst.ReturnUrl);
 }
コード例 #22
0
 protected void WriteLog(AlipayConfig config, AlipayParameterBuilder builder, AlipayResult result)
 {
 }
コード例 #23
0
 protected void WriteLog(AlipayConfig config, AlipayParameterBuilder builder, string content)
 {
 }
コード例 #24
0
 /// <summary>
 /// 初始化支付宝支付服务
 /// </summary>
 /// <param name="provider">支付宝配置提供器</param>
 protected AlipayServiceBase(IAlipayConfigProvider provider)
 {
     provider.CheckNull(nameof(provider));
     _config  = provider.GetConfig();
     _builder = new AlipayParameterBuilder(_config);
 }
コード例 #25
0
 /// <summary>
 /// 测试初始化
 /// </summary>
 public AlipayParameterBuilderTest(ITestOutputHelper output)
 {
     _output = output;
     Time.SetTime("2000-10-10 10:10:10");
     _builder = new AlipayParameterBuilder(new AlipayConfig());
 }
コード例 #26
0
ファイル: AlipayServiceBase.cs プロジェクト: zzti/Util
        /// <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);
        }
コード例 #27
0
ファイル: AlipayServiceBase.cs プロジェクト: zzti/Util
 /// <summary>
 /// 初始化参数生成器
 /// </summary>
 /// <param name="builder">支付宝参数生成器</param>
 /// <param name="param">请求参数</param>
 protected virtual void InitBuilder(AlipayParameterBuilder builder, TRequest param)
 {
 }
コード例 #28
0
 protected virtual void InitContentBuilder(AlipayParameterBuilder builder, TPayParam param)
 {
 }
コード例 #29
0
 /// <summary>
 /// 初始化参数生成器
 /// </summary>
 /// <param name="builder">支付宝参数生成器</param>
 /// <param name="param">支付参数</param>
 protected override void InitBuilder(AlipayParameterBuilder builder, PayParam param)
 {
     builder.Init(param);
     builder.Content.Scene(GetScene());
 }
コード例 #30
0
 protected override void InitContentBuilder(AlipayParameterBuilder builder, AlipayPagePayRequest param)
 {
     builder.ReturnUrl(param.ReturnUrl);
 }