Skip to content

Commit

Permalink
log
Browse files Browse the repository at this point in the history
  • Loading branch information
my6521 committed May 9, 2024
1 parent 3b2637a commit 41c3009
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 32 deletions.
76 changes: 45 additions & 31 deletions src/WWB.Paylink.BaoFooTransfer/BaoFooTransClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Microsoft.Extensions.Logging;
using System;
using System.Net.Http;
using System.Threading.Tasks;
using WWB.Paylink.BaoFooTransfer.Parser;
Expand All @@ -7,42 +8,55 @@

namespace WWB.Paylink.BaoFooTransfer
{
public class BaoFooTransClient : IBaoFooTransClient
public class BaoFooTransClient : IBaoFooTransClient
{
public const string Name = "WWB.Paylink.BaoFooTransfer.Client";

private readonly IHttpClientFactory _httpClientFactory;
private readonly ILogger<BaoFooTransClient> _logger;

public BaoFooTransClient(IHttpClientFactory httpClientFactory, ILogger<BaoFooTransClient> logger)
{
public const string Name = "WWB.Paylink.BaoFooTransfer.Client";
_httpClientFactory = httpClientFactory;
_logger = logger;
}

private readonly IHttpClientFactory _httpClientFactory;
public async Task<T> ExecuteAsync<T>(IBaoFooTransRequest<T> request, BaoFooTransOptions options) where T : BaseResponse
{
if (options == null)
{
throw new ArgumentNullException(nameof(options));
}

public BaoFooTransClient(IHttpClientFactory httpClientFactory)
//获取参数
var txtParams = request.PrimaryHandler(options);
//获取请求url
var url = request.GetRequestUrl(options.Debug);
//获取提交类型0
var contentType = request.GetContentType();
//提交
using (var client = _httpClientFactory.CreateClient(Name))
{
var (body, isSuccessStatusCode) = await client.PostAsync(url, contentType, txtParams);
if (isSuccessStatusCode)
{
_httpClientFactory = httpClientFactory;
}
_logger.LogInformation($"反馈消息:{body}");

//解密
var realContent = RSAUtil.DecryptByCer(body, options.CerCertificate);

public async Task<T> ExecuteAsync<T>(IBaoFooTransRequest<T> request, BaoFooTransOptions options) where T : BaseResponse
_logger.LogInformation($"消息解密:{realContent}");

//反序列化
var parser = new ResponseJsonParser<T>();
var response = parser.Parse(realContent);
return response;
}
else
{
if (options == null)
{
throw new ArgumentNullException(nameof(options));
}

//获取参数
var txtParams = request.PrimaryHandler(options);
//获取请求url
var url = request.GetRequestUrl(options.Debug);
//获取提交类型
var contentType = request.GetContentType();
//提交
using (var client = _httpClientFactory.CreateClient(Name))
{
var (body, isSuccessStatusCode) = await client.PostAsync(url, contentType, txtParams);
//解密
var realContent = RSAUtil.DecryptByCer(body, options.CerCertificate);
//反序列化
var parser = new ResponseJsonParser<T>();
var response = parser.Parse(realContent);

return response;
}
throw new BaoFooTransException($"请求错误");
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>disable</Nullable>
<PackageId>WWB.Paylink.BaoFooTransfer</PackageId>
<Version>1.0.9</Version>
<Version>1.0.10</Version>
<Authors>my6521</Authors>
<Description>宝付代付SDK。</Description>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
Expand Down

0 comments on commit 41c3009

Please sign in to comment.