chore: 升级示例项目为基于 .NET 6.0 的实现

This commit is contained in:
Fu Diwei
2021-12-27 19:39:03 +08:00
parent 15e9042cad
commit b2ce287136
36 changed files with 23 additions and 19 deletions

View File

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<NullableReferenceTypes>true</NullableReferenceTypes>
</PropertyGroup>

View File

@@ -26,14 +26,14 @@ namespace SKIT.FlurlHttpClient.Wechat.Api.Sample_Net5.Services.HttpClients.Imple
public WechatApiClient Create(string appId)
{
var wechatAccount = _wechatOptions.Accounts?.FirstOrDefault(e => string.Equals(appId, e.AppId));
if (wechatAccount == null)
var wechatAccountOptions = _wechatOptions.Accounts?.FirstOrDefault(e => string.Equals(appId, e.AppId));
if (wechatAccountOptions == null)
throw new Exception("未在配置项中找到该 AppId 对应的微信账号。");
return new WechatApiClient(new WechatApiClientOptions()
{
AppId = wechatAccount.AppId,
AppSecret = wechatAccount.AppSecret
AppId = wechatAccountOptions.AppId,
AppSecret = wechatAccountOptions.AppSecret
});
}
}

View File

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<NullableReferenceTypes>true</NullableReferenceTypes>
</PropertyGroup>

View File

@@ -15,6 +15,8 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Sample_Net5.Services.HttpClients.
public CertificateManager Create(string merchantId)
{
// 注意:这里的工厂方法是为了演示多租户而存在的;如果你的项目只存在唯一一个租户,那么直接注入 `CertificateManager` 就可以
return _dict.GetOrAdd(merchantId, new InMemoryCertificateManager());
}
}

View File

@@ -29,17 +29,19 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Sample_Net5.Services.HttpClients.
public WechatTenpayClient Create(string merchantId)
{
var merchantOptions = _tenpayOptions.Merchants?.FirstOrDefault(e => string.Equals(merchantId, e.MerchantId));
if (merchantOptions == null)
// 注意:这里的工厂方法是为了演示多租户而存在的;如果你的项目只存在唯一一个租户,那么直接注入 `WechatTenpayClient` 就可以
var tenpayMerchantOptions = _tenpayOptions.Merchants?.FirstOrDefault(e => string.Equals(merchantId, e.MerchantId));
if (tenpayMerchantOptions == null)
throw new Exception("未在配置项中找到该 MerchantId 对应的微信商户号。");
return new WechatTenpayClient(new WechatTenpayClientOptions()
{
MerchantId = merchantOptions.MerchantId,
MerchantV3Secret = merchantOptions.SecretV3,
MerchantCertSerialNumber = merchantOptions.CertSerialNumber,
MerchantCertPrivateKey = merchantOptions.CertPrivateKey,
CertificateManager = _tenpayCertificateManagerFactory.Create(merchantOptions.MerchantId),
MerchantId = tenpayMerchantOptions.MerchantId,
MerchantV3Secret = tenpayMerchantOptions.SecretV3,
MerchantCertSerialNumber = tenpayMerchantOptions.CertSerialNumber,
MerchantCertPrivateKey = tenpayMerchantOptions.CertPrivateKey,
CertificateManager = _tenpayCertificateManagerFactory.Create(tenpayMerchantOptions.MerchantId),
AutoEncryptRequestSensitiveProperty = true,
AutoDecryptResponseSensitiveProperty = true
});