mirror of
https://gitee.com/fudiwei/DotNetCore.SKIT.FlurlHttpClient.Wechat.git
synced 2025-09-19 10:08:20 +08:00
docs: 完善文档
This commit is contained in:
51
docs/WechatTenpayV3/Advanced_Extensions.md
Normal file
51
docs/WechatTenpayV3/Advanced_Extensions.md
Normal file
@@ -0,0 +1,51 @@
|
||||
## 如何扩展额外的 API?
|
||||
|
||||
---
|
||||
|
||||
如果有某些接口本库尚未支持,你可按照下面的示例自行扩展:
|
||||
|
||||
```csharp
|
||||
/* 继承 WechatTenpayRequest 实现自定义请求类 */
|
||||
public class MyFakeRequest : WechatTenpayRequest
|
||||
{
|
||||
[Newtonsoft.Json.JsonProperty("my_fake_props")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("my_fake_props")]
|
||||
public string MyFakeProps { get; set; }
|
||||
}
|
||||
|
||||
/* 继承 WechatTenpayResponse 实现自定义响应类 */
|
||||
public class MyFakeResponse : WechatTenpayResponse
|
||||
{
|
||||
[Newtonsoft.Json.JsonProperty("my_fake_props")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("my_fake_props")]
|
||||
public string MyFakeProps { get; set; }
|
||||
}
|
||||
|
||||
/* 扩展 WechatTenpayClient 方法 */
|
||||
public static class MyFakeClientExtensions
|
||||
{
|
||||
public static async Task<MyFakeResponse> ExecuteMyFakeAsync(this WechatTenpayClient client, MyFakeRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (client is null) throw new ArgumentNullException(nameof(client));
|
||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(request, HttpMethod.Post, "my-fake-url")
|
||||
.SetQueryParam("access_token", request.AccessToken);
|
||||
|
||||
return await client.SendRequestWithJsonAsync<MyFakeResponse>(flurlReq, request, cancellationToken);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
同样的,你也可自行扩展回调通知事件的敏感数据模型:
|
||||
|
||||
```csharp
|
||||
/* 实现自定义的 JSON 格式的回调通知事件敏感数据 */
|
||||
public class MyFakeEvent : WechatTenpayEvent.Types.IDecryptedResource
|
||||
{
|
||||
[Newtonsoft.Json.JsonProperty("my_fake_props")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("my_fake_props")]
|
||||
public string MyFakeProps { get; set; }
|
||||
}
|
||||
```
|
@@ -147,3 +147,5 @@ else
|
||||
- [如何解密回调通知事件中的敏感数据?](./Advanced_EventDataDecryption.md)
|
||||
|
||||
- [如何生成客户端调起支付时所需的参数及签名?](./Advanced_Payment.md)
|
||||
|
||||
- [如何扩展额外的 API?](./Advanced_Extensions.md)
|
||||
|
Reference in New Issue
Block a user