feat(tenpayv3): 新增电商订单实名信息校验接口

This commit is contained in:
Fu Diwei
2025-03-14 10:02:20 +08:00
parent 17b8478115
commit c07b2ff1d5
6 changed files with 175 additions and 8 deletions

View File

@@ -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);
}
}
}

View File

@@ -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;
}
}

View File

@@ -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; }
}
}