docs: 完善文档

This commit is contained in:
Fu Diwei
2021-06-17 19:43:20 +08:00
parent a19ab7bd46
commit b317d78fc1
16 changed files with 88 additions and 214 deletions

View File

@@ -0,0 +1,39 @@
### 如何使用拦截器?
---
拦截器是一种可以监视或重写请求调用的强大机制。下面给出一个用于记录传出请求和传入响应的拦截器简单示例:
```csharp
public class LoggingInterceptor : WechatHttpCallInterceptor
{
private readonly ILogger _logger;
public WechatAdsAgencyTokenInterceptor(ILogger logger)
{
_logger = logger;
}
public override Task BeforeCallAsync(FlurlCall flurlCall)
{
logger.LogInformation($"Sending request to {flurlCall.Request.Url} on {DateTimeOffset.Now}.");
return Task.CompletedTask;
}
public override Task AfterCallAsync(FlurlCall flurlCall)
{
logger.LogInformation($"Received response in {flurlCall.Duration.Value.TotalMilliseconds}ms.");
return Task.CompletedTask;
}
}
```
示例代码中的 `FlurlCall` 对象,是 `Flurl.Http` 的内置类型,有关该类型的更进一步的说明,请自行阅读相关文档。
你可以在构造得到 `WechatApiClient` 对象后,将拦截器注入到该客户端中:
```csharp
client.Interceptors.Add(new LoggingInterceptor(loggerFactory.CreateLogger()));
```
拦截器的工作方式类似于洋葱模型。对于请求拦截器而言,将按照添加时的顺序依次执行;对于响应拦截器而言,将按照添加时的顺序逆序依次执行。

View File

@@ -8,7 +8,7 @@
默认情况下,本库使用 `System.Text.Json` 作为 JSON 序列化器。
如果你更习惯于 `Newtonsoft.Json`,那么你可以在构造得到 `WechatTenpayClient` 对象后:
如果你更习惯于 `Newtonsoft.Json`,那么你可以在构造得到 `WechatApiClient` 对象后:
```csharp
client.Configure(settings =>

View File

@@ -4,7 +4,7 @@
[![NuGet Download](https://img.shields.io/nuget/dt/SKIT.FlurlHttpClient.Wechat.Api.svg?sanitize=true)](https://www.nuget.org/packages/SKIT.FlurlHttpClient.Wechat.Api)
[![GitHub License](https://img.shields.io/github/license/fudiwei/DotNetCore.SKIT.FlurlHttpClient.Wechat)](https://github.com/fudiwei/DotNetCore.SKIT.FlurlHttpClient.Wechat/blob/main/LICENSE)
基于 `Flurl.Http` 的[微信公众平台]((https://mp.weixin.qq.com/)) & [微信开放平台]((https://open.weixin.qq.com/)) API 客户端。
基于 `Flurl.Http` 的[微信公众平台](<(https://mp.weixin.qq.com/)>) & [微信开放平台](<(https://open.weixin.qq.com/)>) API 客户端。
---
@@ -161,6 +161,8 @@ var response = await client.ExecuteCgibinUserInfoAsync(request);
- [如何指定 JSON 序列化器?](./Advanced_JsonSerializer.md)
- [如何使用拦截器?](./Advanced_Interceptor.md)
- [如何解析回调通知事件?](./Advanced_EventDataDeserialization.md)
- [如何生成 JS-SDK 初始化时所需的参数及签名?](./Advanced_JSSDK.md)