chore(tenpayv3): 新增基于 .NET Framework 4.7 的示例项目

This commit is contained in:
Fu Diwei
2021-12-28 14:05:39 +08:00
parent b2ce287136
commit 2dcfcab262
58 changed files with 1114 additions and 204 deletions

View File

@@ -0,0 +1,57 @@
using System;
using System.Diagnostics;
using System.Threading.Tasks;
namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Sample.Services.BackgroundJobs
{
using SKIT.FlurlHttpClient.Wechat.TenpayV3.Models;
using SKIT.FlurlHttpClient.Wechat.TenpayV3.Settings;
class TenpayCertificateRefreshingBackgroundJob
{
private readonly HttpClients.IWechatTenpayHttpClientFactory _tenpayHttpClientFactory;
public TenpayCertificateRefreshingBackgroundJob(
HttpClients.IWechatTenpayHttpClientFactory tenpayHttpClientFactory)
{
_tenpayHttpClientFactory = tenpayHttpClientFactory;
}
public async Task ExecuteAsync()
{
foreach (var tenpayMerchantOptions in Options.TenpayOptions.Instance.Value.Merchants)
{
try
{
var client = _tenpayHttpClientFactory.Create(tenpayMerchantOptions.MerchantId);
var request = new QueryCertificatesRequest();
var response = await client.ExecuteQueryCertificatesAsync(request);
if (response.IsSuccessful())
{
// NOTICE:
// 如果启用了 `AutoDecryptResponseSensitiveProperty` 配置项,则无需再手动执行下面被注释的解密方法:
// response = client.DecryptResponseSensitiveProperty(response);
foreach (var certificateModel in response.CertificateList)
{
client.CertificateManager.AddEntry(new CertificateEntry(certificateModel));
}
Debug.WriteLine("刷新微信商户平台证书成功。");
}
else
{
Debug.WriteLine(
"刷新微信商户平台证书失败(状态码:{0},错误代码:{1},错误描述:{2})。",
response.RawStatus, response.ErrorCode, response.ErrorMessage
);
}
}
catch (Exception ex)
{
Debug.WriteLine("刷新微信商户平台证书遇到异常。\r\n{0}", ex);
}
}
}
}
}