docs: 完善文档

This commit is contained in:
Fu Diwei
2022-11-14 13:25:07 +08:00
parent d18985f260
commit 115d374449
6 changed files with 87 additions and 5 deletions

View File

@@ -44,7 +44,7 @@ switch (msgType)
var callbackModel = client.DeserializeEventFromXml<Events.TextMessageEvent>(callbackXml);
}
break;
// 省略其他情况
// 其他情况
}
```

View File

@@ -164,6 +164,7 @@ public class RedisCertificateManager : CertificateManager
IDictionary<string, string> map = values.ToDictionary(k => k.Name.ToString(), v => v.Value.ToString());
return new CertificateEntry(
algorithmType: map[nameof(CertificateEntry.AlgorithmType)],
serialNumber: map[nameof(CertificateEntry.SerialNumber)],
certificate: map[nameof(CertificateEntry.Certificate)],
effectiveTime: DateTimeOffset.Parse(map[nameof(CertificateEntry.EffectiveTime)]),
@@ -175,6 +176,7 @@ public class RedisCertificateManager : CertificateManager
{
return new HashEntry[]
{
new HashEntry(nameof(CertificateEntry.AlgorithmType), entry.AlgorithmType),
new HashEntry(nameof(CertificateEntry.SerialNumber), entry.SerialNumber),
new HashEntry(nameof(CertificateEntry.Certificate), entry.Certificate),
new HashEntry(nameof(CertificateEntry.EffectiveTime), entry.EffectiveTime.ToString()),

View File

@@ -0,0 +1,37 @@
## 如何接入国密算法?
---
> 请先自行阅读:
>
> [《微信支付开发者文档 - 国密接入指引》](https://pay.weixin.qq.com/docs/merchant/development/shangmi/introduction.html)
从 v2.14.0 版本起,本库支持接入微信支付平台基于国密证书和使用 SM2/SM3/SM4 算法的 API v3 接口。
---
### 接入指引
在微信商户平台开通国密接入权限后,你需要在原有的项目代码基础上做出如下两点调整。
首先,构造得到 `WechatTenpayClient` 对象的方式与原有方式基本一致,只需将 `MerchantCertificateSerialNumber``MerchantCertificatePrivateKey` 替换为相应的国密证书内容即可,并指定签名认证方式:
```csharp
var options = new WechatTenpayClientOptions()
{
// 其他配置项略
SignScheme = Constants.SignSchemes.WECHATPAY2_SM2_WITH_SM3
};
var client = new WechatTenpayClient(options);
```
此外,获取平台证书并存入平台证书管理器 `PlatformCertificateManager` 时,需指定证书的算法类型:
```csharp
// 如果是 RSA 证书
manager.AddEntry(new CertificateEntry("RSA", "RSA 证书序列号", "RSA 证书内容", "RSA 证书生效时间", "RSA 证书过期时间"));
// 如果是 SM2 证书
manager.AddEntry(new CertificateEntry("SM2", "SM2 证书序列号", "SM2 证书内容", "SM2 证书生效时间", "SM2 证书过期时间"));
```
这样,就已经完成了接入国密算法的全部流程。请求自动签名、响应验证签名、加解密敏感数据字段、解析回调通知事件模型等相关的扩展方法调用方式与原有方式完全一致。

View File

@@ -12,9 +12,9 @@
- 支持直连商户、服务商两种模式。
- 请求时自动生成签名,无需开发者手动干预。
- 请求时自动生成签名(同时支持国际 RSA 算法或国密 SM 算法),无需开发者手动干预。
- 提供了微信支付所需的 RSA、AES、SHA-256 等算法工具类。
- 提供了微信支付所需的 RSA、AES、SM2/SM3/SM4、SHA-256 等算法工具类。
- 提供了生成调起支付签名、加密请求中敏感数据、解密响应中敏感数据、解析回调通知事件敏感数据等扩展方法。
@@ -114,6 +114,8 @@ else
- [如何生成客户端调起支付时所需的参数及签名?](./Advanced_Parameters.md)
- [如何接入国密算法?](./Advanced_SMAlgorithm.md)
- [如何扩展额外的 API](./Advanced_Extensions.md)
---

View File

@@ -35,7 +35,7 @@ switch (msgType)
var callbackModel = client.DeserializeEventFromXml<Events.TextMessageEvent>(callbackXml);
}
break;
// 省略其他情况
// 其他情况
}
```