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
445fc25bfd
commit
df2494dc86
@ -49,6 +49,7 @@
|
||||
| √ | 经营能力:平台收付通 | 合作伙伴 | |
|
||||
| √ | 运营工具:代金券 | 直连商户 & 合作伙伴 | |
|
||||
| √ | 运营工具:商家券 | 直连商户 & 合作伙伴 | |
|
||||
| √ | 运营工具:消费金 | 直连商户 | |
|
||||
| √ | 运营工具:委托营销 | 直连商户 & 合作伙伴 | |
|
||||
| √ | 运营工具:支付有礼 | 直连商户 & 合作伙伴 | |
|
||||
| √ | 运营工具:智慧商圈 | 直连商户 & 合作伙伴 | |
|
||||
@ -361,6 +362,16 @@
|
||||
|
||||
- 图片上传:`UploadMerchantMediaImage`
|
||||
|
||||
- 消费金
|
||||
|
||||
- 下载批次退款明细:`GetMultiuseStockRefundFlow`
|
||||
|
||||
- 下载批次发放明细:`GetMultiuseStockSendFlow`
|
||||
|
||||
- 下载核销明细:`GetMultiuseStockUseFlow`
|
||||
|
||||
- 发放指定批次的消费金:`SendMultiuseUserCoupon`
|
||||
|
||||
- 委托营销
|
||||
|
||||
- 建立合作关系:`BuildMarketingPartnership`
|
||||
|
@ -0,0 +1,99 @@
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Flurl.Http;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.TenpayV3
|
||||
{
|
||||
public static class WechatTenpayClientExecuteMultiuseExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>异步调用 [GET] /multiuse/stocks/{stock_id}/refund-flow 接口。</para>
|
||||
/// <para>
|
||||
/// REF: <br/>
|
||||
/// <![CDATA[ https://pay.weixin.qq.com/docs/merchant/apis/multiuse-coupon/stock/refund-flow.html ]]>
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<Models.GetMultiuseStockRefundFlowResponse> ExecuteGetMultiuseStockRefundFlowAsync(this WechatTenpayClient client, Models.GetMultiuseStockRefundFlowRequest 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, "multiuse", "stocks", request.StockId, "refund-flow");
|
||||
|
||||
return await client.SendFlurlRequestAsJsonAsync<Models.GetMultiuseStockRefundFlowResponse>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>异步调用 [GET] /multiuse/stocks/{stock_id}/send-flow 接口。</para>
|
||||
/// <para>
|
||||
/// REF: <br/>
|
||||
/// <![CDATA[ https://pay.weixin.qq.com/docs/merchant/apis/multiuse-coupon/stock/send-flow.html ]]>
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<Models.GetMultiuseStockSendFlowResponse> ExecuteGetMultiuseStockSendFlowAsync(this WechatTenpayClient client, Models.GetMultiuseStockSendFlowRequest 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, "multiuse", "stocks", request.StockId, "send-flow");
|
||||
|
||||
return await client.SendFlurlRequestAsJsonAsync<Models.GetMultiuseStockSendFlowResponse>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>异步调用 [GET] /multiuse/stocks/{stock_id}/use-flow 接口。</para>
|
||||
/// <para>
|
||||
/// REF: <br/>
|
||||
/// <![CDATA[ https://pay.weixin.qq.com/docs/merchant/apis/multiuse-coupon/stock/use-flow.html ]]>
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<Models.GetMultiuseStockUseFlowResponse> ExecuteGetMultiuseStockUseFlowAsync(this WechatTenpayClient client, Models.GetMultiuseStockUseFlowRequest 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, "multiuse", "stocks", request.StockId, "use-flow");
|
||||
|
||||
return await client.SendFlurlRequestAsJsonAsync<Models.GetMultiuseStockUseFlowResponse>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>异步调用 [POST] /multiuse/users/{openid}/coupons 接口。</para>
|
||||
/// <para>
|
||||
/// REF: <br/>
|
||||
/// <![CDATA[ https://pay.weixin.qq.com/docs/merchant/apis/multiuse-coupon/multiuse-coupon/send-multiuse-coupon.html ]]>
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<Models.SendMultiuseUserCouponResponse> ExecuteSendMultiuseUserCouponAsync(this WechatTenpayClient client, Models.SendMultiuseUserCouponRequest 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.Post, "multiuse", "users", request.OpenId, "coupons");
|
||||
|
||||
return await client.SendFlurlRequestAsJsonAsync<Models.SendMultiuseUserCouponResponse>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [GET] /multiuse/stocks/{stock_id}/refund-flow 接口的请求。</para>
|
||||
/// </summary>
|
||||
public class GetMultiuseStockRefundFlowRequest : WechatTenpayRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置批次号。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonIgnore]
|
||||
[System.Text.Json.Serialization.JsonIgnore]
|
||||
public string StockId { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [GET] /multiuse/stocks/{stock_id}/refund-flow 接口的响应。</para>
|
||||
/// </summary>
|
||||
public class GetMultiuseStockRefundFlowResponse : WechatTenpayResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置下载链接。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("url")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("url")]
|
||||
public string Url { get; set; } = default!;
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [GET] /multiuse/stocks/{stock_id}/send-flow 接口的请求。</para>
|
||||
/// </summary>
|
||||
public class GetMultiuseStockSendFlowRequest : WechatTenpayRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置批次号。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonIgnore]
|
||||
[System.Text.Json.Serialization.JsonIgnore]
|
||||
public string StockId { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [GET] /multiuse/stocks/{stock_id}/send-flow 接口的响应。</para>
|
||||
/// </summary>
|
||||
public class GetMultiuseStockSendFlowResponse : WechatTenpayResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置下载链接。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("url")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("url")]
|
||||
public string Url { get; set; } = default!;
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [GET] /multiuse/stocks/{stock_id}/use-flow 接口的请求。</para>
|
||||
/// </summary>
|
||||
public class GetMultiuseStockUseFlowRequest : WechatTenpayRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置批次号。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonIgnore]
|
||||
[System.Text.Json.Serialization.JsonIgnore]
|
||||
public string StockId { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [GET] /multiuse/stocks/{stock_id}/use-flow 接口的响应。</para>
|
||||
/// </summary>
|
||||
public class GetMultiuseStockUseFlowResponse : WechatTenpayResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置下载链接。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("url")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("url")]
|
||||
public string Url { get; set; } = default!;
|
||||
}
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /multiuse/users/{openid}/coupons 接口的请求。</para>
|
||||
/// </summary>
|
||||
[WechatTenpaySensitive]
|
||||
public class SendMultiuseUserCouponRequest : WechatTenpayRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置批次号。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("stock_id")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("stock_id")]
|
||||
public string StockId { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置微信 AppId。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("appid")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("appid")]
|
||||
public string AppId { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置用户唯一标识。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonIgnore]
|
||||
[System.Text.Json.Serialization.JsonIgnore]
|
||||
public string OpenId { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置商户单据号。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("out_request_no")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("out_request_no")]
|
||||
public string OutRequestNumber { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置指定发券面额(单位:分)。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("amount")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("amount")]
|
||||
public int? CouponAmount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置身份证件类型。
|
||||
/// <para>默认值:"ID_CARD"</para>
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("card_type")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("card_type")]
|
||||
public string IdCardType { get; set; } = "ID_CARD";
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置用户姓名(需使用平台公钥/证书加密)。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("user_name")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("user_name")]
|
||||
[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)]
|
||||
public string UserName { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置身份证件号码(需使用平台公钥/证书加密)。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("id_card_number")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("id_card_number")]
|
||||
[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)]
|
||||
public string IdCardNumber { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /multiuse/users/{openid}/coupons 接口的响应。</para>
|
||||
/// </summary>
|
||||
public class SendMultiuseUserCouponResponse : WechatTenpayResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置消费金 ID。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("coupon_id")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("coupon_id")]
|
||||
public string CouponId { get; set; } = default!;
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
{
|
||||
"url": "https://api.mch.weixin.qq.com/v3/billdownload/file?token=ja7q-s1yy1ZbROASakz0Jx4BjW3qdnympjfcB4v4yLftXXXXXXXXXXXX"
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
{
|
||||
"url": "https://api.mch.weixin.qq.com/v3/billdownload/file?token=ja7q-s1yy1ZbROASakz0Jx4BjW3qdnympjfcB4v4yLftXXXXXXXXXXXX"
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
{
|
||||
"url": "https://api.mch.weixin.qq.com/v3/billdownload/file?token=ja7q-s1yy1ZbROASakz0Jx4BjW3qdnympjfcB4v4yLftXXXXXXXXXXXX"
|
||||
}
|
@ -982,6 +982,62 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.UnitTests
|
||||
}
|
||||
}
|
||||
|
||||
[Fact(DisplayName = "测试用例:加密请求中的敏感数据([POST] /multiuse/users/{openid}/coupons)")]
|
||||
public async Task TestEncryptRequestSensitiveProperty_SendMultiuseUserCouponRequest()
|
||||
{
|
||||
static Models.SendMultiuseUserCouponRequest GenerateMockRequestModel()
|
||||
{
|
||||
return new Models.SendMultiuseUserCouponRequest()
|
||||
{
|
||||
UserName = MOCK_PLAIN_STR,
|
||||
IdCardNumber = MOCK_PLAIN_STR
|
||||
};
|
||||
}
|
||||
|
||||
static void AssertMockRequestModel(Models.SendMultiuseUserCouponRequest request, Func<string, string> decryptor)
|
||||
{
|
||||
Assert.NotEqual(MOCK_PLAIN_STR, request.UserName!);
|
||||
Assert.NotEqual(MOCK_PLAIN_STR, request.IdCardNumber!);
|
||||
Assert.Equal(MOCK_PLAIN_STR, decryptor.Invoke(request.UserName!));
|
||||
Assert.Equal(MOCK_PLAIN_STR, decryptor.Invoke(request.IdCardNumber!));
|
||||
Assert.Equal(MOCK_CERT_SN, request.WechatpayCertificateSerialNumber!, 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.ExecuteSendMultiuseUserCouponAsync(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.ExecuteSendMultiuseUserCouponAsync(request);
|
||||
AssertMockRequestModel(request, (cipher) => Utilities.SM2Utility.Decrypt(SM2_PEM_PRIVATE_KEY, (EncodedString)cipher)!);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Fact(DisplayName = "测试用例:加密请求中的敏感数据([POST] /new-tax-control-fapiao/fapiao-applications)")]
|
||||
public async Task TestEncryptRequestSensitiveProperty_CreateNewTaxControlFapiaoApplicationRequest()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user