mirror of
https://gitee.com/fudiwei/DotNetCore.SKIT.FlurlHttpClient.Wechat.git
synced 2025-12-29 01:44:42 +08:00
chore: 升级示例项目为基于 .NET 6.0 的实现
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Sample_Net5.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("notify")]
|
||||
public class TenpayNotifyController : ControllerBase
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly Services.HttpClients.IWechatTenpayHttpClientFactory _tenpayHttpClientFactory;
|
||||
|
||||
public TenpayNotifyController(
|
||||
ILoggerFactory loggerFactory,
|
||||
Services.HttpClients.IWechatTenpayHttpClientFactory tenpayHttpClientFactory)
|
||||
{
|
||||
_logger = loggerFactory.CreateLogger(GetType());
|
||||
_tenpayHttpClientFactory = tenpayHttpClientFactory;
|
||||
}
|
||||
|
||||
|
||||
[HttpPost]
|
||||
[Route("m-{merchant_id}/message-push")]
|
||||
public async Task<IActionResult> ReceiveMessage(
|
||||
[FromRoute(Name = "merchant_id")] string merchantId,
|
||||
[FromHeader(Name = "Wechatpay-Timestamp")] string timestamp,
|
||||
[FromHeader(Name = "Wechatpay-Nonce")] string nonce,
|
||||
[FromHeader(Name = "Wechatpay-Signature")] string signature,
|
||||
[FromHeader(Name = "Wechatpay-Serial")] string serialNumber)
|
||||
{
|
||||
// 接收服务器推送
|
||||
// 文档:https://pay.weixin.qq.com/wiki/doc/apiv3/wechatpay/wechatpay4_2.shtml
|
||||
|
||||
using var reader = new StreamReader(Request.Body, Encoding.UTF8);
|
||||
string content = await reader.ReadToEndAsync();
|
||||
_logger.LogInformation("接收到微信支付推送的数据:{0}", content);
|
||||
|
||||
var client = _tenpayHttpClientFactory.Create(merchantId);
|
||||
bool valid = client.VerifyEventSignature(
|
||||
callbackTimestamp: timestamp,
|
||||
callbackNonce: nonce,
|
||||
callbackBody: content,
|
||||
callbackSignature: signature,
|
||||
callbackSerialNumber: serialNumber
|
||||
);
|
||||
if (!valid)
|
||||
{
|
||||
// 注意:需提前注入 CertificateManager、并添加平台证书,才可以使用扩展方法执行验签操作
|
||||
// 有关 CertificateManager 的用法请参阅《开发文档 / 高级技巧 / 如何验证回调通知事件签名?》
|
||||
return new JsonResult(new { code = "FAIL", message = "验签失败" });
|
||||
}
|
||||
|
||||
return new JsonResult(new { code = "SUCCESS", message = "成功" });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using SKIT.FlurlHttpClient.Wechat.TenpayV3;
|
||||
using SKIT.FlurlHttpClient.Wechat.TenpayV3.Models;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Sample_Net5.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("order")]
|
||||
public class TenpayOrderController : ControllerBase
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly Options.TenpayOptions _tenpayOptions;
|
||||
private readonly Services.HttpClients.IWechatTenpayHttpClientFactory _tenpayHttpClientFactory;
|
||||
|
||||
public TenpayOrderController(
|
||||
ILoggerFactory loggerFactory,
|
||||
IOptions<Options.TenpayOptions> tenpayOptions,
|
||||
Services.HttpClients.IWechatTenpayHttpClientFactory tenpayHttpClientFactory)
|
||||
{
|
||||
_logger = loggerFactory.CreateLogger(GetType());
|
||||
_tenpayOptions = tenpayOptions.Value;
|
||||
_tenpayHttpClientFactory = tenpayHttpClientFactory;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route("jsapi")]
|
||||
public async Task<IActionResult> CreateOrderByJsapi([FromBody] Models.CreateOrderByJsapiRequest requestModel)
|
||||
{
|
||||
// JSAPI 下单
|
||||
// 文档:https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_1.shtml
|
||||
|
||||
var client = _tenpayHttpClientFactory.Create(requestModel.MerchantId);
|
||||
var request = new CreatePayTransactionJsapiRequest()
|
||||
{
|
||||
OutTradeNumber = "SAMPLE_OTN_" + DateTimeOffset.Now.ToString("yyyyMMddHHmmssfff"),
|
||||
AppId = requestModel.AppId,
|
||||
Description = "演示订单",
|
||||
NotifyUrl = _tenpayOptions.NotifyUrl,
|
||||
Amount = new CreatePayTransactionJsapiRequest.Types.Amount() { Total = requestModel.Amount },
|
||||
Payer = new CreatePayTransactionJsapiRequest.Types.Payer() { OpenId = requestModel.OpenId }
|
||||
};
|
||||
var response = await client.ExecuteCreatePayTransactionJsapiAsync(request, cancellationToken: HttpContext.RequestAborted);
|
||||
if (!response.IsSuccessful())
|
||||
{
|
||||
_logger.LogWarning(
|
||||
"JSAPI 下单失败(状态码:{0},错误代码:{1},错误描述:{2})。",
|
||||
response.RawStatus, response.ErrorCode, response.ErrorMessage
|
||||
);
|
||||
}
|
||||
|
||||
return new JsonResult(response);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using SKIT.FlurlHttpClient.Wechat.TenpayV3;
|
||||
using SKIT.FlurlHttpClient.Wechat.TenpayV3.Models;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Sample_Net5.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("refund")]
|
||||
public class TenpayRefundController : ControllerBase
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly Options.TenpayOptions _tenpayOptions;
|
||||
private readonly Services.HttpClients.IWechatTenpayHttpClientFactory _tenpayHttpClientFactory;
|
||||
|
||||
public TenpayRefundController(
|
||||
ILoggerFactory loggerFactory,
|
||||
IOptions<Options.TenpayOptions> tenpayOptions,
|
||||
Services.HttpClients.IWechatTenpayHttpClientFactory tenpayHttpClientFactory)
|
||||
{
|
||||
_logger = loggerFactory.CreateLogger(GetType());
|
||||
_tenpayOptions = tenpayOptions.Value;
|
||||
_tenpayHttpClientFactory = tenpayHttpClientFactory;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route("")]
|
||||
public async Task<IActionResult> CreateRefund([FromBody] Models.CreateRefundRequest requestModel)
|
||||
{
|
||||
// 申请退款
|
||||
// 文档:https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_9.shtml
|
||||
|
||||
var client = _tenpayHttpClientFactory.Create(requestModel.MerchantId);
|
||||
var request = new CreateRefundDomesticRefundRequest()
|
||||
{
|
||||
TransactionId = requestModel.TransactionId,
|
||||
OutRefundNumber = "SAMPLE_ORN_" + DateTimeOffset.Now.ToString("yyyyMMddHHmmssfff"),
|
||||
Amount = new CreateRefundDomesticRefundRequest.Types.Amount()
|
||||
{
|
||||
Total = requestModel.OrderAmount,
|
||||
Refund = requestModel.RefundAmount
|
||||
},
|
||||
Reason = "示例退款",
|
||||
NotifyUrl = _tenpayOptions.NotifyUrl
|
||||
};
|
||||
var response = await client.ExecuteCreateRefundDomesticRefundAsync(request, cancellationToken: HttpContext.RequestAborted);
|
||||
if (!response.IsSuccessful())
|
||||
{
|
||||
_logger.LogWarning(
|
||||
"申请退款失败(状态码:{0},错误代码:{1},错误描述:{2})。",
|
||||
response.RawStatus, response.ErrorCode, response.ErrorMessage
|
||||
);
|
||||
}
|
||||
|
||||
return new JsonResult(response);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Sample_Net5.Models
|
||||
{
|
||||
public class CreateOrderByJsapiRequest
|
||||
{
|
||||
public string MerchantId { get; set; } = default!;
|
||||
|
||||
public string AppId { get; set; } = default!;
|
||||
|
||||
public string OpenId { get; set; } = default!;
|
||||
|
||||
// NOTICE: 单机演示时金额来源于客户端请求,生产项目请替换成服务端计算生成
|
||||
public int Amount { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Sample_Net5.Models
|
||||
{
|
||||
public class CreateRefundRequest
|
||||
{
|
||||
public string MerchantId { get; set; } = default!;
|
||||
|
||||
public string TransactionId { get; set; } = default!;
|
||||
|
||||
// NOTICE: 单机演示时金额来源于客户端请求,生产项目请替换成服务端获取生成
|
||||
public int OrderAmount { get; set; }
|
||||
|
||||
public int RefundAmount { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Sample_Net5.Options
|
||||
{
|
||||
public partial class TenpayOptions : IOptions<TenpayOptions>
|
||||
{
|
||||
TenpayOptions IOptions<TenpayOptions>.Value => this;
|
||||
|
||||
public WechatMerchant[] Merchants { get; set; } = Array.Empty<WechatMerchant>();
|
||||
|
||||
public string NotifyUrl { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
partial class TenpayOptions
|
||||
{
|
||||
public class WechatMerchant
|
||||
{
|
||||
public string MerchantId { get; set; } = string.Empty;
|
||||
|
||||
public string SecretV3 { get; set; } = string.Empty;
|
||||
|
||||
public string CertSerialNumber { get; set; } = string.Empty;
|
||||
|
||||
public string CertPrivateKey { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using System.Text;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Sample_Net5
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
||||
|
||||
Host.CreateDefaultBuilder(args)
|
||||
.ConfigureWebHostDefaults(builder =>
|
||||
{
|
||||
builder.UseStartup<Startup>();
|
||||
})
|
||||
.Build()
|
||||
.Run();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"$schema": "http://json.schemastore.org/launchsettings.json",
|
||||
"profiles": {
|
||||
"SKIT.FlurlHttpClient.Wechat.TenpayV3.Sample_Net5": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": "true",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "weatherforecast",
|
||||
"applicationUrl": "https://localhost:5001;http://localhost:5000",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<NullableReferenceTypes>true</NullableReferenceTypes>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\SKIT.FlurlHttpClient.Wechat.TenpayV3\SKIT.FlurlHttpClient.Wechat.TenpayV3.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,74 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using SKIT.FlurlHttpClient.Wechat.TenpayV3.Models;
|
||||
using SKIT.FlurlHttpClient.Wechat.TenpayV3.Settings;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Sample_Net5.Services.BackgroundServices
|
||||
{
|
||||
class TenpayCertificateRefreshingBackgroundService : BackgroundService
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly Options.TenpayOptions _tenpayOptions;
|
||||
private readonly HttpClients.IWechatTenpayHttpClientFactory _tenpayHttpClientFactory;
|
||||
|
||||
public TenpayCertificateRefreshingBackgroundService(
|
||||
ILoggerFactory loggerFactory,
|
||||
IOptions<Options.TenpayOptions> tenpayOptions,
|
||||
HttpClients.IWechatTenpayHttpClientFactory tenpayHttpClientFactory)
|
||||
{
|
||||
_logger = loggerFactory.CreateLogger(GetType());
|
||||
_tenpayOptions = tenpayOptions.Value;
|
||||
_tenpayHttpClientFactory = tenpayHttpClientFactory;
|
||||
}
|
||||
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
while (!stoppingToken.IsCancellationRequested)
|
||||
{
|
||||
var wxpayMerchant = _tenpayOptions.Merchants.FirstOrDefault();
|
||||
if (wxpayMerchant == null)
|
||||
{
|
||||
_logger.LogWarning("未找到微信商户配置项。");
|
||||
break;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var client = _tenpayHttpClientFactory.Create(wxpayMerchant.MerchantId);
|
||||
var request = new QueryCertificatesRequest();
|
||||
var response = await client.ExecuteQueryCertificatesAsync(request, cancellationToken: stoppingToken);
|
||||
if (response.IsSuccessful())
|
||||
{
|
||||
// 注意:如果启用了 AutoDecryptResponseSensitiveProperty,则无需再手动执行下面被注释的解密方法
|
||||
// response = client.DecryptResponseSensitiveProperty(response);
|
||||
|
||||
foreach (var certificateModel in response.CertificateList)
|
||||
{
|
||||
client.CertificateManager.AddEntry(new CertificateEntry(certificateModel));
|
||||
}
|
||||
|
||||
_logger.LogInformation("刷新微信商户平台证书成功。");
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogWarning(
|
||||
"刷新微信商户平台证书失败(状态码:{0},错误代码:{1},错误描述:{2})。",
|
||||
response.RawStatus, response.ErrorCode, response.ErrorMessage
|
||||
);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "刷新微信商户平台证书遇到异常。");
|
||||
}
|
||||
|
||||
await Task.Delay(TimeSpan.FromDays(1)); // 每隔 1 天轮询刷新
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Sample_Net5.Services.HttpClients
|
||||
{
|
||||
using SKIT.FlurlHttpClient.Wechat.TenpayV3.Settings;
|
||||
|
||||
public interface IWechatTenpayCertificateManagerFactory
|
||||
{
|
||||
CertificateManager Create(string merchantId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Sample_Net5.Services.HttpClients
|
||||
{
|
||||
public interface IWechatTenpayHttpClientFactory
|
||||
{
|
||||
WechatTenpayClient Create(string merchantId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Sample_Net5.Services.HttpClients.Implements
|
||||
{
|
||||
using SKIT.FlurlHttpClient.Wechat.TenpayV3.Settings;
|
||||
|
||||
partial class WechatTenpayCertificateManagerFactory : IWechatTenpayCertificateManagerFactory
|
||||
{
|
||||
private readonly ConcurrentDictionary<string, CertificateManager> _dict;
|
||||
|
||||
public WechatTenpayCertificateManagerFactory()
|
||||
{
|
||||
_dict = new ConcurrentDictionary<string, CertificateManager>();
|
||||
}
|
||||
|
||||
public CertificateManager Create(string merchantId)
|
||||
{
|
||||
// 注意:这里的工厂方法是为了演示多租户而存在的;如果你的项目只存在唯一一个租户,那么直接注入 `CertificateManager` 就可以
|
||||
|
||||
return _dict.GetOrAdd(merchantId, new InMemoryCertificateManager());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Flurl;
|
||||
using Flurl.Http;
|
||||
using Flurl.Http.Configuration;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Sample_Net5.Services.HttpClients.Implements
|
||||
{
|
||||
using SKIT.FlurlHttpClient.Wechat.TenpayV3.Settings;
|
||||
|
||||
partial class WechatTenpayHttpClientFactory : IWechatTenpayHttpClientFactory
|
||||
{
|
||||
private readonly System.Net.Http.IHttpClientFactory _httpClientFactory;
|
||||
private readonly Options.TenpayOptions _tenpayOptions;
|
||||
private readonly IWechatTenpayCertificateManagerFactory _tenpayCertificateManagerFactory;
|
||||
|
||||
public WechatTenpayHttpClientFactory(
|
||||
System.Net.Http.IHttpClientFactory httpClientFactory,
|
||||
IOptions<Options.TenpayOptions> tenpayOptions,
|
||||
IWechatTenpayCertificateManagerFactory tenpayCertificateManagerFactory)
|
||||
{
|
||||
_httpClientFactory = httpClientFactory;
|
||||
_tenpayOptions = tenpayOptions.Value;
|
||||
_tenpayCertificateManagerFactory = tenpayCertificateManagerFactory;
|
||||
|
||||
FlurlHttp.GlobalSettings.FlurlClientFactory = new DelegatingFlurlClientFactory(_httpClientFactory);
|
||||
}
|
||||
|
||||
public WechatTenpayClient Create(string merchantId)
|
||||
{
|
||||
// 注意:这里的工厂方法是为了演示多租户而存在的;如果你的项目只存在唯一一个租户,那么直接注入 `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 = tenpayMerchantOptions.MerchantId,
|
||||
MerchantV3Secret = tenpayMerchantOptions.SecretV3,
|
||||
MerchantCertSerialNumber = tenpayMerchantOptions.CertSerialNumber,
|
||||
MerchantCertPrivateKey = tenpayMerchantOptions.CertPrivateKey,
|
||||
CertificateManager = _tenpayCertificateManagerFactory.Create(tenpayMerchantOptions.MerchantId),
|
||||
AutoEncryptRequestSensitiveProperty = true,
|
||||
AutoDecryptResponseSensitiveProperty = true
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
partial class WechatTenpayHttpClientFactory
|
||||
{
|
||||
internal class DelegatingFlurlClientFactory : IFlurlClientFactory
|
||||
{
|
||||
private readonly System.Net.Http.IHttpClientFactory _httpClientFactory;
|
||||
|
||||
public DelegatingFlurlClientFactory(System.Net.Http.IHttpClientFactory httpClientFactory)
|
||||
{
|
||||
_httpClientFactory = httpClientFactory ?? throw new ArgumentNullException(nameof(httpClientFactory));
|
||||
}
|
||||
|
||||
public IFlurlClient Get(Url url)
|
||||
{
|
||||
return new FlurlClient(_httpClientFactory.CreateClient(url.ToUri().Host));
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
// Do Nothing
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Sample_Net5
|
||||
{
|
||||
public class Startup
|
||||
{
|
||||
public IConfiguration Configuration { get; }
|
||||
|
||||
public Startup(IConfiguration configuration)
|
||||
{
|
||||
Configuration = configuration;
|
||||
}
|
||||
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddControllers();
|
||||
|
||||
// ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
services.AddOptions();
|
||||
services.Configure<Options.TenpayOptions>(Configuration.GetSection(nameof(Options.TenpayOptions)));
|
||||
|
||||
// ע<>빤<EFBFBD><EBB9A4> HTTP <20>ͻ<EFBFBD><CDBB><EFBFBD>
|
||||
services.AddHttpClient();
|
||||
services.AddSingleton<Services.HttpClients.IWechatTenpayCertificateManagerFactory, Services.HttpClients.Implements.WechatTenpayCertificateManagerFactory>();
|
||||
services.AddSingleton<Services.HttpClients.IWechatTenpayHttpClientFactory, Services.HttpClients.Implements.WechatTenpayHttpClientFactory>();
|
||||
|
||||
// ע<><D7A2><EFBFBD><EFBFBD>̨<EFBFBD><CCA8><EFBFBD><EFBFBD>
|
||||
services.AddHostedService<Services.BackgroundServices.TenpayCertificateRefreshingBackgroundService>();
|
||||
}
|
||||
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
{
|
||||
app.UseRouting();
|
||||
|
||||
app.UseEndpoints(endpoints =>
|
||||
{
|
||||
endpoints.MapControllers();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft": "Warning",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
},
|
||||
|
||||
"AllowedHosts": "*",
|
||||
|
||||
"TenpayOptions": {
|
||||
"Merchants": [
|
||||
{
|
||||
"MerchantId": "<22><>д<EFBFBD>̻<EFBFBD><CCBB><EFBFBD>",
|
||||
"SecretV3": "<22><>д V3 API <20><>Կ",
|
||||
"CertSerialNumber": "<22><>д<EFBFBD>̻<EFBFBD>֤<EFBFBD><D6A4><EFBFBD><EFBFBD><EFBFBD>к<EFBFBD>",
|
||||
"CertPrivateKey": "<22><>д<EFBFBD>̻<EFBFBD>֤<EFBFBD><D6A4><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>"
|
||||
}
|
||||
],
|
||||
"NotifyUrl": "https://localhost:5001"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user