mirror of
https://gitee.com/fudiwei/DotNetCore.SKIT.FlurlHttpClient.Wechat.git
synced 2025-04-05 17:37:54 +08:00
feat(tenpayv3): 新增电商订单实名信息校验接口
This commit is contained in:
parent
17b8478115
commit
c07b2ff1d5
@ -1370,6 +1370,20 @@
|
||||
|
||||
- 查询不活跃商户身份核实结果:`GetComplianceInactiveMerchantIdentityVerificationByVerificationId`
|
||||
|
||||
- 扩展工具
|
||||
|
||||
- 电商订单实名校验
|
||||
|
||||
- 实名信息校验:`GetRealNameVerification`
|
||||
|
||||
- 微信点餐订单
|
||||
|
||||
- 点餐订单信息同步:`SyncCateringOrderStatus`
|
||||
|
||||
- 微信寄快递
|
||||
|
||||
- 用户 OpenID 转换:`TransformExpressUserOpenId`
|
||||
|
||||
- 其他
|
||||
|
||||
- 来账识别
|
||||
@ -1576,14 +1590,6 @@
|
||||
|
||||
- 服务商银行来账查询:`QueryMerchantFundMerchantIncomeRecords`
|
||||
|
||||
- 微信点餐订单
|
||||
|
||||
- 点餐订单信息同步:`SyncCateringOrderStatus`
|
||||
|
||||
- 微信寄快递
|
||||
|
||||
- 用户 OpenID 转换:`TransformExpressUserOpenId`
|
||||
|
||||
</details>
|
||||
|
||||
---
|
||||
|
@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Flurl.Http;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.TenpayV3
|
||||
{
|
||||
public static class WechatTenpayClientExecuteRealNameExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>异步调用 [GET] /realname/verify 接口。</para>
|
||||
/// <para>
|
||||
/// REF: <br/>
|
||||
/// <![CDATA[ https://pay.weixin.qq.com/doc/v3/partner/4013735179 ]]>
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<Models.GetRealNameVerificationResponse> ExecuteGetRealNameVerificationAsync(this WechatTenpayClient client, Models.GetRealNameVerificationRequest 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
|
||||
.CreateFlurlRequest(request, HttpMethod.Get, "realname", "verify")
|
||||
.SetQueryParam("credential_type", request.CredentialType)
|
||||
.SetQueryParam("encrypted_credential_id", request.CredentialId)
|
||||
.SetQueryParam("encrypted_name", request.CredentialName)
|
||||
.SetQueryParam("wxp_trade_no", request.TransactionId);
|
||||
|
||||
return await client.SendFlurlRequestAsJsonAsync<Models.GetRealNameVerificationResponse>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [GET] /realname/verify 接口的请求。</para>
|
||||
/// </summary>
|
||||
[WechatTenpaySensitive]
|
||||
public class GetRealNameVerificationRequest : WechatTenpayRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置下单用户证件类型。
|
||||
/// <para>默认值:"1"</para>
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonIgnore]
|
||||
[System.Text.Json.Serialization.JsonIgnore]
|
||||
public string CredentialType { get; set; } = "1";
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置下单用户证件号(需使用平台公钥/证书加密)。
|
||||
/// </summary>
|
||||
[WechatTenpaySensitiveProperty(scheme: Constants.SignSchemes.WECHATPAY2_RSA_2048_WITH_SHA256, algorithm: Constants.EncryptionAlgorithms.RSA_2048_ECB_PKCS8_OAEP_WITH_SHA1_AND_MGF1)]
|
||||
[WechatTenpaySensitiveProperty(scheme: Constants.SignSchemes.WECHATPAY2_SM2_WITH_SM3, algorithm: Constants.EncryptionAlgorithms.SM2_C1C3C2_ASN1)]
|
||||
[Newtonsoft.Json.JsonIgnore]
|
||||
[System.Text.Json.Serialization.JsonIgnore]
|
||||
public string CredentialId { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置下单用户姓名(需使用平台公钥/证书加密)。
|
||||
/// </summary>
|
||||
[WechatTenpaySensitiveProperty(scheme: Constants.SignSchemes.WECHATPAY2_RSA_2048_WITH_SHA256, algorithm: Constants.EncryptionAlgorithms.RSA_2048_ECB_PKCS8_OAEP_WITH_SHA1_AND_MGF1)]
|
||||
[WechatTenpaySensitiveProperty(scheme: Constants.SignSchemes.WECHATPAY2_SM2_WITH_SM3, algorithm: Constants.EncryptionAlgorithms.SM2_C1C3C2_ASN1)]
|
||||
[Newtonsoft.Json.JsonIgnore]
|
||||
[System.Text.Json.Serialization.JsonIgnore]
|
||||
public string CredentialName { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置微信支付交易单号。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonIgnore]
|
||||
[System.Text.Json.Serialization.JsonIgnore]
|
||||
public string TransactionId { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [GET] /realname/verify 接口的响应。</para>
|
||||
/// </summary>
|
||||
public class GetRealNameVerificationResponse : WechatTenpayResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置实名比对结果。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("verify_result")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("verify_result")]
|
||||
public int VerifyResult { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置实名比对错误信息。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("err_message")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("err_message")]
|
||||
public string? VerifyErrorMessage { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
{
|
||||
"verify_result": 0,
|
||||
"err_message": "realname verify succ"
|
||||
}
|
@ -1774,6 +1774,62 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.UnitTests
|
||||
}
|
||||
}
|
||||
|
||||
[Fact(DisplayName = "测试用例:加密请求中的敏感数据([POST] /realname/verify)")]
|
||||
public async Task TestEncryptRequestSensitiveProperty_GetRealNameVerificationRequest()
|
||||
{
|
||||
static Models.GetRealNameVerificationRequest GenerateMockRequestModel()
|
||||
{
|
||||
return new Models.GetRealNameVerificationRequest()
|
||||
{
|
||||
CredentialId = MOCK_PLAIN_STR,
|
||||
CredentialName = MOCK_PLAIN_STR
|
||||
};
|
||||
}
|
||||
|
||||
static void AssertMockRequestModel(Models.GetRealNameVerificationRequest request, Func<string, string> decryptor)
|
||||
{
|
||||
Assert.NotEqual(MOCK_PLAIN_STR, request.CredentialId);
|
||||
Assert.NotEqual(MOCK_PLAIN_STR, request.CredentialName);
|
||||
Assert.Equal(MOCK_PLAIN_STR, decryptor.Invoke(request.CredentialId));
|
||||
Assert.Equal(MOCK_PLAIN_STR, decryptor.Invoke(request.CredentialName));
|
||||
Assert.Equal(MOCK_CERT_SN, request.WechatpaySerialNumber!, ignoreCase: true);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(TestConfigs.WechatMerchantRSACertificatePrivateKey))
|
||||
{
|
||||
using (var client = CreateMockClientUseRSA(autoEncrypt: false))
|
||||
{
|
||||
var request = GenerateMockRequestModel();
|
||||
client.EncryptRequestSensitiveProperty(request);
|
||||
AssertMockRequestModel(request, (cipher) => Utilities.RSAUtility.DecryptWithECB(RSA_PEM_PRIVATE_KEY, (EncodedString)cipher)!);
|
||||
}
|
||||
|
||||
using (var client = CreateMockClientUseRSA(autoEncrypt: true))
|
||||
{
|
||||
var request = GenerateMockRequestModel();
|
||||
await client.ExecuteGetRealNameVerificationAsync(request);
|
||||
AssertMockRequestModel(request, (cipher) => Utilities.RSAUtility.DecryptWithECB(RSA_PEM_PRIVATE_KEY, (EncodedString)cipher)!);
|
||||
}
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(TestConfigs.WechatMerchantSM2CertificatePrivateKey))
|
||||
{
|
||||
using (var client = CreateMockClientUseSM2(autoEncrypt: false))
|
||||
{
|
||||
var request = GenerateMockRequestModel();
|
||||
client.EncryptRequestSensitiveProperty(request);
|
||||
AssertMockRequestModel(request, (cipher) => Utilities.SM2Utility.Decrypt(SM2_PEM_PRIVATE_KEY, (EncodedString)cipher)!);
|
||||
}
|
||||
|
||||
using (var client = CreateMockClientUseSM2(autoEncrypt: true))
|
||||
{
|
||||
var request = GenerateMockRequestModel();
|
||||
await client.ExecuteGetRealNameVerificationAsync(request);
|
||||
AssertMockRequestModel(request, (cipher) => Utilities.SM2Utility.Decrypt(SM2_PEM_PRIVATE_KEY, (EncodedString)cipher)!);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Fact(DisplayName = "测试用例:加密请求中的敏感数据([POST] /refund/domestic/refunds/{refund_id}/apply-abnormal-refund)")]
|
||||
public async Task TestEncryptRequestSensitiveProperty_CreateRefundDomesticAbnormalRefundApply()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user